From 2193acef3b525a84b3102bb0b06a8bf5a99efbcb Mon Sep 17 00:00:00 2001 From: Aline Date: Fri, 19 May 2017 13:35:45 +0200 Subject: [PATCH] Added CLI options for date/time font and clock text color --- i3lock.c | 30 ++++++++++++++++++++++++++++++ unlock_indicator.c | 17 +++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/i3lock.c b/i3lock.c index 0180dfe..d649a90 100644 --- a/i3lock.c +++ b/i3lock.c @@ -66,6 +66,7 @@ char ringwrongcolor[9] = "7d3300ff"; char ringcolor[9] = "337d00ff"; char linecolor[9] = "000000ff"; char textcolor[9] = "000000ff"; +char clockcolor[9] = "000000ff"; char keyhlcolor[9] = "33db00ff"; char bshlcolor[9] = "db3300ff"; char separatorcolor[9] = "000000ff"; @@ -82,6 +83,8 @@ bool show_clock = false; */ char time_format[32] = "%H:%M:%S\0"; char date_format[32] = "%A, %m %Y\0"; +char time_font[32] = "sans-serif\0"; +char date_font[32] = "sans-serif\0"; /* opts for blurring */ bool blur = false; @@ -888,6 +891,7 @@ int main(int argc, char *argv[]) { {"ringcolor", required_argument, NULL, 0}, // --r-c {"linecolor", required_argument, NULL, 0}, // --l-c {"textcolor", required_argument, NULL, 0}, // --t-c + {"clockcolor", required_argument, NULL, 0}, // --c-c {"keyhlcolor", required_argument, NULL, 0}, // --k-c {"bshlcolor", required_argument, NULL, 0}, // --b-c {"separatorcolor", required_argument, NULL, 0}, @@ -899,6 +903,8 @@ int main(int argc, char *argv[]) { {"clock", no_argument, NULL, 'k'}, {"timestr", required_argument, NULL, 0}, {"datestr", required_argument, NULL, 0}, + {"timefont", required_argument, NULL, 0}, + {"datefont", required_argument, NULL, 0}, {"blur", required_argument, NULL, 'B'}, @@ -1069,6 +1075,16 @@ int main(int argc, char *argv[]) { if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", textcolor) != 1) errx(1, "textcolor is invalid, color must be given in 8-byte format: rrggbb\n"); } + else if (strcmp(longopts[optind].name, "clockcolor") == 0) { + char *arg = optarg; + + /* Skip # if present */ + if (arg[0] == '#') + arg++; + + if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", clockcolor) != 1) + errx(1, "clockcolor is invalid, color must be given in 8-byte format: rrggbb\n"); + } else if (strcmp(longopts[optind].name, "keyhlcolor") == 0) { char *arg = optarg; @@ -1113,6 +1129,20 @@ int main(int argc, char *argv[]) { } strcpy(date_format,optarg); } + else if (strcmp(longopts[optind].name, "timefont") == 0) { + //read in to time_font + if (strlen(optarg) > 31) { + errx(1, "time font string can be at most 31 characters"); + } + strcpy(time_font,optarg); + } + else if (strcmp(longopts[optind].name, "datefont") == 0) { + //read in to date_font + if (strlen(optarg) > 31) { + errx(1, "date font string can be at most 31 characters"); + } + strcpy(date_font,optarg); + } break; case 'f': show_failed_attempts = true; diff --git a/unlock_indicator.c b/unlock_indicator.c index 4dcdd70..6ebbc3f 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -67,6 +67,7 @@ extern char ringwrongcolor[9]; extern char ringcolor[9]; extern char linecolor[9]; extern char textcolor[9]; +extern char clockcolor[9]; extern char keyhlcolor[9]; extern char bshlcolor[9]; extern char separatorcolor[9]; @@ -77,6 +78,8 @@ extern int screen_number; extern bool show_clock; extern char time_format[32]; extern char date_format[32]; +extern char time_font[32]; +extern char date_font[32]; /* Whether the failed attempts should be displayed. */ extern bool show_failed_attempts; /* Number of failed unlock attempts. */ @@ -229,6 +232,14 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { (strtol(strgroupst[1], NULL, 16)), (strtol(strgroupst[2], NULL, 16)), (strtol(strgroupst[3], NULL, 16))}; + char strgroupsc[4][3] = {{clockcolor[0], clockcolor[1], '\0'}, + {clockcolor[2], clockcolor[3], '\0'}, + {clockcolor[4], clockcolor[5], '\0'}, + {clockcolor[6], clockcolor[7], '\0'}}; + uint32_t clock16[4] = {(strtol(strgroupsc[0], NULL, 16)), + (strtol(strgroupsc[1], NULL, 16)), + (strtol(strgroupsc[2], NULL, 16)), + (strtol(strgroupsc[3], NULL, 16))}; char strgroupsk[4][3] = {{keyhlcolor[0], keyhlcolor[1], '\0'}, {keyhlcolor[2], keyhlcolor[3], '\0'}, {keyhlcolor[4], keyhlcolor[5], '\0'}, @@ -385,6 +396,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_text_extents_t extents; double x, y; + cairo_select_font_face(ctx, time_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_source_rgba(ctx, (double)clock16[0]/255, (double)clock16[1]/255, (double)clock16[2]/255, (double)clock16[3]/255); cairo_text_extents(ctx, text, &extents); x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing); if (date) { @@ -402,8 +415,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_text_extents_t extents; double x, y; - // TODO: different date/time colors - cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255); + cairo_select_font_face(ctx, date_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_source_rgba(ctx, (double)clock16[0]/255, (double)clock16[1]/255, (double)clock16[2]/255, (double)clock16[3]/255); cairo_set_font_size(ctx, 14.0); cairo_text_extents(ctx, date, &extents);