evdev: read LIBINPUT_ATTR_KEYBOARD_INTEGRATION property
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 22 May 2017 03:34:10 +0000 (13:34 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 May 2017 05:10:10 +0000 (15:10 +1000)
We have heuristics for detecting whether a keyboard is internal or external,
but in some cases (e.g. Surface 3) these heuristics fail. Add a udev property
that we can apply to these cases so we have something that's reliable.

This will likely eventually become ID_INPUT_KEYBOARD_INTEGRATION as shipped by
systemd, similar to the touchpad property.

https://bugs.freedesktop.org/show_bug.cgi?id=101101

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev-mt-touchpad.c
src/evdev.c
src/evdev.h
udev/90-libinput-model-quirks.hwdb
udev/90-libinput-model-quirks.rules.in
udev/parse_hwdb.py

index 17b14bc854edda4abcda81337d072bc8c6f2a277..e5f2a5cee813214f7d2ea911560d39370a583b73 100644 (file)
@@ -1601,8 +1601,7 @@ tp_want_dwt(struct evdev_device *touchpad,
        /* For Apple touchpads, always use its internal keyboard */
        if (vendor_tp == VENDOR_ID_APPLE) {
                return vendor_kbd == vendor_tp &&
-                      keyboard->model_flags &
-                               EVDEV_MODEL_APPLE_INTERNAL_KEYBOARD;
+                      keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD;
        }
 
        /* everything else we don't really know, so we have to assume
index f7a019c66405d7d4c9b18e1a1850ff499d01b483..02ed4f1ab1628fdc44c7d8707956f69aae6b820f 100644 (file)
@@ -1089,10 +1089,25 @@ evdev_tag_trackpoint(struct evdev_device *device,
                device->tags |= EVDEV_TAG_TRACKPOINT;
 }
 
+static inline void
+evdev_tag_keyboard_internal(struct evdev_device *device)
+{
+       device->tags |= EVDEV_TAG_INTERNAL_KEYBOARD;
+       device->tags &= ~EVDEV_TAG_EXTERNAL_KEYBOARD;
+}
+
+static inline void
+evdev_tag_keyboard_external(struct evdev_device *device)
+{
+       device->tags |= EVDEV_TAG_EXTERNAL_KEYBOARD;
+       device->tags &= ~EVDEV_TAG_INTERNAL_KEYBOARD;
+}
+
 static void
 evdev_tag_keyboard(struct evdev_device *device,
                   struct udev_device *udev_device)
 {
+       const char *prop;
        int code;
 
        if (!libevdev_has_event_type(device->evdev, EV_KEY))
@@ -1105,6 +1120,21 @@ evdev_tag_keyboard(struct evdev_device *device,
                        return;
        }
 
+       /* This should eventually become ID_INPUT_KEYBOARD_INTEGRATION */
+       prop = udev_device_get_property_value(udev_device,
+                                             "LIBINPUT_ATTR_KEYBOARD_INTEGRATION");
+       if (prop) {
+               if (streq(prop, "internal")) {
+                       evdev_tag_keyboard_internal(device);
+               } else if (streq(prop, "external")) {
+                       evdev_tag_keyboard_external(device);
+               } else {
+                       evdev_log_info(device,
+                                      "tagged with unknown value %s\n",
+                                      prop);
+               }
+       }
+
        device->tags |= EVDEV_TAG_KEYBOARD;
 }
 
@@ -2251,7 +2281,6 @@ evdev_read_model_flags(struct evdev_device *device)
                MODEL(ALPS_TOUCHPAD),
                MODEL(SYNAPTICS_SERIAL_TOUCHPAD),
                MODEL(JUMPING_SEMI_MT),
-               MODEL(APPLE_INTERNAL_KEYBOARD),
                MODEL(CYBORG_RAT),
                MODEL(HP_STREAM11_TOUCHPAD),
                MODEL(LENOVO_T450_TOUCHPAD),
index a5c11fc3173fcf7170c1ef6e380b5ae84b42848b..b891f90658e16734790080461c334d5593483410 100644 (file)
@@ -73,6 +73,8 @@ enum evdev_device_tags {
        EVDEV_TAG_TRACKPOINT = (1 << 3),
        EVDEV_TAG_KEYBOARD = (1 << 4),
        EVDEV_TAG_LID_SWITCH = (1 << 5),
+       EVDEV_TAG_INTERNAL_KEYBOARD = (1 << 6),
+       EVDEV_TAG_EXTERNAL_KEYBOARD = (1 << 7),
 };
 
 enum evdev_middlebutton_state {
@@ -112,7 +114,6 @@ enum evdev_device_model {
        EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD = (1 << 9),
        EVDEV_MODEL_JUMPING_SEMI_MT = (1 << 10),
        EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81 = (1 << 12),
-       EVDEV_MODEL_APPLE_INTERNAL_KEYBOARD = (1 << 13),
        EVDEV_MODEL_CYBORG_RAT = (1 << 14),
        EVDEV_MODEL_HP_STREAM11_TOUCHPAD = (1 << 16),
        EVDEV_MODEL_LENOVO_T450_TOUCHPAD= (1 << 17),
index 3f048092a201933b361431549109b056856cec00..229fb1defe3a69a01294359e6bae4a4fc7eb01f5 100644 (file)
@@ -25,6 +25,12 @@ libinput:name:*Lid Switch*:dmi:*:ct10:*
 libinput:name:*Lid Switch*:dmi:*:ct9:*
  LIBINPUT_ATTR_LID_SWITCH_RELIABILITY=reliable
 
+##########################################
+# Serial keyboards are internal
+##########################################
+libinput:keyboard:input:b0011v*
+ LIBINPUT_ATTR_KEYBOARD_INTEGRATION=internal
+
 ##########################################
 # ALPS
 ##########################################
@@ -45,7 +51,7 @@ libinput:touchpad:input:b0005v05ACp*
  LIBINPUT_ATTR_SIZE_HINT=104x75
 
 libinput:name:*Apple Inc. Apple Internal Keyboard*:dmi:*
- LIBINPUT_MODEL_APPLE_INTERNAL_KEYBOARD=1
+ LIBINPUT_ATTR_KEYBOARD_INTEGRATION=internal
 
 libinput:mouse:input:b0005v05ACp030D*
  LIBINPUT_MODEL_APPLE_MAGICMOUSE=1
@@ -186,6 +192,10 @@ libinput:mouse:input:b0003v046DpC408*
 libinput:name:*Lid Switch*:dmi:*svnMicrosoftCorporation:pnSurface3:*
  LIBINPUT_ATTR_LID_SWITCH_RELIABILITY=write_open
 
+# Surface 3 Type Cover keyboard
+libinput:name:*Microsoft Surface Type Cover Keyboard*:dmi:*svnMicrosoftCorporation:pnSurface3:*
+ LIBINPUT_ATTR_KEYBOARD_INTEGRATION=internal
+
 ##########################################
 # Synaptics
 ##########################################
index 8bff192d51116a68dc0de57071bca09faa362c5d..ace2bf077264cea1a24dc5e53f89fe55f4a939c5 100644 (file)
@@ -33,6 +33,10 @@ ENV{ID_INPUT_TOUCHPAD}=="1", \
 ENV{ID_INPUT_MOUSE}=="1", \
   IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=libinput:mouse:"
 
+# libinput:touchpad:<modalias>
+ENV{ID_INPUT_KEYBOARD}=="1", \
+  IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=libinput:keyboard:"
+
 # libinput:name:<name>:dmi:<dmi string>
 KERNELS=="input*", \
   IMPORT{builtin}="hwdb 'libinput:name:$attr{name}:$attr{[dmi/id]modalias}'"
index b4f0b1bfeea349d2d35bb75eda251ca50b2cb107..8ac6401034c3029f30ee7e2ea9c4a17d3b0bc199 100755 (executable)
@@ -60,7 +60,7 @@ REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER))
 UDEV_TAG = Word(string.ascii_uppercase, alphanums + '_')
 
 TYPES = {
-         'libinput': ('name', 'touchpad', 'mouse'),
+         'libinput': ('name', 'touchpad', 'mouse', 'keyboard'),
          }
 
 @functools.lru_cache()
@@ -117,8 +117,13 @@ def property_grammar():
                       Suppress('=') -
                       Group(pressure_range('SETTINGS*')) ]
 
+    kbintegration_tags = Or(('internal', 'external'))
+    kbintegration = [Literal('LIBINPUT_ATTR_KEYBOARD_INTEGRATION')('NAME') -
+                         Suppress('=') -
+                         kbintegration_tags('VALUE')]
+
     grammar = Or(model_props + size_props + reliability + tpkbcombo +
-                 pressure_prop)
+                 pressure_prop + kbintegration)
 
     return grammar