I’m using the KMSDRM backend of SDL2 for a Linux console application.Most of the things work as expected but the Keyboard LEDs (NumLock, CapsLock, SrollLock) don’t.
So I looked at the souce code in SDL_evdev_kbd.c and found an ioctl() with KDGKBLED to read the keyboard LED states, but I couldn’t find anything which sets the LED state. Therefore I naively tried adding another ioctl() whenever the “ledflagstate” is changed:
diff -r c70cf178aacb src/core/linux/SDL_evdev_kbd.c --- a/src/core/linux/SDL_evdev_kbd.c Sun Dec 10 09:17:33 2017 -0800 +++ b/src/core/linux/SDL_evdev_kbd.c Mon Dec 11 11:54:45 2017 +0100 @@ -350,17 +350,19 @@ static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - return ((kbd->ledflagstate >> flag) & 1); + return (kbd->ledflagstate & flag) != 0; } static void set_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate |= 1 <ledflagstate |= flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); } static void clr_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate &= ~(1 <ledflagstate &= ~flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); } static void chg_vc_kbd_lock(SDL_EVDEV_keyboard_state *kbd, int flag) @@ -375,7 +377,8 @@ static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate ^= 1 <ledflagstate ^= flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); }
Note, that I also changed replaced “1<<flag” with “flag”. I think the left shift is not necessary because the LED flag values are powers of two already.
With this change I got the NumLock LED working, but CapsLock still doesn’t.
What am I missing here?
-Rainer