From f2457b90ff0cb28a55fca8c8aa72622c5966d284 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Tue, 14 Jan 2020 21:07:20 -0500 Subject: [PATCH] Add patch for $DefaultColor, courtesy of Tim Chase. --- src/calendar.c | 25 +++++++++++++++++++++++-- src/globals.h | 3 +++ src/var.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/calendar.c b/src/calendar.c index c04267c5..f61510cb 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1070,7 +1070,15 @@ static int DoCalRem(ParsePtr p, int col) int is_color, col_r, col_g, col_b; - is_color = 0; + is_color = ( + DefaultColorR != -1 + && DefaultColorG != -1 + && DefaultColorB != -1); + if (is_color) { + col_r = DefaultColorR; + col_g = DefaultColorG; + col_b = DefaultColorB; + } DBufInit(&buf); DBufInit(&pre_buf); DBufInit(&raw_buf); @@ -1152,6 +1160,19 @@ static int DoCalRem(ParsePtr p, int col) strcpy(trig.passthru, "PSFile"); trig.typ = PASSTHRU_TYPE; } + + /* If it's a plain reminder but we have a default color, add the + three colors to the prebuf and change passthru to "COLOR" */ + if (trig.typ == MSG_TYPE || + trig.typ == CAL_TYPE) { + if (PsCal && is_color) { + char cbuf[24]; + sprintf(cbuf, "%d %d %d ", col_r, col_g, col_b); + DBufPuts(&pre_buf, cbuf); + strcpy(trig.passthru, "COLOR"); + /* Don't change trig.typ or next if() will trigger! */ + } + } if (trig.typ == PASSTHRU_TYPE) { if (!PsCal && strcmp(trig.passthru, "COLOR") && strcmp(trig.passthru, "COLOUR")) { FreeTrig(&trig); @@ -1358,7 +1379,7 @@ static int DoCalRem(ParsePtr p, int col) } e->lineno = LineNo; - if (trig.typ == PASSTHRU_TYPE) { + if (trig.typ == PASSTHRU_TYPE || is_color) { StrnCpy(e->passthru, trig.passthru, PASSTHRU_LEN); } else { e->passthru[0] = 0; diff --git a/src/globals.h b/src/globals.h index 976279c4..ea6e6f19 100644 --- a/src/globals.h +++ b/src/globals.h @@ -73,6 +73,9 @@ EXTERN INIT( int Daemon, 0); EXTERN INIT( char DateSep, DATESEP); EXTERN INIT( char TimeSep, TIMESEP); EXTERN INIT( char DateTimeSep, DATETIMESEP); +EXTERN INIT( int DefaultColorR, -1); +EXTERN INIT( int DefaultColorB, -1); +EXTERN INIT( int DefaultColorG, -1); EXTERN INIT( int SynthesizeTags, 0); EXTERN INIT( int ScFormat, SC_AMPM); EXTERN INIT( int MaxSatIter, 150); diff --git a/src/var.c b/src/var.c index cc01ae3f..d1731af8 100644 --- a/src/var.c +++ b/src/var.c @@ -168,6 +168,40 @@ static int datetime_sep_func(int do_set, Value *val) return OK; } +static int default_color_func(int do_set, Value *val) +{ + int col_r, col_g, col_b; + if (!do_set) { + /* 12 = strlen("255 255 255\0") */ + val->v.str = malloc(12); + if (!val->v.str) return E_NO_MEM; + snprintf(val->v.str, 12, "%d %d %d", + DefaultColorR, + DefaultColorB, + DefaultColorG + ); + val->type = STR_TYPE; + return OK; + } + if (val->type != STR_TYPE) return E_BAD_TYPE; + if (sscanf(val->v.str, "%d %d %d", &col_r, &col_g, &col_b) != 3) { + return E_BAD_TYPE; + } + if (col_r != -1 || col_g != -1 || col_b != -1) { + /* if any of them aren't -1, clamp them all as set */ + if (col_r < 0) col_r = 0; + else if (col_r > 255) col_r = 255; + if (col_g < 0) col_g = 0; + else if (col_g > 255) col_g = 255; + if (col_b < 0) col_b = 0; + else if (col_b > 255) col_b = 255; + } + DefaultColorR = col_r; + DefaultColorB = col_b; + DefaultColorG = col_g; + return OK; +} + static int date_sep_func(int do_set, Value *val) { if (!do_set) { @@ -608,6 +642,7 @@ static SysVar SysVarArr[] = { {"Daemon", 0, INT_TYPE, &Daemon, 0, 0 }, {"DateSep", 1, SPECIAL_TYPE, date_sep_func, 0, 0 }, {"DateTimeSep", 1, SPECIAL_TYPE, datetime_sep_func, 0, 0 }, + {"DefaultColor", 1, SPECIAL_TYPE, default_color_func, 0, 0 }, {"DefaultPrio", 1, INT_TYPE, &DefaultPrio, 0, 9999}, {"DeltaOffset", 0, INT_TYPE, &DeltaOffset, 0, 0 }, {"DontFork", 0, INT_TYPE, &DontFork, 0, 0 },