[PATCH evdev 4/4] Expand product check to include all keyboards defined in the kernel

Peter Hutterer peter.hutterer at who-t.net
Tue May 17 22:00:58 PDT 2011


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/apple.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/src/apple.c b/src/apple.c
index 1a82e2a..03345ac 100644
--- a/src/apple.c
+++ b/src/apple.c
@@ -53,12 +53,58 @@
  */
 
 #define FNMODE_PATH "/sys/module/hid_apple/parameters/fnmode"
-#define APPLE_VENDOR 0x5ac
-#define APPLE_KEYBOARD 0x220
+
+/* Taken from the kernel */
+#define USB_VENDOR_ID_APPLE                             0x05ac
+#define USB_DEVICE_ID_APPLE_ALU_MINI_ANSI               0x021d
+#define USB_DEVICE_ID_APPLE_ALU_MINI_ISO                0x021e
+#define USB_DEVICE_ID_APPLE_ALU_MINI_JIS                0x021f
+#define USB_DEVICE_ID_APPLE_ALU_ANSI                    0x0220
+#define USB_DEVICE_ID_APPLE_ALU_ISO                     0x0221
+#define USB_DEVICE_ID_APPLE_ALU_JIS                     0x0222
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI           0x022c
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO            0x022d
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS            0x022e
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI      0x0239
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO       0x023a
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS       0x023b
+
 
 static Atom prop_fnmode;
 static Bool fnmode_readonly; /* set if we can only read fnmode */
 
+struct product_table
+{
+    unsigned int vendor;
+    unsigned int product;
+} apple_keyboard_table[] = {
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO},
+    { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS},
+    { 0, 0}
+};
+
+/**
+ * @return TRUE if the device matches a product in the given product table,
+ *         FALSE otherwise
+ * */
+static Bool product_check(const struct product_table *t, int vendor, int product)
+{
+    while (t->vendor)
+        if (vendor == t->vendor && product == t->product)
+            return TRUE;
+
+    return FALSE;
+}
 
 /**
  * @retval 0 fnmode is set to function keys
@@ -149,8 +195,8 @@ EvdevAppleInitProperty(DeviceIntPtr dev)
     EvdevPtr     pEvdev = pInfo->private;
     char fnmode;
 
-    if (pEvdev->id_vendor != APPLE_VENDOR ||
-        pEvdev->id_product != APPLE_KEYBOARD)
+    if (!product_check(apple_keyboard_table,
+                       pEvdev->id_vendor, pEvdev->id_product))
         return;
 
     fnmode = get_fnmode();
-- 
1.7.4.4



More information about the xorg-devel mailing list