3262bac
From 638cab7e1dc3711f7fb04155bcdabf4b8895cc5e Mon Sep 17 00:00:00 2001
91482be
From: Peter Hutterer <peter.hutterer@who-t.net>
3262bac
Date: Mon, 4 Aug 2008 17:08:36 +0930
3262bac
Subject: [PATCH] xfree86: force SwitchCoreKeyboard for evdev devices (updated).
91482be
3262bac
If an evdev keyboard device is added through the HAL mechanism, force a
3262bac
SwitchCoreKeyboard to load the evdev map into the VCK. This way, by the time a
3262bac
client starts the evdev keymap is already there, leading to less pain lateron.
91482be
3262bac
Works if:
3262bac
- all keyboards are hotplugged through HAL, and/or
3262bac
- the xorg.conf keyboard uses the kbd driver.
91482be
3262bac
Has no effect (i.e. busted keymaps) if:
3262bac
- an evdev keyboard device has been specified in the xorg.conf.
3262bac
- we don't have a device at startup and plug a device in after starting the
3262bac
  desktop environment.
3262bac
- if the device we use isn't the first one reported by HAL.
3262bac
3262bac
If HAL isn't set up, this patch is a noop.
91482be
---
3262bac
 hw/xfree86/common/xf86Xinput.c |   31 +++++++++++++++++++++++++++++++
3262bac
 1 files changed, 31 insertions(+), 0 deletions(-)
91482be
91482be
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
3262bac
index 710e787..dacc3dc 100644
91482be
--- a/hw/xfree86/common/xf86Xinput.c
91482be
+++ b/hw/xfree86/common/xf86Xinput.c
3262bac
@@ -423,6 +423,37 @@ NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
91482be
         (!is_auto || xf86Info.autoEnableDevices))
91482be
         EnableDevice(dev);
91482be
 
91482be
+    /* XXX: The VCK always starts with built-in defaults for keymap. These
91482be
+     * defaults are different to the evdev ones. When the first key is hit on
91482be
+     * an extension device, the keymap is copied into the VCK's and any
91482be
+     * changes made at runtime to the VCK map are lost.
91482be
+     *
3262bac
+     * Assumption: if we have at least one evdev keyboard device, we can
3262bac
+     * ignore kbd devices. Force a SwitchCoreKeyboard so the VCK has the same
3262bac
+     * keymap as we do.
91482be
+     *
91482be
+     * Next time we hit a key, we don't change the map over anymore (see
91482be
+     * SwitchCoreKeyboard), and live happily ever after.
91482be
+     * Until we have 2 physical keyboards. Or the first real keyboard isn't
91482be
+     * actually the one we use. Oh well.
3262bac
+     *
91482be
+     */
91482be
+    if (dev->key)
91482be
+    {
3262bac
+        InputInfoPtr info;
91482be
+
3262bac
+        /* Search if there is one other keyboard that uses evdev. */
3262bac
+        for (info = xf86InputDevs; info; info = info->next)
91482be
+        {
3262bac
+            if (info != pInfo && info->dev && info->dev->key &&
3262bac
+                (strcmp(info->drv->driverName, "evdev") == 0))
91482be
+                break;
91482be
+        }
91482be
+
3262bac
+        if (!info)
91482be
+            SwitchCoreKeyboard(dev);
91482be
+    }
91482be
+
91482be
     *pdev = dev;
91482be
     return Success;
91482be
 
91482be
-- 
91482be
1.5.5.1
91482be