From 42d414f9f760c97244d1b1f774d853c7d0b79f7e Mon Sep 17 00:00:00 2001 From: n3rdopolis Date: Mon, 2 Jan 2023 11:57:21 -0500 Subject: [PATCH] ply-input-device: Ensure that the LED state is updated on the keyboard of which the lock key was pressed on When a lock modifier is pressed, plymouth goes through some gymnastics to ensure the LEDs on all attached keyboards are appropriately updated. Unfortunately, an optimization in the code used to avoid redundant updates of keyboards that already have the correct state is actually preventing the initiating keyboard from getting its LEDs turned on. This is because the initiating keyboard gets its state updated at key press time before the LED handling code runs, thus making it seem like that run is redundant. This commit introduces a new state variable `leds_state_invalid` on the input device to mark this situation and updates the optimization check to also check the new variable. Some contributions by Ray Strode. --- src/libply-splash-core/ply-input-device.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libply-splash-core/ply-input-device.c b/src/libply-splash-core/ply-input-device.c index be473fc5..fc92de56 100644 --- a/src/libply-splash-core/ply-input-device.c +++ b/src/libply-splash-core/ply-input-device.c @@ -61,6 +61,8 @@ struct _ply_input_device struct xkb_compose_state *compose_state; struct libevdev *dev; + + uint32_t leds_state_invalid : 1; }; static bool @@ -204,8 +206,10 @@ on_input (ply_input_device_t *input_device) updated_state = xkb_state_update_key (input_device->keyboard_state, keycode, xkb_key_direction); - if ((updated_state & XKB_STATE_LEDS) != 0) + if ((updated_state & XKB_STATE_LEDS) != 0) { + input_device->leds_state_invalid = true; ply_trigger_pull (input_device->leds_changed_trigger, input_device); + } /* If the key is repeating, or is being pressed down */ if (key_state == PLY_KEY_HELD || key_state == PLY_KEY_DOWN) @@ -384,7 +388,8 @@ ply_input_device_set_state (ply_input_device_t *input_device, if (mods_depressed == xkb_state->mods_depressed && mods_latched == xkb_state->mods_latched && mods_locked == xkb_state->mods_locked && - group == xkb_state->group) + group == xkb_state->group && + !input_device->leds_state_invalid) return; mods_depressed = xkb_state->mods_depressed; @@ -414,6 +419,7 @@ ply_input_device_set_state (ply_input_device_t *input_device, ev[i].code = SYN_REPORT; ply_write (input_device->fd, ev, sizeof(ev)); + input_device->leds_state_invalid = false; } ply_xkb_keyboard_state_t