[mutter/wip/carlosg/input-thread: 156/159] backends/native: Shuffle xkb_keymap creation




commit 163dd6d4985e1569ed04b6f12f9951c23f7e4175
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 | 18 ++----------
 src/backends/native/meta-seat-impl.c      | 25 ----------------
 src/backends/native/meta-seat-impl.h      |  4 ---
 src/backends/native/meta-seat-native.c    | 48 +++++++++++++++++++++++++++----
 src/backends/native/meta-seat-native.h    |  8 ++++--
 5 files changed, 50 insertions(+), 53 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 8a9f5d4eef..0fa248585a 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -243,27 +243,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);
-
   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 2a791a452e..bbfe44e6cf 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -2993,22 +2993,6 @@ meta_seat_impl_set_keyboard_map (MetaSeatImpl      *seat,
   meta_seat_impl_update_xkb_state (seat);
 }
 
-/**
- * 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)
-{
-  g_return_val_if_fail (META_IS_SEAT_IMPL (seat), NULL);
-
-  return xkb_state_get_keymap (seat->xkb);
-}
-
 /**
  * meta_seat_impl_set_keyboard_layout_index: (skip)
  * @seat: the #ClutterSeat created by the evdev backend
@@ -3043,15 +3027,6 @@ meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl       *seat,
   g_rw_lock_writer_unlock (&seat->state_lock);
 }
 
-/**
- * meta_seat_impl_get_keyboard_layout_index: (skip)
- */
-xkb_layout_index_t
-meta_seat_impl_get_keyboard_layout_index (MetaSeatImpl *seat)
-{
-  return seat->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 8cc5cae15c..6e41b03785 100644
--- a/src/backends/native/meta-seat-impl.h
+++ b/src/backends/native/meta-seat-impl.h
@@ -218,13 +218,9 @@ struct xkb_state * meta_seat_impl_get_xkb_state (MetaSeatImpl *seat);
 void               meta_seat_impl_set_keyboard_map   (MetaSeatImpl      *seat,
                                                       struct xkb_keymap *keymap);
 
-struct xkb_keymap * meta_seat_impl_get_keyboard_map (MetaSeatImpl *seat);
-
 void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl       *seat,
                                                xkb_layout_index_t  idx);
 
-xkb_layout_index_t meta_seat_impl_get_keyboard_layout_index (MetaSeatImpl *seat);
-
 void meta_seat_impl_set_keyboard_numlock (MetaSeatImpl *seat,
                                           gboolean      numlock_state);
 
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index a9f90cc7a9..9de54fcc5c 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"
@@ -225,6 +226,8 @@ meta_seat_native_finalize (GObject *object)
 {
   MetaSeatNative *seat = META_SEAT_NATIVE (object);
 
+  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);
@@ -471,6 +474,28 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
   seat->released = FALSE;
 }
 
+static struct xkb_keymap *
+create_keymap (const gchar *layouts,
+               const gchar *variants,
+               const gchar *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
@@ -482,12 +507,22 @@ 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));
+  struct xkb_keymap *keymap, *impl_keymap;
+
+  keymap = create_keymap (layouts, variants, options);
+  impl_keymap = create_keymap (layouts, variants, options);
+
+  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);
 }
 
 /**
@@ -503,7 +538,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;
 }
 
 /**
@@ -519,6 +554,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);
 }
 
@@ -528,7 +564,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 ac42bcbfb5..fffd0c81c7 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;
@@ -91,8 +93,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]