Make clock font size modifiable

This commit is contained in:
Aline 2017-05-19 16:14:37 +02:00
parent e64f9adedc
commit e26171d545
2 changed files with 36 additions and 10 deletions

View File

@ -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;

View File

@ -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);