From e26171d545ae9d10eaeaabf9fc857601d7445b3c Mon Sep 17 00:00:00 2001 From: Aline Date: Fri, 19 May 2017 16:14:37 +0200 Subject: [PATCH] Make clock font size modifiable --- i3lock.c | 33 +++++++++++++++++++++++++++------ unlock_indicator.c | 13 +++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/i3lock.c b/i3lock.c index cd5a722..a0b9ca1 100644 --- a/i3lock.c +++ b/i3lock.c @@ -88,6 +88,9 @@ char date_font[32] = "sans-serif\0"; char clock_x_expr[32] = "ix\0"; char clock_y_expr[32] = "iy+20\0"; +double time_size = 32; +double date_size = 14; + /* opts for blurring */ bool blur = false; bool step_blur = false; @@ -907,6 +910,8 @@ int main(int argc, char *argv[]) { {"datestr", required_argument, NULL, 0}, {"timefont", required_argument, NULL, 0}, {"datefont", required_argument, NULL, 0}, + {"timesize", required_argument, NULL, 0}, + {"datesize", required_argument, NULL, 0}, {"clockpos", required_argument, NULL, 0}, {"blur", required_argument, NULL, 'B'}, @@ -1121,40 +1126,56 @@ int main(int argc, char *argv[]) { else if (strcmp(longopts[optind].name, "timestr") == 0) { //read in to timestr if (strlen(optarg) > 31) { - errx(1, "time format string can be at most 31 characters"); + errx(1, "time format string can be at most 31 characters\n"); } strcpy(time_format,optarg); } else if (strcmp(longopts[optind].name, "datestr") == 0) { //read in to datestr if (strlen(optarg) > 31) { - errx(1, "time format string can be at most 31 characters"); + errx(1, "time format string can be at most 31 characters\n"); } 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"); + errx(1, "time font string can be at most 31 characters\n"); } 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"); + errx(1, "date font string can be at most 31 characters\n"); } strcpy(date_font,optarg); } + else if (strcmp(longopts[optind].name, "timesize") == 0) { + char *arg = optarg; + + if (sscanf(arg, "%lf", &time_size) != 1) + errx(1, "timesize must be a number\n"); + if (time_size < 1) + errx(1, "timesize must be larger than 0\n"); + } + else if (strcmp(longopts[optind].name, "datesize") == 0) { + char *arg = optarg; + + if (sscanf(arg, "%lf", &date_size) != 1) + errx(1, "datesize must be a number\n"); + if (date_size < 1) + errx(1, "datesize must be larger than 0\n"); + } else if (strcmp(longopts[optind].name, "clockpos") == 0) { //read in to clock_x_expr and clock_y_expr if (strlen(optarg) > 31) { // this is overly restrictive since both the x and y string buffers have size 32, but it's easier to check. - errx(1, "date position string can be at most 31 characters"); + errx(1, "date position string can be at most 31 characters\n"); } char* arg = optarg; if (sscanf(arg, "%30[^:]:%30[^:]", &clock_x_expr, &clock_y_expr) != 2) { - errx(1, "clockpos must be of the form x:y"); + errx(1, "clockpos must be of the form x:y\n"); } } break; diff --git a/unlock_indicator.c b/unlock_indicator.c index 4251390..a9e8679 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -85,6 +85,9 @@ extern char time_font[32]; extern char date_font[32]; extern char clock_x_expr[32]; extern char clock_y_expr[32]; + +extern double time_size; +extern double date_size; /* Whether the failed attempts should be displayed. */ extern bool show_failed_attempts; /* Number of failed unlock attempts. */ @@ -469,12 +472,14 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { if (text) { double x, y; cairo_text_extents_t extents; - cairo_set_font_size(clock_ctx, 32.0); + + cairo_set_font_size(clock_ctx, time_size); cairo_select_font_face(clock_ctx, time_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_source_rgba(clock_ctx, (double)clock16[0]/255, (double)clock16[1]/255, (double)clock16[2]/255, (double)clock16[3]/255); + cairo_text_extents(clock_ctx, text, &extents); x = CLOCK_WIDTH/2 - ((extents.width / 2) + extents.x_bearing); - y = CLOCK_HEIGHT/2 - extents.height; + y = CLOCK_HEIGHT/2 - 10; cairo_move_to(clock_ctx, x, y); cairo_show_text(clock_ctx, text); @@ -487,11 +492,11 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_select_font_face(clock_ctx, date_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_source_rgba(clock_ctx, (double)clock16[0]/255, (double)clock16[1]/255, (double)clock16[2]/255, (double)clock16[3]/255); - cairo_set_font_size(clock_ctx, 14.0); + cairo_set_font_size(clock_ctx, date_size); cairo_text_extents(clock_ctx, date, &extents); x = CLOCK_WIDTH/2 - ((extents.width / 2) + extents.x_bearing); - y = CLOCK_HEIGHT/2; + y = CLOCK_HEIGHT/2 - extents.y_bearing; cairo_move_to(clock_ctx, x, y); cairo_show_text(clock_ctx, date);