summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2020-08-12 12:47:07 +0200
committerMarge Bot <marge-bot@gnome.org>2020-11-27 15:14:33 +0000
commit23f95348fd73f2c19a0e9aa6c28712dfc9538a2a (patch)
tree1f0d786c84753ef9b60346cadd5dbaad2f76b606
parent40665b0fb168e28292c26aeed4619abd62e0c35f (diff)
downloadmutter-23f95348fd73f2c19a0e9aa6c28712dfc9538a2a.tar.gz
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. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403>
-rw-r--r--src/backends/native/meta-backend-native.c30
-rw-r--r--src/backends/native/meta-seat-impl.c44
-rw-r--r--src/backends/native/meta-seat-impl.h4
-rw-r--r--src/backends/native/meta-seat-native.c59
-rw-r--r--src/backends/native/meta-seat-native.h8
5 files changed, 74 insertions, 71 deletions
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index bcc9a55ab..c7809a8b5 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 d7cdd8243..df53e55f5 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);
@@ -2940,22 +2945,6 @@ meta_seat_impl_set_keyboard_map (MetaSeatImpl *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
* @idx: the xkb layout index to set
@@ -2990,15 +2979,6 @@ meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat_impl,
}
/**
- * 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
* @numlock_set: TRUE to set NumLock ON, FALSE otherwise.
diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h
index 027fd624b..a62af83f5 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 00b3c36ba..88654f7b5 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -29,6 +29,7 @@
#include "backends/native/meta-seat-native.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"
@@ -170,6 +171,8 @@ meta_seat_native_constructed (GObject *object)
seat->core_pointer = meta_seat_impl_get_pointer (seat->impl);
seat->core_keyboard = meta_seat_impl_get_keyboard (seat->impl);
+ meta_seat_native_set_keyboard_map (seat, "us", "", "");
+
if (G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed)
G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed (object);
}
@@ -220,6 +223,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);
@@ -506,6 +511,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
@@ -517,13 +544,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);
}
/**
@@ -539,7 +583,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;
}
/**
@@ -555,6 +599,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);
}
@@ -564,7 +609,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 84eb8bb7e..787b2cc2b 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);