Fixed bug 4347 - Keyboard LEDs don't work on linux console
authorSam Lantinga <slouken@libsdl.org>
Wed, 31 Oct 2018 15:01:20 -0700
changeset 12375d9a16c76d8d1
parent 12374 0f9e74a94e62
child 12376 cfc65d4d49ae
Fixed bug 4347 - Keyboard LEDs don't work on linux console

Rainer Sabelka

When using SLD2 on a Linux console with the KMS/DRM video backend and Linux evdev keyboard support, the caps lock, scroll lock, and num lock leds do not work.

The attached patch adds ioctls for setting the LED state in SDL_evdev_kbd.c
src/core/linux/SDL_evdev_kbd.c
     1.1 --- a/src/core/linux/SDL_evdev_kbd.c	Wed Oct 31 10:18:05 2018 -0700
     1.2 +++ b/src/core/linux/SDL_evdev_kbd.c	Wed Oct 31 15:01:20 2018 -0700
     1.3 @@ -510,17 +510,19 @@
     1.4  
     1.5  static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
     1.6  {
     1.7 -    return ((kbd->ledflagstate >> flag) & 1);
     1.8 +    return (kbd->ledflagstate & flag) != 0;
     1.9  }
    1.10  
    1.11  static void set_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
    1.12  {
    1.13 -    kbd->ledflagstate |= 1 << flag;
    1.14 +    kbd->ledflagstate |= flag;
    1.15 +    ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate));
    1.16  }
    1.17  
    1.18  static void clr_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
    1.19  {
    1.20 -    kbd->ledflagstate &= ~(1 << flag);
    1.21 +    kbd->ledflagstate &= ~flag;
    1.22 +    ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate));
    1.23  }
    1.24  
    1.25  static void chg_vc_kbd_lock(SDL_EVDEV_keyboard_state *kbd, int flag)
    1.26 @@ -535,7 +537,8 @@
    1.27  
    1.28  static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
    1.29  {
    1.30 -    kbd->ledflagstate ^= 1 << flag;
    1.31 +    kbd->ledflagstate ^= flag;
    1.32 +    ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate));
    1.33  }
    1.34  
    1.35  /*