From 556cc7f0a86258105ca5c2907745ff2a6c1b6d0f Mon Sep 17 00:00:00 2001 From: Jakob Lindskog Date: Fri, 5 Oct 2018 16:40:50 +0200 Subject: [PATCH] add greeter option, which displays a user provided string --- fonts.h | 3 ++- i3lock.1 | 20 +++++++++++++---- i3lock.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-- unlock_indicator.c | 42 ++++++++++++++++++++++++++++++++++-- unlock_indicator.h | 1 + 5 files changed, 111 insertions(+), 9 deletions(-) diff --git a/fonts.h b/fonts.h index f3595b8..e178687 100644 --- a/fonts.h +++ b/fonts.h @@ -12,11 +12,12 @@ #define LAYOUT_FONT 2 #define TIME_FONT 3 #define DATE_FONT 4 +#define GREETER_FONT 5 typedef struct text { bool show; - char str[40]; + char str[512]; double size; cairo_font_face_t *font; diff --git a/i3lock.1 b/i3lock.1 index 761a6bd..d5c5587 100644 --- a/i3lock.1 +++ b/i3lock.1 @@ -249,8 +249,8 @@ iy - the y value of the indicator on the current display. .RE .TP -.B \-\-time\-align, \-\-date\-align, \-\-layout\-align, \-\-verif\-align, \-\-wrong\-align, \-\-modif\-align -Sets the text alignment of the time, date, keylayout, verification text, wrong text, and modifier text. +.B \-\-time\-align, \-\-date\-align, \-\-layout\-align, \-\-verif\-align, \-\-wrong\-align, \-\-modif\-align, \-\-greeter\-align +Sets the text alignment of the time, date, keylayout, verification text, wrong text, modifier text and greeter text. .RS .RS @@ -272,11 +272,11 @@ Sets the color of the date in the clock. Sets the format used for generating the date string. See strftime(3) for a full list of format specifiers. .TP -.B \-\-{time, date, layout, verif, wrong}\-font=sans-serif +.B \-\-{time, date, layout, verif, wrong, greeter}\-font=sans-serif Sets the font used to render various strings. .TP -.B \-\-{time, date, layout, verif, wrong}size=number +.B \-\-{time, date, layout, verif, wrong, greeter}size=number Sets the font size used to render various strings. .TP @@ -292,6 +292,18 @@ ty - the computed y value of the timestring, for the current display. .RE .RE +.TP +.B \-\-greetertext="text" +Sets the greeter text. Defaults to "". + +.TP +.B \-\-greetercolor=rrggbbaa +Sets the color of the greeter text. + +.TP +.B \-\-greeterpos="x position:y position" +Sets the position for the date string. All the variables from \-\-indpos and \-\-timepos may be used. + .TP .B \-\-refresh\-rate=seconds-as-double The refresh rate of the indicator, given in seconds. This should automatically align itself, but is somewhat buggy currently. Values less than one will work, but may result in poor system performance. diff --git a/i3lock.c b/i3lock.c index d3fcee8..2578b09 100644 --- a/i3lock.c +++ b/i3lock.c @@ -88,6 +88,7 @@ char datecolor[9] = "000000ff"; char keyhlcolor[9] = "33db00ff"; char bshlcolor[9] = "db3300ff"; char separatorcolor[9] = "000000ff"; +char greetercolor[9] = "000000ff"; /* int defining which display the lock indicator should be shown on. If -1, then show on all displays.*/ int screen_number = 0; @@ -117,6 +118,7 @@ int time_align = 0; int date_align = 0; int layout_align = 0; int modif_align = 0; +int greeter_align = 0; char time_format[32] = "%H:%M:%S\0"; char date_format[32] = "%A, %m %Y\0"; @@ -126,13 +128,15 @@ char wrong_font[32] = "sans-serif\0"; char layout_font[32] = "sans-serif\0"; char time_font[32] = "sans-serif\0"; char date_font[32] = "sans-serif\0"; +char greeter_font[32] = "sans-serif\0"; -char* fonts[5] = { +char* fonts[6] = { verif_font, wrong_font, layout_font, time_font, - date_font + date_font, + greeter_font }; char ind_x_expr[32] = "x + (w / 2)\0"; @@ -151,6 +155,8 @@ char verif_x_expr[32] = "ix\0"; char verif_y_expr[32] = "iy\0"; char wrong_x_expr[32] = "ix\0"; char wrong_y_expr[32] = "iy\0"; +char greeter_x_expr[32] = "ix\0"; +char greeter_y_expr[32] = "ix\0"; double time_size = 32.0; double date_size = 14.0; @@ -160,6 +166,7 @@ double modifier_size = 14.0; double layout_size = 14.0; double circle_radius = 90.0; double ring_width = 7.0; +double greeter_size = 32.0; char* verif_text = "verifying…"; char* wrong_text = "wrong!"; @@ -168,6 +175,7 @@ char* lock_text = "locking…"; char* lock_failed_text = "lock failed!"; int keylayout_mode = -1; char* layout_text = NULL; +char* greeter_text = ""; /* opts for blurring */ bool blur = false; @@ -1206,6 +1214,7 @@ int main(int argc, char *argv[]) { {"keyhlcolor", required_argument, NULL, 312}, {"bshlcolor", required_argument, NULL, 313}, {"separatorcolor", required_argument, NULL, 314}, + {"greetercolor", required_argument, NULL, 315}, {"line-uses-ring", no_argument, NULL, 'r'}, {"line-uses-inside", no_argument, NULL, 's'}, @@ -1226,6 +1235,7 @@ int main(int argc, char *argv[]) { {"wrong-align", required_argument, NULL, 503}, {"layout-align", required_argument, NULL, 504}, {"modif-align", required_argument, NULL, 505}, + {"greeter-align", required_argument, NULL, 506}, // string stuff @@ -1237,6 +1247,7 @@ int main(int argc, char *argv[]) { {"noinputtext", required_argument, NULL, 515}, {"locktext", required_argument, NULL, 516}, {"lockfailedtext", required_argument, NULL, 517}, + {"greetertext", required_argument, NULL, 518}, // fonts @@ -1245,6 +1256,7 @@ int main(int argc, char *argv[]) { {"verif-font", required_argument, NULL, 522}, {"wrong-font", required_argument, NULL, 523}, {"layout-font", required_argument, NULL, 524}, + {"greeter-font", required_argument, NULL, 525}, // text size @@ -1254,6 +1266,7 @@ int main(int argc, char *argv[]) { {"wrongsize", required_argument, NULL, 533}, {"layoutsize", required_argument, NULL, 534}, {"modsize", required_argument, NULL, 535}, + {"greetersize", required_argument, NULL, 536}, // text/indicator positioning @@ -1265,6 +1278,7 @@ int main(int argc, char *argv[]) { {"statuspos", required_argument, NULL, 545}, {"modifpos", required_argument, NULL, 546}, {"indpos", required_argument, NULL, 547}, + {"greeterpos", required_argument, NULL, 548}, // bar indicator stuff @@ -1428,6 +1442,9 @@ int main(int argc, char *argv[]) { case 314: parse_color(separatorcolor); break; + case 315: + parse_color(greetercolor); + break; // general indicator opts case 400: show_clock = true; @@ -1486,6 +1503,11 @@ int main(int argc, char *argv[]) { if (opt < 0 || opt > 2) opt = 0; modif_align = opt; break; + case 506: + opt = atoi(optarg); + if (opt < 0 || opt > 2) opt = 0; + greeter_align = opt; + break; // string stuff case 510: if (strlen(optarg) > 31) { @@ -1520,6 +1542,9 @@ int main(int argc, char *argv[]) { case 517: lock_failed_text = optarg; break; + case 518: + greeter_text = optarg; + break; // font stuff case 520: if (strlen(optarg) > 31) { @@ -1553,6 +1578,12 @@ int main(int argc, char *argv[]) { } strcpy(fonts[LAYOUT_FONT],optarg); break; + case 525: + if (strlen(optarg) > 31) { + errx(1, "greeter font string can be at most 31 characters\n"); + } + strcpy(fonts[GREETER_FONT],optarg); + break; // text size case 530: arg = optarg; @@ -1602,6 +1633,15 @@ int main(int argc, char *argv[]) { modifier_size = 14.0; } break; + case 536: + arg = optarg; + if (sscanf(arg, "%lf", &greeter_size) != 1) + errx(1, "greetersize must be a number\n"); + if (greeter_size < 1) { + fprintf(stderr, "greetersize must be a positive integer; ignoring...\n"); + greeter_size = 14.0; + } + break; // Positions case 540: //read in to time_x_expr and time_y_expr @@ -1683,6 +1723,16 @@ int main(int argc, char *argv[]) { errx(1, "indpos must be of the form x:y\n"); } break; + case 548: + 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, "indicator position string can be at most 31 characters\n"); + } + arg = optarg; + if (sscanf(arg, "%30[^:]:%30[^:]", greeter_x_expr, greeter_y_expr) != 2) { + errx(1, "indpos must be of the form x:y\n"); + } + break; // bar indicator case 700: bar_enabled = true; diff --git a/unlock_indicator.c b/unlock_indicator.c index 18f3d40..706d270 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -88,6 +88,7 @@ extern char datecolor[9]; extern char keyhlcolor[9]; extern char bshlcolor[9]; extern char separatorcolor[9]; +extern char greetercolor[9]; extern int internal_line_source; extern int screen_number; @@ -102,9 +103,10 @@ extern int time_align; extern int date_align; extern int layout_align; extern int modif_align; +extern int greeter_align; extern char time_format[32]; extern char date_format[32]; -extern char *fonts[5]; +extern char *fonts[6]; extern char ind_x_expr[32]; extern char ind_y_expr[32]; extern char time_x_expr[32]; @@ -121,6 +123,8 @@ extern char wrong_x_expr[32]; extern char wrong_y_expr[32]; extern char modif_x_expr[32]; extern char modif_y_expr[32]; +extern char greeter_x_expr[32]; +extern char greeter_y_expr[32]; extern double time_size; extern double date_size; @@ -128,6 +132,7 @@ extern double verif_size; extern double wrong_size; extern double modifier_size; extern double layout_size; +extern double greeter_size; extern char *verif_text; extern char *wrong_text; @@ -135,6 +140,7 @@ extern char *noinput_text; extern char *lock_text; extern char *lock_failed_text; extern char *layout_text; +extern char *greeter_text; /* Whether the failed attempts should be displayed. */ extern bool show_failed_attempts; @@ -182,6 +188,7 @@ rgba_t keyhl16; rgba_t bshl16; rgba_t sep16; rgba_t bar16; +rgba_t greeter16; // just rgb rgb_t rgb16; @@ -206,7 +213,8 @@ extern char bar_expr[32]; extern bool bar_bidirectional; extern bool bar_reversed; -static cairo_font_face_t *font_faces[5] = { +static cairo_font_face_t *font_faces[6] = { + NULL, NULL, NULL, NULL, @@ -602,6 +610,7 @@ void init_colors_once(void) { colorgen(&tmp, bshlcolor, &bshl16); colorgen(&tmp, separatorcolor, &sep16); colorgen(&tmp, bar_base_color, &bar16); + colorgen(&tmp, greetercolor, &greeter16); colorgen_rgb(&tmp_rgb, color, &rgb16); } @@ -658,6 +667,7 @@ static void draw_elements(cairo_t *const ctx, DrawData const *const draw_data) { draw_text(ctx, draw_data->mod_text); draw_text(ctx, draw_data->time_text); draw_text(ctx, draw_data->date_text); + draw_text(ctx, draw_data->greeter_text); } /* @@ -822,6 +832,15 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { draw_data.keylayout_text.align = layout_align; } + if (greeter_text) { + draw_data.greeter_text.show = true; + strncpy(draw_data.greeter_text.str, greeter_text, sizeof(draw_data.greeter_text.str) - 1); + draw_data.greeter_text.size = greeter_size; + draw_data.greeter_text.font = get_font_face(GREETER_FONT); + draw_data.greeter_text.color = greeter16; + draw_data.greeter_text.align = greeter_align; + } + if (show_clock && (!draw_data.status_text.show || always_show_clock)) { time_t rawtime; struct tm *timeinfo; @@ -844,6 +863,14 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { draw_data.date_text.font = get_font_face(DATE_FONT); draw_data.date_text.align = date_align; } + + if (*draw_data.greeter_text.str) { + draw_data.greeter_text.show = true; + draw_data.greeter_text.size = greeter_size; + draw_data.greeter_text.color = greeter16; + draw_data.greeter_text.font = get_font_face(GREETER_FONT); + draw_data.greeter_text.align = greeter_align; + } } // initialize positioning vars @@ -887,6 +914,9 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { te_expr *te_modif_y_expr = compile_expression("--modifpos", modif_y_expr, vars, vars_size); te_expr *te_bar_expr = compile_expression("--bar-position", bar_expr, vars, vars_size); + te_expr *te_greeter_x_expr = compile_expression("--greeterpos", greeter_x_expr, vars, vars_size); + te_expr *te_greeter_y_expr = compile_expression("--greeterpos", greeter_y_expr, vars, vars_size); + if (xr_screens > 0) { if (screen_number < 0 || screen_number > xr_screens) { screen_number = 0; @@ -901,6 +931,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { draw_data.time_text.y = 0; draw_data.date_text.x = 0; draw_data.date_text.y = 0; + draw_data.greeter_text.x = 0; + draw_data.greeter_text.y = 0; width = xr_resolutions[current_screen].width / scaling_factor; height = xr_resolutions[current_screen].height / scaling_factor; @@ -922,6 +954,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { draw_data.date_text.y = te_eval(te_date_y_expr); draw_data.keylayout_text.x = te_eval(te_layout_x_expr); draw_data.keylayout_text.y = te_eval(te_layout_y_expr); + draw_data.greeter_text.x = te_eval(te_greeter_x_expr); + draw_data.greeter_text.y = te_eval(te_greeter_y_expr); switch (auth_state) { case STATE_AUTH_VERIFY: @@ -970,6 +1004,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { draw_data.date_text.y = te_eval(te_date_y_expr); draw_data.keylayout_text.x = te_eval(te_layout_x_expr); draw_data.keylayout_text.y = te_eval(te_layout_y_expr); + draw_data.greeter_text.x = te_eval(te_greeter_x_expr); + draw_data.greeter_text.y = te_eval(te_greeter_y_expr); switch (auth_state) { case STATE_AUTH_VERIFY: case STATE_AUTH_LOCK: @@ -1017,6 +1053,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { te_free(te_modif_x_expr); te_free(te_modif_y_expr); te_free(te_bar_expr); + te_free(te_greeter_x_expr); + te_free(te_greeter_y_expr); cairo_set_source_surface(xcb_ctx, output, 0, 0); cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); diff --git a/unlock_indicator.h b/unlock_indicator.h index d71f48c..90e247e 100644 --- a/unlock_indicator.h +++ b/unlock_indicator.h @@ -30,6 +30,7 @@ typedef struct { text_t keylayout_text; text_t time_text; text_t date_text; + text_t greeter_text; double indicator_x, indicator_y;