91482be
From b2943b507261d1c68a6266b090ec44495d7796a1 Mon Sep 17 00:00:00 2001
91482be
From: Peter Hutterer <peter.hutterer@who-t.net>
91482be
Date: Mon, 28 Jul 2008 12:17:17 +0930
91482be
Subject: [PATCH] xfree86: call SwitchCoreKeyboard for first physical device.
91482be
91482be
The VCK's keymap is different to the (evdev) keyboard's keymap. Any changes to
91482be
the VCK are lost when the first key is pressed (see X.Org Bug 16364). By
91482be
calling SwitchCoreKeyboard for the first hotplugged keyboard, the keymap is
91482be
toggled already when the first apps start.
91482be
91482be
This fixes GNOME, which stores the keycode instead of the keysym.
91482be
Fixes xmodmap, etc. settings in xinitrc or otherwise set before the first key
91482be
press.
91482be
91482be
This breaks if the first hotplugged keyboard is not the actual keyboard the
91482be
user wants to use.
91482be
---
91482be
 hw/xfree86/common/xf86Xinput.c |   27 +++++++++++++++++++++++++++
91482be
 1 files changed, 27 insertions(+), 0 deletions(-)
91482be
91482be
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
91482be
index 710e787..fe08626 100644
91482be
--- a/hw/xfree86/common/xf86Xinput.c
91482be
+++ b/hw/xfree86/common/xf86Xinput.c
91482be
@@ -423,6 +423,33 @@ 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
+     *
91482be
+     * If this is the first real keyboard to activate, force a
91482be
+     * SwitchCoreKeyboard so the VCK has the same 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.
91482be
+     */
91482be
+    if (dev->key)
91482be
+    {
91482be
+        DeviceIntPtr it;
91482be
+
91482be
+        for (it = inputInfo.keyboard->next; it; it = it->next)
91482be
+        {
91482be
+            if (it->key && it != dev)
91482be
+                break;
91482be
+        }
91482be
+
91482be
+        if (!it) /* no other keyboard found */
91482be
+            SwitchCoreKeyboard(dev);
91482be
+    }
91482be
+
91482be
     *pdev = dev;
91482be
     return Success;
91482be
 
91482be
-- 
91482be
1.5.5.1
91482be