From 66bd7af3e59e509000b8a55a9429e7a8e133fd81 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 14 Mar 2023 23:30:32 +0100 Subject: Sync with upstream 2.14.1 and update the documentation --- unlock_indicator.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'unlock_indicator.c') diff --git a/unlock_indicator.c b/unlock_indicator.c index 8f69972..6f6fbf7 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -1,6 +1,6 @@ /* * This file is part of i3lock-extended - * Copyright (C) 2020 Simeon Simeonov + * Copyright (C) 2020-2023 Simeon Simeonov * i3lock-extended is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -103,6 +104,9 @@ extern bool show_failed_attempts; /* Number of failed unlock attempts. */ extern int failed_attempts; +extern struct xkb_keymap *xkb_keymap; +extern struct xkb_state *xkb_state; + /******************************************************************************* * Variables defined in xcb.c. ******************************************************************************/ @@ -122,6 +126,44 @@ static xcb_visualtype_t *vistype; unlock_state_t unlock_state; auth_state_t auth_state; +/* check_modifier_keys describes the currently active modifiers (Caps Lock, Alt, + Num Lock or Super) in the modifier_string variable. */ +static void check_modifier_keys(void) { + xkb_mod_index_t idx, num_mods; + const char *mod_name; + + num_mods = xkb_keymap_num_mods(xkb_keymap); + + for (idx = 0; idx < num_mods; idx++) { + if (!xkb_state_mod_index_is_active(xkb_state, idx, XKB_STATE_MODS_EFFECTIVE)) + continue; + + mod_name = xkb_keymap_mod_get_name(xkb_keymap, idx); + if (mod_name == NULL) + continue; + + /* Replace certain xkb names with nicer, human-readable ones. */ + if (strcmp(mod_name, XKB_MOD_NAME_CAPS) == 0) { + mod_name = "Caps Lock"; + } else if (strcmp(mod_name, XKB_MOD_NAME_NUM) == 0) { + mod_name = "Num Lock"; + } else { + /* Show only Caps Lock and Num Lock, other modifiers (e.g. Shift) + * leak state about the password. */ + continue; + } + + char *tmp; + if (modifier_string == NULL) { + if (asprintf(&tmp, "%s", mod_name) != -1) + modifier_string = tmp; + } else if (asprintf(&tmp, "%s, %s", modifier_string, mod_name) != -1) { + free(modifier_string); + modifier_string = tmp; + } + } +} + /* * Draws global image with fill color onto a pixmap with the given * resolution and returns it. @@ -291,7 +333,7 @@ void draw_image(xcb_pixmap_t bg_pixmap, uint32_t *resolution) { cairo_close_path(ctx); } - if (auth_state == STATE_AUTH_WRONG && (modifier_string != NULL)) { + if (modifier_string != NULL) { cairo_text_extents_t extents; double x, y; @@ -432,6 +474,13 @@ void free_bg_pixmap(void) { */ void redraw_screen(void) { DEBUG("redraw_screen(unlock_state = %d, auth_state = %d)\n", unlock_state, auth_state); + + if (modifier_string) { + free(modifier_string); + modifier_string = NULL; + } + check_modifier_keys(); + if (bg_pixmap == XCB_NONE) { DEBUG("allocating pixmap for %d x %d px\n", last_resolution[0], last_resolution[1]); bg_pixmap = create_bg_pixmap(conn, screen, last_resolution, color); -- cgit v1.3