[mutter] wayland: Notify modifiers after keymap changes



commit 32565e096d89a4269874587cbbd9b2957158f90e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jul 22 00:54:04 2014 +0200

    wayland: Notify modifiers after keymap changes
    
    Anytime the keymap is changed, either directly, or indirectly through the
    keyboard capability being released/initialized, there should be a
    notification of the modifiers being changed too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733563

 src/wayland/meta-wayland-keyboard.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index c7dc961..53d9809 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -60,6 +60,8 @@
 
 #include "meta-wayland-private.h"
 
+static void meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard);
+
 static void
 unbind_resource (struct wl_resource *resource)
 {
@@ -147,8 +149,7 @@ meta_wayland_keyboard_take_keymap (MetaWaylandKeyboard *keyboard,
   xkb_keymap_unref (xkb_info->keymap);
   xkb_info->keymap = keymap;
 
-  xkb_state_unref (xkb_info->state);
-  xkb_info->state = xkb_state_new (keymap);
+  meta_wayland_keyboard_update_xkb_state (keyboard);
 
   keymap_str = xkb_map_get_as_string (xkb_info->keymap);
   if (keymap_str == NULL)
@@ -259,6 +260,36 @@ notify_modifiers (MetaWaylandKeyboard *keyboard, uint32_t serial,
     }
 }
 
+static void
+meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard)
+{
+  MetaWaylandXkbInfo *xkb_info = &keyboard->xkb_info;
+  xkb_mod_mask_t latched, locked, group;
+
+  /* Preserve latched/locked modifiers state */
+  if (xkb_info->state)
+    {
+      latched = xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LATCHED);
+      locked = xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LOCKED);
+      group = xkb_state_serialize_layout (xkb_info->state, XKB_STATE_LAYOUT_EFFECTIVE);
+      xkb_state_unref (xkb_info->state);
+    }
+  else
+    latched = locked = group = 0;
+
+  xkb_info->state = xkb_state_new (xkb_info->keymap);
+
+  if (latched || locked || group)
+    xkb_state_update_mask (xkb_info->state, 0, latched, locked, 0, 0, group);
+
+  notify_modifiers (keyboard,
+                    wl_display_next_serial (keyboard->display),
+                    xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_DEPRESSED),
+                    xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LATCHED),
+                    xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LOCKED),
+                    xkb_state_serialize_layout (xkb_info->state, XKB_STATE_LAYOUT_EFFECTIVE));
+}
+
 void
 meta_wayland_keyboard_init (MetaWaylandKeyboard *keyboard,
                             struct wl_display   *display)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]