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.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403
This commit is contained in:
Carlos Garnacho 2020-08-12 12:47:07 +02:00
parent 4b88a769d2
commit faec8d29b0
6 changed files with 65 additions and 79 deletions

View File

@ -148,12 +148,12 @@ meta_backend_native_post_init (MetaBackend *backend)
MetaSeatNative *seat = MetaSeatNative *seat =
META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend)); META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
native->input_settings = meta_seat_impl_get_input_settings (seat->impl); native->input_settings = meta_seat_impl_get_input_settings (seat->impl);
g_signal_connect_object (native->input_settings, "kbd-a11y-changed", g_signal_connect_object (native->input_settings, "kbd-a11y-changed",
G_CALLBACK (kbd_a11y_changed_cb), backend, 0); 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, if (meta_settings_is_experimental_feature_enabled (settings,
META_EXPERIMENTAL_FEATURE_RT_SCHEDULER)) META_EXPERIMENTAL_FEATURE_RT_SCHEDULER))
{ {
@ -243,27 +243,13 @@ meta_backend_native_set_keymap (MetaBackend *backend,
const char *options) const char *options)
{ {
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
struct xkb_rule_names names;
struct xkb_keymap *keymap;
struct xkb_context *context;
ClutterSeat *seat; 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); 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); meta_backend_notify_keymap_changed (backend);
xkb_keymap_unref (keymap);
} }
static struct xkb_keymap * static struct xkb_keymap *

View File

@ -25,10 +25,6 @@
#include "backends/native/meta-keymap-native.h" #include "backends/native/meta-keymap-native.h"
#include "backends/native/meta-seat-native.h" #include "backends/native/meta-seat-native.h"
static const char *option_xkb_layout = "us";
static const char *option_xkb_variant = "";
static const char *option_xkb_options = "";
typedef struct _MetaKeymapNative MetaKeymapNative; typedef struct _MetaKeymapNative MetaKeymapNative;
struct _MetaKeymapNative struct _MetaKeymapNative
@ -91,19 +87,6 @@ meta_keymap_native_class_init (MetaKeymapNativeClass *klass)
static void static void
meta_keymap_native_init (MetaKeymapNative *keymap) meta_keymap_native_init (MetaKeymapNative *keymap)
{ {
struct xkb_context *ctx;
struct xkb_rule_names names;
names.rules = "evdev";
names.model = "pc105";
names.layout = option_xkb_layout;
names.variant = option_xkb_variant;
names.options = option_xkb_options;
ctx = meta_create_xkb_context ();
g_assert (ctx);
keymap->keymap = xkb_keymap_new_from_names (ctx, &names, 0);
xkb_context_unref (ctx);
} }
void void

View File

@ -2837,19 +2837,23 @@ meta_seat_impl_set_device_callbacks (MetaOpenDeviceCallback open_callback,
void void
meta_seat_impl_update_xkb_state (MetaSeatImpl *seat) meta_seat_impl_update_xkb_state (MetaSeatImpl *seat)
{ {
xkb_mod_mask_t latched_mods; xkb_mod_mask_t latched_mods = 0;
xkb_mod_mask_t locked_mods; xkb_mod_mask_t locked_mods = 0;
struct xkb_keymap *xkb_keymap; struct xkb_keymap *xkb_keymap;
g_rw_lock_writer_lock (&seat->state_lock); g_rw_lock_writer_lock (&seat->state_lock);
xkb_keymap = meta_keymap_native_get_keyboard_map (seat->keymap); xkb_keymap = meta_keymap_native_get_keyboard_map (seat->keymap);
if (seat->xkb)
{
latched_mods = xkb_state_serialize_mods (seat->xkb, latched_mods = xkb_state_serialize_mods (seat->xkb,
XKB_STATE_MODS_LATCHED); XKB_STATE_MODS_LATCHED);
locked_mods = xkb_state_serialize_mods (seat->xkb, locked_mods = xkb_state_serialize_mods (seat->xkb,
XKB_STATE_MODS_LOCKED); XKB_STATE_MODS_LOCKED);
xkb_state_unref (seat->xkb); xkb_state_unref (seat->xkb);
}
seat->xkb = xkb_state_new (xkb_keymap); seat->xkb = xkb_state_new (xkb_keymap);
xkb_state_update_mask (seat->xkb, xkb_state_update_mask (seat->xkb,
@ -2992,22 +2996,6 @@ meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat,
meta_seat_impl_update_xkb_state (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) * meta_seat_impl_set_keyboard_layout_index: (skip)
* @seat: the #ClutterSeat created by the evdev backend * @seat: the #ClutterSeat created by the evdev backend
@ -3042,15 +3030,6 @@ meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat,
g_rw_lock_writer_unlock (&seat->state_lock); 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) * meta_seat_impl_set_keyboard_numlock: (skip)
* @seat: the #ClutterSeat created by the evdev backend * @seat: the #ClutterSeat created by the evdev backend

View File

@ -218,13 +218,9 @@ struct xkb_state * meta_seat_impl_get_xkb_state (MetaSeatImpl *seat);
void meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat, void meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat,
struct xkb_keymap *keymap); 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, void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat,
xkb_layout_index_t idx); 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, void meta_seat_impl_set_keyboard_numlock (MetaSeatImpl *seat,
gboolean numlock_state); gboolean numlock_state);

View File

@ -35,6 +35,7 @@
#include <math.h> #include <math.h>
#include "backends/meta-cursor-tracker-private.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-barrier-native.h"
#include "backends/native/meta-event-native.h" #include "backends/native/meta-event-native.h"
#include "backends/native/meta-input-device-native.h" #include "backends/native/meta-input-device-native.h"
@ -176,6 +177,8 @@ meta_seat_native_constructed (GObject *object)
seat->kms_cursor_renderer = seat->kms_cursor_renderer =
meta_kms_cursor_renderer_new (meta_get_backend ()); meta_kms_cursor_renderer_new (meta_get_backend ());
meta_seat_native_set_keyboard_map (seat, "us", "", "");
if (G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed) if (G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed)
G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed (object); G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed (object);
} }
@ -225,6 +228,8 @@ meta_seat_native_finalize (GObject *object)
{ {
MetaSeatNative *seat = META_SEAT_NATIVE (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_pointer);
g_clear_object (&seat->core_keyboard); g_clear_object (&seat->core_keyboard);
g_clear_object (&seat->impl); g_clear_object (&seat->impl);
@ -471,6 +476,28 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
seat->released = FALSE; 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) * meta_seat_native_set_keyboard_map: (skip)
* @seat: the #ClutterSeat created by the evdev backend * @seat: the #ClutterSeat created by the evdev backend
@ -483,11 +510,21 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
*/ */
void void
meta_seat_native_set_keyboard_map (MetaSeatNative *seat, meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
struct xkb_keymap *xkb_keymap) const char *layouts,
const char *variants,
const char *options)
{ {
g_return_if_fail (META_IS_SEAT_NATIVE (seat)); struct xkb_keymap *keymap, *impl_keymap;
meta_seat_impl_set_keyboard_map (seat->impl, xkb_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, impl_keymap);
xkb_keymap_unref (impl_keymap);
} }
/** /**
@ -503,7 +540,7 @@ meta_seat_native_get_keyboard_map (MetaSeatNative *seat)
{ {
g_return_val_if_fail (META_IS_SEAT_NATIVE (seat), NULL); 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 +556,7 @@ meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
{ {
g_return_if_fail (META_IS_SEAT_NATIVE (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); meta_seat_impl_set_keyboard_layout_index (seat->impl, idx);
} }
@ -528,7 +566,7 @@ meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
xkb_layout_index_t xkb_layout_index_t
meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat) meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat)
{ {
return meta_seat_impl_get_keyboard_layout_index (seat->impl); return seat->xkb_layout_index;
} }
/** /**

View File

@ -46,6 +46,8 @@ struct _MetaSeatNative
char *seat_id; char *seat_id;
GList *devices; GList *devices;
struct xkb_keymap *xkb_keymap;
xkb_layout_index_t xkb_layout_index;
ClutterInputDevice *core_pointer; ClutterInputDevice *core_pointer;
ClutterInputDevice *core_keyboard; ClutterInputDevice *core_keyboard;
@ -92,7 +94,9 @@ void meta_seat_native_release_devices (MetaSeatNative *seat);
void meta_seat_native_reclaim_devices (MetaSeatNative *seat); void meta_seat_native_reclaim_devices (MetaSeatNative *seat);
void meta_seat_native_set_keyboard_map (MetaSeatNative *seat, void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
struct xkb_keymap *keymap); const char *layouts,
const char *variants,
const char *options);
struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat); struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat);