Blame SOURCES/0036-xwayland-Handle-keymap-changes.patch

d64d53
From 6240dcadc8f51b00abe7d1fc4e682b442809fb91 Mon Sep 17 00:00:00 2001
70130e
From: Rui Matos <tiagomatos@gmail.com>
70130e
Date: Mon, 21 Oct 2013 14:41:54 +0200
d64d53
Subject: [PATCH 36/38] xwayland: Handle keymap changes
70130e
70130e
---
70130e
 hw/xfree86/xwayland/xwayland-input.c | 39 +++++++++++++++++++++++++++++++++---
70130e
 include/input.h                      |  2 +-
70130e
 2 files changed, 37 insertions(+), 4 deletions(-)
70130e
70130e
diff --git a/hw/xfree86/xwayland/xwayland-input.c b/hw/xfree86/xwayland/xwayland-input.c
70130e
index d031b34..ebf1af1 100644
70130e
--- a/hw/xfree86/xwayland/xwayland-input.c
70130e
+++ b/hw/xfree86/xwayland/xwayland-input.c
70130e
@@ -143,7 +143,10 @@ xwl_keyboard_proc(DeviceIntPtr device, int what)
70130e
     switch (what) {
70130e
     case DEVICE_INIT:
70130e
 	device->public.on = FALSE;
70130e
-	len = strnlen(xwl_seat->keymap, xwl_seat->keymap_size);
70130e
+        if (xwl_seat->keymap)
70130e
+            len = strnlen(xwl_seat->keymap, xwl_seat->keymap_size);
70130e
+        else
70130e
+            len = 0;
70130e
         if (!InitKeyboardDeviceStructFromString(device, xwl_seat->keymap,
70130e
 						len,
70130e
 						NULL, xwl_keyboard_control))
70130e
@@ -453,12 +456,42 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
70130e
 		       uint32_t format, int fd, uint32_t size)
70130e
 {
70130e
     struct xwl_seat *xwl_seat = data;
70130e
+    DeviceIntPtr master;
70130e
+    XkbDescPtr xkb;
70130e
+    XkbChangesRec changes = { 0 };
70130e
+
70130e
+    if (xwl_seat->keymap)
70130e
+        munmap(xwl_seat->keymap, xwl_seat->keymap_size);
70130e
 
70130e
     xwl_seat->keymap_size = size;
70130e
     xwl_seat->keymap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
70130e
-    if (xwl_seat->keymap == MAP_FAILED)
70130e
-	;	/* wah wah */
70130e
+    if (xwl_seat->keymap == MAP_FAILED) {
70130e
+        xwl_seat->keymap_size = 0;
70130e
+        xwl_seat->keymap = NULL;
70130e
+        goto out;
70130e
+    }
70130e
+
70130e
+    if (!xwl_seat->keyboard)
70130e
+        goto out;
70130e
+
70130e
+    xkb = XkbCompileKeymapFromString(xwl_seat->keyboard, xwl_seat->keymap,
70130e
+                                     strnlen(xwl_seat->keymap, xwl_seat->keymap_size));
70130e
+    if (!xkb)
70130e
+        goto out;
70130e
+
70130e
+    XkbUpdateDescActions(xkb, xkb->min_key_code, XkbNumKeys(xkb), &changes);
70130e
+    /* Keep the current controls */
70130e
+    XkbCopyControls(xkb, xwl_seat->keyboard->key->xkbInfo->desc);
70130e
+
70130e
+    XkbDeviceApplyKeymap(xwl_seat->keyboard, xkb);
70130e
+
70130e
+    master = GetMaster(xwl_seat->keyboard, MASTER_KEYBOARD);
70130e
+    if (master && master->lastSlave == xwl_seat->keyboard)
70130e
+        XkbDeviceApplyKeymap(master, xkb);
70130e
+
70130e
+    XkbFreeKeyboard(xkb, XkbAllComponentsMask, TRUE);
70130e
 
70130e
+ out:
70130e
     close(fd);
70130e
 }
70130e
 
70130e
diff --git a/include/input.h b/include/input.h
d64d53
index b1cc3ff..6a814c2 100644
70130e
--- a/include/input.h
70130e
+++ b/include/input.h
70130e
@@ -508,7 +508,7 @@ extern int AttachDevice(ClientPtr client,
70130e
                         DeviceIntPtr slave, DeviceIntPtr master);
70130e
 
70130e
 extern _X_EXPORT DeviceIntPtr GetPairedDevice(DeviceIntPtr kbd);
70130e
-extern DeviceIntPtr GetMaster(DeviceIntPtr dev, int type);
70130e
+extern _X_EXPORT DeviceIntPtr GetMaster(DeviceIntPtr dev, int type);
70130e
 
70130e
 extern _X_EXPORT int AllocDevicePair(ClientPtr client,
70130e
                                      const char *name,
70130e
-- 
d64d53
1.8.4.2
70130e