[PATCH v5 RESEND 09/10] config/udev: better distinguish between real keyboards and other key input devices

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Mon Jul 20 04:14:55 PDT 2015


This patch introduces a new flag ATTR_KEY for hotplugged input devices,
so we can better distinguish between real keyboards (i.e. devices with
udev property ID_INPUT_KEYBOARD="1") and other key input devices like
lid switches, power buttons, etc.

All supported hotplug backends (udev, hal, and wscons) will set both
flags ATTR_KEY and ATTR_KEYBOARD for real keyboards, but udev backend
will set ATTR_KEY, but not ATTR_KEYBOARD, for non-keyboard key input
devices (hal and wscons will set both flags in any case). With this
distinction, kdrive input hotplugging mechanism will be allowed to
only grab real keyboards, as other key input devices are currently
not supported.

In order to don't break current behaviour, this patch will replace all
ATTR_KEYBOARD occurrences with ATTR_KEY in hw/xfree86/common/xf86Xinput.c.

Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
---
 config/hal.c                   |  2 +-
 config/udev.c                  |  4 ++++
 config/wscons.c                |  2 +-
 hw/kdrive/src/kinput.c         |  4 +++-
 hw/xfree86/common/xf86Xinput.c |  2 +-
 include/input.h                | 13 +++++++------
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index ea574ca..c76eced 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -170,7 +170,7 @@ device_added(LibHalContext * hal_ctx, const char *udi)
     free(hal_tags);
 
     if (libhal_device_query_capability(hal_ctx, udi, "input.keys", NULL))
-        attrs.flags |= ATTR_KEYBOARD;
+        attrs.flags |= ATTR_KEY | ATTR_KEYBOARD;
     if (libhal_device_query_capability(hal_ctx, udi, "input.mouse", NULL))
         attrs.flags |= ATTR_POINTER;
     if (libhal_device_query_capability(hal_ctx, udi, "input.joystick", NULL))
diff --git a/config/udev.c b/config/udev.c
index 28c2658..958c95f 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -240,6 +240,10 @@ device_added(struct udev_device *udev_device)
         }
         else if (!strcmp(key, "ID_INPUT_KEY")) {
             LOG_PROPERTY(path, key, value);
+            attrs.flags |= ATTR_KEY;
+        }
+        else if (!strcmp(key, "ID_INPUT_KEYBOARD")) {
+            LOG_PROPERTY(path, key, value);
             attrs.flags |= ATTR_KEYBOARD;
         }
         else if (!strcmp(key, "ID_INPUT_MOUSE")) {
diff --git a/config/wscons.c b/config/wscons.c
index fb114bd..ee45675 100644
--- a/config/wscons.c
+++ b/config/wscons.c
@@ -163,7 +163,7 @@ wscons_add_keyboard(void)
         }
 
  kbd_config_done:
-    attrs.flags |= ATTR_KEYBOARD;
+    attrs.flags |= ATTR_KEY | ATTR_KEYBOARD;
     rc = NewInputDeviceRequest(input_options, &attrs, &dev);
     if (rc != Success)
         goto unwind;
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 8510ccd..6594f4f 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -2401,7 +2401,9 @@ NewInputDeviceRequest(InputOption *options, InputAttributes * attrs,
         *pdev = ki->dixdev;
     }
     else {
-        ErrorF("unrecognised device identifier!\n");
+        ErrorF("unrecognised device identifier: %s\n",
+               input_option_get_value(input_option_find(optionsdup,
+                                                        "device")));
         input_option_free_list(&optionsdup);
         return BadValue;
     }
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index a5b0568..bb2fbb7 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -632,7 +632,7 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev,
 
     /* MatchIs* booleans */
     if (iclass->is_keyboard.set &&
-        iclass->is_keyboard.val != ! !(attrs->flags & ATTR_KEYBOARD))
+        iclass->is_keyboard.val != ! !(attrs->flags & ATTR_KEY))
         return FALSE;
     if (iclass->is_pointer.set &&
         iclass->is_pointer.val != ! !(attrs->flags & ATTR_POINTER))
diff --git a/include/input.h b/include/input.h
index d8bd9c6..19ef0c9 100644
--- a/include/input.h
+++ b/include/input.h
@@ -230,12 +230,13 @@ typedef struct _InputAttributes {
     uint32_t flags;
 } InputAttributes;
 
-#define ATTR_KEYBOARD (1<<0)
-#define ATTR_POINTER (1<<1)
-#define ATTR_JOYSTICK (1<<2)
-#define ATTR_TABLET (1<<3)
-#define ATTR_TOUCHPAD (1<<4)
-#define ATTR_TOUCHSCREEN (1<<5)
+#define ATTR_KEY (1<<0)
+#define ATTR_KEYBOARD (1<<1)
+#define ATTR_POINTER (1<<2)
+#define ATTR_JOYSTICK (1<<3)
+#define ATTR_TABLET (1<<4)
+#define ATTR_TOUCHPAD (1<<5)
+#define ATTR_TOUCHSCREEN (1<<6)
 
 /* Key/Button has been run through all input processing and events sent to clients. */
 #define KEY_PROCESSED 1
-- 
2.3.6



More information about the xorg-devel mailing list