[mutter/wip/carlosg/input-thread: 61/88] backends/native: Shuffle xkb_keymap creation




commit 6c1f5ff63906e02dd0833f5600af8a6f18ff67b2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Aug 12 12:47:07 2020 +0200

    backends/native: Shuffle xkb_keymap creation
    
    Push it a little bit down to the MetaSeatNative. As both the UI thread
    and the input thread are interested in dealing with the xkb_keymap and
    it is not meant to be used in different threads, keep 2 separate copies
    around.
    
    The keyboard map will always be set from the UI thread, so the xkb_keymap
    owned by the MetaSeatNative (owned by the UI thread) can be considered
    canonical.

 src/backends/native/meta-backend-native.c | 30 +++-------------
 src/backends/native/meta-seat-impl.c      | 44 +++++++-----------------
 src/backends/native/meta-seat-impl.h      |  4 ---
 src/backends/native/meta-seat-native.c    | 57 +++++++++++++++++++++++++++----
 src/backends/native/meta-seat-native.h    |  8 +++--
 5 files changed, 72 insertions(+), 71 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index bcc9a55ab3..c7809a8b58 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -187,12 +187,12 @@ meta_backend_native_post_init (MetaBackend *backend)
   MetaSeatNative *seat =
     META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
 
-  META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
-
   backend_native->input_settings = meta_seat_impl_get_input_settings (seat->impl);
   g_signal_connect_object (backend_native->input_settings, "kbd-a11y-changed",
                            G_CALLBACK (kbd_a11y_changed_cb), backend, 0);
 
+  META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
+
   if (meta_settings_is_experimental_feature_enabled (settings,
                                                      META_EXPERIMENTAL_FEATURE_RT_SCHEDULER))
     {
@@ -286,35 +286,13 @@ meta_backend_native_set_keymap (MetaBackend *backend,
                                 const char  *options)
 {
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
-  struct xkb_rule_names names;
-  struct xkb_keymap *keymap;
-  struct xkb_context *context;
   ClutterSeat *seat;
 
-  names.rules = DEFAULT_XKB_RULES_FILE;
-  names.model = DEFAULT_XKB_MODEL;
-  names.layout = layouts;
-  names.variant = variants;
-  names.options = options;
-
-  context = meta_create_xkb_context ();
-  keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
-  xkb_context_unref (context);
-
-  if (keymap == NULL)
-    {
-      g_warning ("Unable to load configured keymap: rules=%s, model=%s, layout=%s, variant=%s, options=%s",
-                 DEFAULT_XKB_RULES_FILE, DEFAULT_XKB_MODEL, layouts,
-                 variants, options);
-      return;
-    }
-
   seat = clutter_backend_get_default_seat (clutter_backend);
-  meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat), keymap);
+  meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat),
+                                     layouts, variants, options);
 
   meta_backend_notify_keymap_changed (backend);
-
-  xkb_keymap_unref (keymap);
 }
 
 static struct xkb_keymap *
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index d7cdd8243c..df53e55f5a 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -2826,19 +2826,23 @@ meta_seat_impl_set_device_callbacks (MetaOpenDeviceCallback  open_callback,
 void
 meta_seat_impl_update_xkb_state (MetaSeatImpl *seat_impl)
 {
-  xkb_mod_mask_t latched_mods;
-  xkb_mod_mask_t locked_mods;
+  xkb_mod_mask_t latched_mods = 0;
+  xkb_mod_mask_t locked_mods = 0;
   struct xkb_keymap *xkb_keymap;
 
   g_rw_lock_writer_lock (&seat_impl->state_lock);
 
   xkb_keymap = meta_keymap_native_get_keyboard_map (seat_impl->keymap);
 
-  latched_mods = xkb_state_serialize_mods (seat_impl->xkb,
-                                           XKB_STATE_MODS_LATCHED);
-  locked_mods = xkb_state_serialize_mods (seat_impl->xkb,
-                                          XKB_STATE_MODS_LOCKED);
-  xkb_state_unref (seat_impl->xkb);
+  if (seat_impl->xkb)
+    {
+      latched_mods = xkb_state_serialize_mods (seat_impl->xkb,
+                                               XKB_STATE_MODS_LATCHED);
+      locked_mods = xkb_state_serialize_mods (seat_impl->xkb,
+                                              XKB_STATE_MODS_LOCKED);
+      xkb_state_unref (seat_impl->xkb);
+    }
+
   seat_impl->xkb = xkb_state_new (xkb_keymap);
 
   xkb_state_update_mask (seat_impl->xkb,
@@ -2932,6 +2936,7 @@ meta_seat_impl_set_keyboard_map (MetaSeatImpl      *seat_impl,
   MetaKeymapNative *keymap;
 
   g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
+  g_return_if_fail (xkb_keymap != NULL);
 
   keymap = seat_impl->keymap;
   meta_keymap_native_set_keyboard_map (keymap, xkb_keymap);
@@ -2939,22 +2944,6 @@ meta_seat_impl_set_keyboard_map (MetaSeatImpl      *seat_impl,
   meta_seat_impl_update_xkb_state (seat_impl);
 }
 
-/**
- * meta_seat_impl_get_keyboard_map: (skip)
- * @seat: the #ClutterSeat created by the evdev backend
- *
- * Retrieves the #xkb_keymap in use by the evdev backend.
- *
- * Return value: the #xkb_keymap.
- */
-struct xkb_keymap *
-meta_seat_impl_get_keyboard_map (MetaSeatImpl *seat_impl)
-{
-  g_return_val_if_fail (META_IS_SEAT_IMPL (seat_impl), NULL);
-
-  return xkb_state_get_keymap (seat_impl->xkb);
-}
-
 /**
  * meta_seat_impl_set_keyboard_layout_index: (skip)
  * @seat: the #ClutterSeat created by the evdev backend
@@ -2989,15 +2978,6 @@ meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl       *seat_impl,
   g_rw_lock_writer_unlock (&seat_impl->state_lock);
 }
 
-/**
- * meta_seat_impl_get_keyboard_layout_index: (skip)
- */
-xkb_layout_index_t
-meta_seat_impl_get_keyboard_layout_index (MetaSeatImpl *seat_impl)
-{
-  return seat_impl->layout_idx;
-}
-
 /**
  * meta_seat_impl_set_keyboard_numlock: (skip)
  * @seat: the #ClutterSeat created by the evdev backend
diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h
index 027fd624bf..a62af83f5d 100644
--- a/src/backends/native/meta-seat-impl.h
+++ b/src/backends/native/meta-seat-impl.h
@@ -206,13 +206,9 @@ struct xkb_state * meta_seat_impl_get_xkb_state (MetaSeatImpl *seat_impl);
 void               meta_seat_impl_set_keyboard_map   (MetaSeatImpl      *seat_impl,
                                                       struct xkb_keymap *keymap);
 
-struct xkb_keymap * meta_seat_impl_get_keyboard_map (MetaSeatImpl *seat_impl);
-
 void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl       *seat_impl,
                                                xkb_layout_index_t  idx);
 
-xkb_layout_index_t meta_seat_impl_get_keyboard_layout_index (MetaSeatImpl *seat_impl);
-
 void meta_seat_impl_set_keyboard_numlock (MetaSeatImpl *seat_impl,
                                           gboolean      numlock_state);
 
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index bbe36a6595..45fc2dde17 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -35,6 +35,7 @@
 #include <math.h>
 
 #include "backends/meta-cursor-tracker-private.h"
+#include "backends/meta-keymap-utils.h"
 #include "backends/native/meta-barrier-native.h"
 #include "backends/native/meta-event-native.h"
 #include "backends/native/meta-input-device-native.h"
@@ -226,6 +227,8 @@ meta_seat_native_finalize (GObject *object)
   MetaSeatNative *seat = META_SEAT_NATIVE (object);
   GList *iter;
 
+  if (seat->xkb_keymap)
+    xkb_keymap_unref (seat->xkb_keymap);
   g_clear_object (&seat->core_pointer);
   g_clear_object (&seat->core_keyboard);
   g_clear_object (&seat->impl);
@@ -512,6 +515,28 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
   seat->released = FALSE;
 }
 
+static struct xkb_keymap *
+create_keymap (const char *layouts,
+               const char *variants,
+               const char *options)
+{
+  struct xkb_rule_names names;
+  struct xkb_keymap *keymap;
+  struct xkb_context *context;
+
+  names.rules = DEFAULT_XKB_RULES_FILE;
+  names.model = DEFAULT_XKB_MODEL;
+  names.layout = layouts;
+  names.variant = variants;
+  names.options = options;
+
+  context = meta_create_xkb_context ();
+  keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
+  xkb_context_unref (context);
+
+  return keymap;
+}
+
 /**
  * meta_seat_native_set_keyboard_map: (skip)
  * @seat: the #ClutterSeat created by the evdev backend
@@ -523,13 +548,30 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
  * is pressed when calling this function.
  */
 void
-meta_seat_native_set_keyboard_map (MetaSeatNative    *seat,
-                                   struct xkb_keymap *xkb_keymap)
+meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
+                                   const char     *layouts,
+                                   const char     *variants,
+                                   const char     *options)
 {
-  g_return_if_fail (META_IS_SEAT_NATIVE (seat));
-  g_return_if_fail (xkb_keymap != NULL);
+  struct xkb_keymap *keymap, *impl_keymap;
+
+  keymap = create_keymap (layouts, variants, options);
+  impl_keymap = create_keymap (layouts, variants, options);
+
+  if (keymap == NULL)
+    {
+      g_warning ("Unable to load configured keymap: rules=%s, model=%s, layout=%s, variant=%s, options=%s",
+                 DEFAULT_XKB_RULES_FILE, DEFAULT_XKB_MODEL, layouts,
+                 variants, options);
+      return;
+    }
+
+  if (seat->xkb_keymap)
+    xkb_keymap_unref (seat->xkb_keymap);
+  seat->xkb_keymap = keymap;
 
-  meta_seat_impl_set_keyboard_map (seat->impl, xkb_keymap);
+  meta_seat_impl_set_keyboard_map (seat->impl, impl_keymap);
+  xkb_keymap_unref (impl_keymap);
 }
 
 /**
@@ -545,7 +587,7 @@ meta_seat_native_get_keyboard_map (MetaSeatNative *seat)
 {
   g_return_val_if_fail (META_IS_SEAT_NATIVE (seat), NULL);
 
-  return meta_seat_impl_get_keyboard_map (seat->impl);
+  return seat->xkb_keymap;
 }
 
 /**
@@ -561,6 +603,7 @@ meta_seat_native_set_keyboard_layout_index (MetaSeatNative     *seat,
 {
   g_return_if_fail (META_IS_SEAT_NATIVE (seat));
 
+  seat->xkb_layout_index = idx;
   meta_seat_impl_set_keyboard_layout_index (seat->impl, idx);
 }
 
@@ -570,7 +613,7 @@ meta_seat_native_set_keyboard_layout_index (MetaSeatNative     *seat,
 xkb_layout_index_t
 meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat)
 {
-  return meta_seat_impl_get_keyboard_layout_index (seat->impl);
+  return seat->xkb_layout_index;
 }
 
 /**
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 84eb8bb7e6..787b2cc2b6 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -46,6 +46,8 @@ struct _MetaSeatNative
   char *seat_id;
 
   GList *devices;
+  struct xkb_keymap *xkb_keymap;
+  xkb_layout_index_t xkb_layout_index;
 
   ClutterInputDevice *core_pointer;
   ClutterInputDevice *core_keyboard;
@@ -93,8 +95,10 @@ void  meta_seat_native_set_device_callbacks (MetaOpenDeviceCallback  open_callba
 void  meta_seat_native_release_devices (MetaSeatNative *seat);
 void  meta_seat_native_reclaim_devices (MetaSeatNative *seat);
 
-void               meta_seat_native_set_keyboard_map   (MetaSeatNative    *seat,
-                                                        struct xkb_keymap *keymap);
+void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
+                                        const char     *layouts,
+                                        const char     *variants,
+                                        const char     *options);
 
 struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat);
 


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