summaryrefslogtreecommitdiff
path: root/src/wayland/meta-wayland-keyboard.c
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2022-05-30 23:48:44 +0200
committerRobert Mader <robert.mader@posteo.de>2022-12-17 15:13:48 +0100
commit2731f0cda4687b6ab32dd53331428751def63a88 (patch)
treeecf8f83dfae01f15c13de5821ee5652705bde8be /src/wayland/meta-wayland-keyboard.c
parentdd2beae6a86eedbfbd7aaceb638cc505da8338cf (diff)
downloadmutter-2731f0cda4687b6ab32dd53331428751def63a88.tar.gz
wayland: Setup and use ownership chains
As elsewhere, make sure objects that need to have a ownership up to the context, and use this ownership chain to find relevant components, such as the backend or the Wayland compositor object instance. wayland/data-device: Hook up data devices to seats They are tied to a seat - make that connection in struct fields too, so that related objects can get to the context via it. wayland: Don't get Wayland compositor via singleton getter This means via the ownership chain or equivalent. xwayland: Hook up manager to Wayland compositor Same applies to the drag-n-drop struct. xwayland: Make X11 event handling compositor instance aware This avoids finding it via singletons in the callee. xwayland: Don't get Wayland compositor from singleton xwayland: Pass manager when handling dnd event window/xwayland: Don't get Wayland compositor from singleton xwayland/grab-keyboard: Don't get backend from singleton xwayland: Don't get backend from singleton wayland: Always get the backend from the context This means traveling up the ownership chain or equivalent when necessary. wayland: Hook up data devices, offers and sources to the compositor This allows tying them to a context without going through any singletons. wayland: Don't get display from singleton xwayland: Don't get display from singleton tablet: Don't get display from singleton Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
Diffstat (limited to 'src/wayland/meta-wayland-keyboard.c')
-rw-r--r--src/wayland/meta-wayland-keyboard.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index a243b51a1..5cdd3f4a5 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -64,6 +64,17 @@ G_DEFINE_TYPE (MetaWaylandKeyboard, meta_wayland_keyboard,
static void meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard);
static void notify_modifiers (MetaWaylandKeyboard *keyboard);
+static MetaBackend *
+backend_from_keyboard (MetaWaylandKeyboard *keyboard)
+{
+ MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (keyboard);
+ MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device);
+ MetaWaylandCompositor *compositor = meta_wayland_seat_get_compositor (seat);
+ MetaContext *context = meta_wayland_compositor_get_context (compositor);
+
+ return meta_context_get_backend (context);
+}
+
static void
unbind_resource (struct wl_resource *resource)
{
@@ -281,9 +292,10 @@ add_vmod (xkb_mod_mask_t mask,
}
static xkb_mod_mask_t
-add_virtual_mods (xkb_mod_mask_t mask)
+add_virtual_mods (MetaDisplay *display,
+ xkb_mod_mask_t mask)
{
- MetaKeyBindingManager *keys = &(meta_get_display ()->key_binding_manager);
+ MetaKeyBindingManager *keys = &display->key_binding_manager;
xkb_mod_mask_t added;
guint i;
/* Order is important here: if multiple vmods share the same real
@@ -309,12 +321,20 @@ keyboard_send_modifiers (MetaWaylandKeyboard *keyboard,
struct wl_resource *resource,
uint32_t serial)
{
+ MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (keyboard);
+ MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device);
+ MetaWaylandCompositor *compositor = meta_wayland_seat_get_compositor (seat);
+ MetaContext *context = meta_wayland_compositor_get_context (compositor);
+ MetaDisplay *display = meta_context_get_display (context);
struct xkb_state *state = keyboard->xkb_info.state;
xkb_mod_mask_t depressed, latched, locked;
- depressed = add_virtual_mods (xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED));
- latched = add_virtual_mods (xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED));
- locked = add_virtual_mods (xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED));
+ depressed = add_virtual_mods (display,
+ xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED));
+ latched = add_virtual_mods (display,
+ xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED));
+ locked = add_virtual_mods (display,
+ xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED));
wl_keyboard_send_modifiers (resource, serial, depressed, latched, locked,
xkb_state_serialize_layout (state, XKB_STATE_LAYOUT_EFFECTIVE));
@@ -353,7 +373,7 @@ meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard)
{
MetaWaylandXkbInfo *xkb_info = &keyboard->xkb_info;
xkb_mod_mask_t latched, locked, numlock;
- MetaBackend *backend = meta_get_backend ();
+ MetaBackend *backend = backend_from_keyboard (keyboard);
xkb_layout_index_t layout_idx;
ClutterKeymap *keymap;
ClutterSeat *seat;
@@ -510,7 +530,7 @@ static const MetaWaylandKeyboardGrabInterface default_keyboard_grab_interface =
void
meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard)
{
- MetaBackend *backend = meta_get_backend ();
+ MetaBackend *backend = backend_from_keyboard (keyboard);
ClutterBackend *clutter_backend = clutter_get_default_backend ();
keyboard->settings = g_settings_new ("org.gnome.desktop.peripherals.keyboard");
@@ -543,7 +563,7 @@ meta_wayland_xkb_info_destroy (MetaWaylandXkbInfo *xkb_info)
void
meta_wayland_keyboard_disable (MetaWaylandKeyboard *keyboard)
{
- MetaBackend *backend = meta_get_backend ();
+ MetaBackend *backend = backend_from_keyboard (keyboard);
g_signal_handlers_disconnect_by_func (backend, on_keymap_changed, keyboard);
g_signal_handlers_disconnect_by_func (backend, on_keymap_layout_group_changed, keyboard);