[mutter] backend: Add a keymap-changed signal



commit 39f65f9f8645140bc6d65c30e7a1d82d70c80f65
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Aug 14 17:32:41 2014 -0400

    backend: Add a keymap-changed signal

 src/backends/meta-backend.c               |    7 ++++++
 src/backends/native/meta-backend-native.c |    2 +-
 src/backends/x11/meta-backend-x11.c       |   32 +++++++++++++++++++++++++++++
 src/core/keybindings-private.h            |    2 -
 src/core/keybindings.c                    |   16 +++++++++-----
 src/x11/events.c                          |    6 +----
 6 files changed, 51 insertions(+), 14 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 75222da..a912d5a 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -167,6 +167,13 @@ meta_backend_class_init (MetaBackendClass *klass)
   klass->ungrab_device = meta_backend_real_ungrab_device;
   klass->update_screen_size = meta_backend_real_update_screen_size;
   klass->select_stage_events = meta_backend_real_select_stage_events;
+
+  g_signal_new ("keymap-changed",
+                G_TYPE_FROM_CLASS (object_class),
+                G_SIGNAL_RUN_LAST,
+                0,
+                NULL, NULL, NULL,
+                G_TYPE_NONE, 0);
 }
 
 static void
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 60f039e..cb9d3a7 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -211,7 +211,7 @@ meta_backend_native_set_keymap (MetaBackend *backend,
 
   clutter_evdev_set_keyboard_map (manager, keymap);
 
-  /* FIXME: emit keymap changed signal */
+  g_signal_emit_by_name (backend, "keymap-changed", 0);
 
   xkb_keymap_unref (keymap);
 }
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 14ba28c..84c5b07 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -159,6 +159,21 @@ maybe_spoof_event_as_stage_event (MetaBackendX11 *x11,
 }
 
 static void
+keymap_changed (MetaBackend *backend)
+{
+  MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
+  MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
+
+  if (priv->keymap)
+    {
+      xkb_keymap_unref (priv->keymap);
+      priv->keymap = NULL;
+    }
+
+  g_signal_emit_by_name (backend, "keymap-changed", 0);
+}
+
+static void
 handle_host_xevent (MetaBackend *backend,
                     XEvent      *event)
 {
@@ -182,6 +197,23 @@ handle_host_xevent (MetaBackend *backend,
   if (event->type == (priv->xsync_event_base + XSyncAlarmNotify))
     handle_alarm_notify (backend, event);
 
+  if (event->type == priv->xkb_event_base)
+    {
+      XkbAnyEvent *xkb_ev = (XkbAnyEvent *) event;
+
+      if (xkb_ev->device == META_VIRTUAL_CORE_KEYBOARD_ID)
+        {
+          switch (xkb_ev->xkb_type)
+            {
+            case XkbNewKeyboardNotify:
+            case XkbMapNotify:
+              keymap_changed (backend);
+            default:
+              break;
+            }
+        }
+    }
+
   {
     MetaMonitorManager *manager = meta_backend_get_monitor_manager (backend);
     if (META_IS_MONITOR_MANAGER_XRANDR (manager) &&
diff --git a/src/core/keybindings-private.h b/src/core/keybindings-private.h
index 028acfb..9c84285 100644
--- a/src/core/keybindings-private.h
+++ b/src/core/keybindings-private.h
@@ -126,8 +126,6 @@ void     meta_window_ungrab_all_keys        (MetaWindow  *window,
 gboolean meta_keybindings_process_event     (MetaDisplay        *display,
                                              MetaWindow         *window,
                                              const ClutterEvent *event);
-void     meta_display_process_mapping_event (MetaDisplay *display,
-                                             XEvent      *event);
 
 ClutterModifierType meta_display_get_window_grab_modifiers (MetaDisplay *display);
 
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index a55ef8b..4a31275 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -937,10 +937,11 @@ meta_display_get_keybinding_action (MetaDisplay  *display,
     }
 }
 
-void
-meta_display_process_mapping_event (MetaDisplay *display,
-                                    XEvent      *event)
+static void
+on_keymap_changed (MetaBackend *backend,
+                   gpointer     user_data)
 {
+  MetaDisplay *display = user_data;
   MetaKeyBindingManager *keys = &display->key_binding_manager;
 
   ungrab_key_bindings (display);
@@ -4185,7 +4186,10 @@ meta_display_init_keys (MetaDisplay *display)
 
   meta_prefs_add_listener (prefs_changed_callback, display);
 
-  XkbSelectEvents (keys->xdisplay, XkbUseCoreKbd,
-                   XkbNewKeyboardNotifyMask | XkbMapNotifyMask,
-                   XkbNewKeyboardNotifyMask | XkbMapNotifyMask);
+  {
+    MetaBackend *backend = meta_get_backend ();
+
+    g_signal_connect (backend, "keymap-changed",
+                      G_CALLBACK (on_keymap_changed), display);
+  }
 }
diff --git a/src/x11/events.c b/src/x11/events.c
index 4e3e621..adb5672 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -1579,7 +1579,6 @@ handle_other_xevent (MetaDisplay *display,
             /* Let XLib know that there is a new keyboard mapping.
              */
             XRefreshKeyboardMapping (&event->xmapping);
-            meta_display_process_mapping_event (display, event);
           }
       }
       break;
@@ -1598,10 +1597,7 @@ handle_other_xevent (MetaDisplay *display,
                   meta_bell_notify (display, xkb_ev);
                 }
               break;
-            case XkbNewKeyboardNotify:
-            case XkbMapNotify:
-              if (xkb_ev->device == META_VIRTUAL_CORE_KEYBOARD_ID)
-                meta_display_process_mapping_event (display, event);
+            default:
               break;
             }
         }


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