Browse Source

Merge pull request #106 from MrYakobo/master

Display a user provided string
master
Cassandra Fox 6 years ago
committed by GitHub
parent
commit
1d58ce0f52
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      fonts.h
  2. 20
      i3lock.1
  3. 54
      i3lock.c
  4. 42
      unlock_indicator.c
  5. 1
      unlock_indicator.h

3
fonts.h

@ -12,11 +12,12 @@
#define LAYOUT_FONT 2 #define LAYOUT_FONT 2
#define TIME_FONT 3 #define TIME_FONT 3
#define DATE_FONT 4 #define DATE_FONT 4
#define GREETER_FONT 5
typedef struct text { typedef struct text {
bool show; bool show;
char str[40]; char str[512];
double size; double size;
cairo_font_face_t *font; cairo_font_face_t *font;

20
i3lock.1

@ -249,8 +249,8 @@ iy - the y value of the indicator on the current display.
.RE .RE
.TP .TP
.B \-\-time\-align, \-\-date\-align, \-\-layout\-align, \-\-verif\-align, \-\-wrong\-align, \-\-modif\-align .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, and modifier text. Sets the text alignment of the time, date, keylayout, verification text, wrong text, modifier text and greeter text.
.RS .RS
.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. Sets the format used for generating the date string. See strftime(3) for a full list of format specifiers.
.TP .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. Sets the font used to render various strings.
.TP .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. Sets the font size used to render various strings.
.TP .TP
@ -292,6 +292,18 @@ ty - the computed y value of the timestring, for the current display.
.RE .RE
.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 .TP
.B \-\-refresh\-rate=seconds-as-double .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. 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.

54
i3lock.c

@ -88,6 +88,7 @@ char datecolor[9] = "000000ff";
char keyhlcolor[9] = "33db00ff"; char keyhlcolor[9] = "33db00ff";
char bshlcolor[9] = "db3300ff"; char bshlcolor[9] = "db3300ff";
char separatorcolor[9] = "000000ff"; 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 defining which display the lock indicator should be shown on. If -1, then show on all displays.*/
int screen_number = 0; int screen_number = 0;
@ -117,6 +118,7 @@ int time_align = 0;
int date_align = 0; int date_align = 0;
int layout_align = 0; int layout_align = 0;
int modif_align = 0; int modif_align = 0;
int greeter_align = 0;
char time_format[32] = "%H:%M:%S\0"; char time_format[32] = "%H:%M:%S\0";
char date_format[32] = "%A, %m %Y\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 layout_font[32] = "sans-serif\0";
char time_font[32] = "sans-serif\0"; char time_font[32] = "sans-serif\0";
char date_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, verif_font,
wrong_font, wrong_font,
layout_font, layout_font,
time_font, time_font,
date_font date_font,
greeter_font
}; };
char ind_x_expr[32] = "x + (w / 2)\0"; 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 verif_y_expr[32] = "iy\0";
char wrong_x_expr[32] = "ix\0"; char wrong_x_expr[32] = "ix\0";
char wrong_y_expr[32] = "iy\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 time_size = 32.0;
double date_size = 14.0; double date_size = 14.0;
@ -160,6 +166,7 @@ double modifier_size = 14.0;
double layout_size = 14.0; double layout_size = 14.0;
double circle_radius = 90.0; double circle_radius = 90.0;
double ring_width = 7.0; double ring_width = 7.0;
double greeter_size = 32.0;
char* verif_text = "verifying…"; char* verif_text = "verifying…";
char* wrong_text = "wrong!"; char* wrong_text = "wrong!";
@ -168,6 +175,7 @@ char* lock_text = "locking…";
char* lock_failed_text = "lock failed!"; char* lock_failed_text = "lock failed!";
int keylayout_mode = -1; int keylayout_mode = -1;
char* layout_text = NULL; char* layout_text = NULL;
char* greeter_text = "";
/* opts for blurring */ /* opts for blurring */
bool blur = false; bool blur = false;
@ -1206,6 +1214,7 @@ int main(int argc, char *argv[]) {
{"keyhlcolor", required_argument, NULL, 312}, {"keyhlcolor", required_argument, NULL, 312},
{"bshlcolor", required_argument, NULL, 313}, {"bshlcolor", required_argument, NULL, 313},
{"separatorcolor", required_argument, NULL, 314}, {"separatorcolor", required_argument, NULL, 314},
{"greetercolor", required_argument, NULL, 315},
{"line-uses-ring", no_argument, NULL, 'r'}, {"line-uses-ring", no_argument, NULL, 'r'},
{"line-uses-inside", no_argument, NULL, 's'}, {"line-uses-inside", no_argument, NULL, 's'},
@ -1226,6 +1235,7 @@ int main(int argc, char *argv[]) {
{"wrong-align", required_argument, NULL, 503}, {"wrong-align", required_argument, NULL, 503},
{"layout-align", required_argument, NULL, 504}, {"layout-align", required_argument, NULL, 504},
{"modif-align", required_argument, NULL, 505}, {"modif-align", required_argument, NULL, 505},
{"greeter-align", required_argument, NULL, 506},
// string stuff // string stuff
@ -1237,6 +1247,7 @@ int main(int argc, char *argv[]) {
{"noinputtext", required_argument, NULL, 515}, {"noinputtext", required_argument, NULL, 515},
{"locktext", required_argument, NULL, 516}, {"locktext", required_argument, NULL, 516},
{"lockfailedtext", required_argument, NULL, 517}, {"lockfailedtext", required_argument, NULL, 517},
{"greetertext", required_argument, NULL, 518},
// fonts // fonts
@ -1245,6 +1256,7 @@ int main(int argc, char *argv[]) {
{"verif-font", required_argument, NULL, 522}, {"verif-font", required_argument, NULL, 522},
{"wrong-font", required_argument, NULL, 523}, {"wrong-font", required_argument, NULL, 523},
{"layout-font", required_argument, NULL, 524}, {"layout-font", required_argument, NULL, 524},
{"greeter-font", required_argument, NULL, 525},
// text size // text size
@ -1254,6 +1266,7 @@ int main(int argc, char *argv[]) {
{"wrongsize", required_argument, NULL, 533}, {"wrongsize", required_argument, NULL, 533},
{"layoutsize", required_argument, NULL, 534}, {"layoutsize", required_argument, NULL, 534},
{"modsize", required_argument, NULL, 535}, {"modsize", required_argument, NULL, 535},
{"greetersize", required_argument, NULL, 536},
// text/indicator positioning // text/indicator positioning
@ -1265,6 +1278,7 @@ int main(int argc, char *argv[]) {
{"statuspos", required_argument, NULL, 545}, {"statuspos", required_argument, NULL, 545},
{"modifpos", required_argument, NULL, 546}, {"modifpos", required_argument, NULL, 546},
{"indpos", required_argument, NULL, 547}, {"indpos", required_argument, NULL, 547},
{"greeterpos", required_argument, NULL, 548},
// bar indicator stuff // bar indicator stuff
@ -1428,6 +1442,9 @@ int main(int argc, char *argv[]) {
case 314: case 314:
parse_color(separatorcolor); parse_color(separatorcolor);
break; break;
case 315:
parse_color(greetercolor);
break;
// general indicator opts // general indicator opts
case 400: case 400:
show_clock = true; show_clock = true;
@ -1486,6 +1503,11 @@ int main(int argc, char *argv[]) {
if (opt < 0 || opt > 2) opt = 0; if (opt < 0 || opt > 2) opt = 0;
modif_align = opt; modif_align = opt;
break; break;
case 506:
opt = atoi(optarg);
if (opt < 0 || opt > 2) opt = 0;
greeter_align = opt;
break;
// string stuff // string stuff
case 510: case 510:
if (strlen(optarg) > 31) { if (strlen(optarg) > 31) {
@ -1520,6 +1542,9 @@ int main(int argc, char *argv[]) {
case 517: case 517:
lock_failed_text = optarg; lock_failed_text = optarg;
break; break;
case 518:
greeter_text = optarg;
break;
// font stuff // font stuff
case 520: case 520:
if (strlen(optarg) > 31) { if (strlen(optarg) > 31) {
@ -1553,6 +1578,12 @@ int main(int argc, char *argv[]) {
} }
strcpy(fonts[LAYOUT_FONT],optarg); strcpy(fonts[LAYOUT_FONT],optarg);
break; 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 // text size
case 530: case 530:
arg = optarg; arg = optarg;
@ -1602,6 +1633,15 @@ int main(int argc, char *argv[]) {
modifier_size = 14.0; modifier_size = 14.0;
} }
break; 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 // Positions
case 540: case 540:
//read in to time_x_expr and time_y_expr //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"); errx(1, "indpos must be of the form x:y\n");
} }
break; 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 // bar indicator
case 700: case 700:
bar_enabled = true; bar_enabled = true;

42
unlock_indicator.c

@ -88,6 +88,7 @@ extern char datecolor[9];
extern char keyhlcolor[9]; extern char keyhlcolor[9];
extern char bshlcolor[9]; extern char bshlcolor[9];
extern char separatorcolor[9]; extern char separatorcolor[9];
extern char greetercolor[9];
extern int internal_line_source; extern int internal_line_source;
extern int screen_number; extern int screen_number;
@ -102,9 +103,10 @@ extern int time_align;
extern int date_align; extern int date_align;
extern int layout_align; extern int layout_align;
extern int modif_align; extern int modif_align;
extern int greeter_align;
extern char time_format[32]; extern char time_format[32];
extern char date_format[32]; extern char date_format[32];
extern char *fonts[5]; extern char *fonts[6];
extern char ind_x_expr[32]; extern char ind_x_expr[32];
extern char ind_y_expr[32]; extern char ind_y_expr[32];
extern char time_x_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 wrong_y_expr[32];
extern char modif_x_expr[32]; extern char modif_x_expr[32];
extern char modif_y_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 time_size;
extern double date_size; extern double date_size;
@ -128,6 +132,7 @@ extern double verif_size;
extern double wrong_size; extern double wrong_size;
extern double modifier_size; extern double modifier_size;
extern double layout_size; extern double layout_size;
extern double greeter_size;
extern char *verif_text; extern char *verif_text;
extern char *wrong_text; extern char *wrong_text;
@ -135,6 +140,7 @@ extern char *noinput_text;
extern char *lock_text; extern char *lock_text;
extern char *lock_failed_text; extern char *lock_failed_text;
extern char *layout_text; extern char *layout_text;
extern char *greeter_text;
/* Whether the failed attempts should be displayed. */ /* Whether the failed attempts should be displayed. */
extern bool show_failed_attempts; extern bool show_failed_attempts;
@ -182,6 +188,7 @@ rgba_t keyhl16;
rgba_t bshl16; rgba_t bshl16;
rgba_t sep16; rgba_t sep16;
rgba_t bar16; rgba_t bar16;
rgba_t greeter16;
// just rgb // just rgb
rgb_t rgb16; rgb_t rgb16;
@ -206,7 +213,8 @@ extern char bar_expr[32];
extern bool bar_bidirectional; extern bool bar_bidirectional;
extern bool bar_reversed; extern bool bar_reversed;
static cairo_font_face_t *font_faces[5] = { static cairo_font_face_t *font_faces[6] = {
NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -602,6 +610,7 @@ void init_colors_once(void) {
colorgen(&tmp, bshlcolor, &bshl16); colorgen(&tmp, bshlcolor, &bshl16);
colorgen(&tmp, separatorcolor, &sep16); colorgen(&tmp, separatorcolor, &sep16);
colorgen(&tmp, bar_base_color, &bar16); colorgen(&tmp, bar_base_color, &bar16);
colorgen(&tmp, greetercolor, &greeter16);
colorgen_rgb(&tmp_rgb, color, &rgb16); 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->mod_text);
draw_text(ctx, draw_data->time_text); draw_text(ctx, draw_data->time_text);
draw_text(ctx, draw_data->date_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; 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)) { if (show_clock && (!draw_data.status_text.show || always_show_clock)) {
time_t rawtime; time_t rawtime;
struct tm *timeinfo; 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.font = get_font_face(DATE_FONT);
draw_data.date_text.align = date_align; 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 // 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_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_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 (xr_screens > 0) {
if (screen_number < 0 || screen_number > xr_screens) { if (screen_number < 0 || screen_number > xr_screens) {
screen_number = 0; screen_number = 0;
@ -901,6 +931,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
draw_data.time_text.y = 0; draw_data.time_text.y = 0;
draw_data.date_text.x = 0; draw_data.date_text.x = 0;
draw_data.date_text.y = 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; width = xr_resolutions[current_screen].width / scaling_factor;
height = xr_resolutions[current_screen].height / 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.date_text.y = te_eval(te_date_y_expr);
draw_data.keylayout_text.x = te_eval(te_layout_x_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.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) { switch (auth_state) {
case STATE_AUTH_VERIFY: 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.date_text.y = te_eval(te_date_y_expr);
draw_data.keylayout_text.x = te_eval(te_layout_x_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.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) { switch (auth_state) {
case STATE_AUTH_VERIFY: case STATE_AUTH_VERIFY:
case STATE_AUTH_LOCK: 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_x_expr);
te_free(te_modif_y_expr); te_free(te_modif_y_expr);
te_free(te_bar_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_set_source_surface(xcb_ctx, output, 0, 0);
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);

1
unlock_indicator.h

@ -30,6 +30,7 @@ typedef struct {
text_t keylayout_text; text_t keylayout_text;
text_t time_text; text_t time_text;
text_t date_text; text_t date_text;
text_t greeter_text;
double indicator_x, indicator_y; double indicator_x, indicator_y;

Loading…
Cancel
Save