[PATCH 3/4] tty/vt/keyboard: reset the LEDs state at each console change

From: Benjamin Tissoires
Date: Fri Jan 27 2017 - 12:26:01 EST


When switching between consoles, the LEDs state is correctly
assigned, as long as the kernel manages the console.
When switching back from Gnome, the VT is not aware of the
current state of the LEDs. So if Gnome changes them, the
kernel still bellieves they are off, and it won't turn them
off when switching to a new TTY.

To keep the LEDs status in sync with the actual modifiers,
simply force a reset of the LEDs when we detect a vt change.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@xxxxxxxxxx>
---
drivers/tty/vt/keyboard.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index ca1d614..410b21e 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -137,6 +137,8 @@ static unsigned char ledioctl;
static bool caps_as_controlllock;
static bool task_caps_as_controlllock;

+static int saved_cur_kbd_console = -1;
+
/*
* Notifier list for console keyboard events
*/
@@ -1482,6 +1484,12 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
/* We are called with interrupts disabled, just take the lock */
spin_lock(&kbd_event_lock);

+ /* reset the led state on console switch */
+ if (saved_cur_kbd_console != fg_console) {
+ ledstate = -1U;
+ saved_cur_kbd_console = fg_console;
+ }
+
if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
kbd_rawcode(value);
if (event_type == EV_KEY)
--
2.9.3