From 4c09fb0dd0f7578c96e5a00d45891f92fd7c5d36 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Nov 2014 17:23:47 +0100 Subject: [PATCH] input_id: Detect whether keyboards have lock LEDs Use capabilities/led whether to detect whether keyboards have NumLock and/or CapsLock LEDs. This allows desktops to show an OSD when the CapsLock/NumLock status changes if the keyboard doesn't have any such LEDs. https://bugs.freedesktop.org/show_bug.cgi?id=86257 --- src/udev/udev-builtin-input_id.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 1a1121e..31d8c2d 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -152,6 +152,7 @@ static void test_pointers (struct udev_device *dev, static void test_key (struct udev_device *dev, const unsigned long* bitmask_ev, const unsigned long* bitmask_key, + const unsigned long* bitmask_led, bool test) { unsigned i; unsigned long found; @@ -188,6 +189,11 @@ static void test_key (struct udev_device *dev, mask = 0xFFFFFFFE; if ((bitmask_key[0] & mask) == mask) udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1"); + + if (test_bit(LED_NUML, bitmask_led)) + udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD_HAS_NUMLOCK_LED", "1"); + if (test_bit(LED_CAPSL, bitmask_led)) + udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD_HAS_CAPSLOCK_LED", "1"); } static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], bool test) { @@ -196,6 +202,7 @@ static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], boo unsigned long bitmask_abs[NBITS(ABS_MAX)]; unsigned long bitmask_key[NBITS(KEY_MAX)]; unsigned long bitmask_rel[NBITS(REL_MAX)]; + unsigned long bitmask_leds[NBITS(LED_MAX)]; /* walk up the parental chain until we find the real input device; the * argument is very likely a subdevice of this, like eventN */ @@ -214,8 +221,9 @@ static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], boo get_cap_mask(dev, pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test); get_cap_mask(dev, pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test); get_cap_mask(dev, pdev, "capabilities/key", bitmask_key, sizeof(bitmask_key), test); + get_cap_mask(dev, pdev, "capabilities/leds", bitmask_leds, sizeof(bitmask_leds), test); test_pointers(dev, bitmask_ev, bitmask_abs, bitmask_key, bitmask_rel, test); - test_key(dev, bitmask_ev, bitmask_key, test); + test_key(dev, bitmask_ev, bitmask_key, bitmask_leds, test); return EXIT_SUCCESS; } -- 2.1.0