289 lines
13 KiB
Diff
289 lines
13 KiB
Diff
From 7dc64ec56b42dc91893f7e07171ddbc1823daed4 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
|
|
Date: Mon, 6 Oct 2025 16:28:01 +0200
|
|
Subject: [PATCH 1/2] input-source-group: Adapt to MetaKeymapDescription usage
|
|
|
|
This adapts to the libmutter API change that changes the keymap setting
|
|
API from using explicit XKB rules to an abstracted keymap description,
|
|
where one can still create such a description from the same XKB rules.
|
|
|
|
This new API can also directly pass the layout index, meaning there will
|
|
be no need for another index changing API call.
|
|
|
|
Part-of: <https://gitlab.gnome.org/GNOME/gnome-kiosk/-/merge_requests/101>
|
|
(cherry picked from commit e80f6b736f1bb7babdcce7006f479b7be1d0e27b)
|
|
---
|
|
compositor/kiosk-input-source-group.c | 161 ++++++++++++++------------
|
|
1 file changed, 84 insertions(+), 77 deletions(-)
|
|
|
|
diff --git a/compositor/kiosk-input-source-group.c b/compositor/kiosk-input-source-group.c
|
|
index 3e7ae7e..d58ae7c 100644
|
|
--- a/compositor/kiosk-input-source-group.c
|
|
+++ b/compositor/kiosk-input-source-group.c
|
|
@@ -45,6 +45,7 @@ struct _KioskInputSourceGroup
|
|
|
|
/* state */
|
|
xkb_layout_index_t layout_index;
|
|
+ MetaKeymapDescription *keymap_description;
|
|
};
|
|
enum
|
|
{
|
|
@@ -141,6 +142,28 @@ out:
|
|
return (char **) g_ptr_array_steal (array, NULL);
|
|
}
|
|
|
|
+static void
|
|
+reset_keymap_description (KioskInputSourceGroup *self)
|
|
+{
|
|
+ g_autofree char *layouts = NULL;
|
|
+ g_autofree char *variants = NULL;
|
|
+
|
|
+ layouts = g_strjoinv (",", (GStrv) self->layouts->pdata);
|
|
+ variants = g_strjoinv (",", (GStrv) self->variants->pdata);
|
|
+
|
|
+ g_debug ("KioskInputSourceGroup: Setting keymap description to [%s] (%s) [%s]",
|
|
+ layouts, variants, self->options);
|
|
+
|
|
+ g_clear_pointer (&self->keymap_description, meta_keymap_description_unref);
|
|
+ self->keymap_description =
|
|
+ meta_keymap_description_new_from_rules (KIOSK_INPUT_SOURCE_KEYBOARD_MODEL,
|
|
+ layouts,
|
|
+ variants,
|
|
+ self->options,
|
|
+ NULL,
|
|
+ NULL);
|
|
+}
|
|
+
|
|
static void
|
|
add_layout (KioskInputSourceGroup *self,
|
|
const char *layout,
|
|
@@ -165,6 +188,8 @@ add_layout (KioskInputSourceGroup *self,
|
|
/* Add back terminating NULL */
|
|
g_ptr_array_add (self->layouts, NULL);
|
|
g_ptr_array_add (self->variants, NULL);
|
|
+
|
|
+ reset_keymap_description (self);
|
|
}
|
|
|
|
gboolean
|
|
@@ -273,27 +298,10 @@ set_keymap_cb (GObject *source_object,
|
|
g_warning ("Failed to set keymap: %s", error->message);
|
|
}
|
|
|
|
-static void
|
|
-set_keymap_layout_group_cb (GObject *source_object,
|
|
- GAsyncResult *result,
|
|
- gpointer user_data)
|
|
-{
|
|
- MetaBackend *backend = META_BACKEND (source_object);
|
|
- g_autoptr (GError) error = NULL;
|
|
-
|
|
- meta_backend_set_keymap_layout_group_finish (backend, result, &error);
|
|
- if (error)
|
|
- g_warning ("Failed to set keymap layout group: %s", error->message);
|
|
-}
|
|
-
|
|
gboolean
|
|
kiosk_input_source_group_activate (KioskInputSourceGroup *self)
|
|
{
|
|
size_t number_of_layouts;
|
|
- g_autofree char *layouts = NULL;
|
|
- g_autofree char *variants = NULL;
|
|
- gboolean keymap_already_set = FALSE;
|
|
- gboolean layout_group_already_locked = FALSE;
|
|
|
|
g_debug ("KioskInputSourceGroup: Activating input source");
|
|
|
|
@@ -307,8 +315,6 @@ kiosk_input_source_group_activate (KioskInputSourceGroup *self)
|
|
return FALSE;
|
|
}
|
|
|
|
- layouts = g_strjoinv (",", (GStrv) self->layouts->pdata);
|
|
- variants = g_strjoinv (",", (GStrv) self->variants->pdata);
|
|
|
|
if (self->input_engine_name != NULL) {
|
|
gboolean activated;
|
|
@@ -323,39 +329,12 @@ kiosk_input_source_group_activate (KioskInputSourceGroup *self)
|
|
kiosk_input_engine_manager_activate_engine (self->input_engine_manager, NULL);
|
|
}
|
|
|
|
-#ifdef HAVE_X11
|
|
- if (self->x_keyboard_manager != NULL) {
|
|
- keymap_already_set = kiosk_x_keyboard_manager_keymap_is_active (self->x_keyboard_manager, (const char * const *) self->layouts->pdata, (const char * const *) self->variants->pdata, self->options);
|
|
- layout_group_already_locked = kiosk_x_keyboard_manager_layout_group_is_locked (self->x_keyboard_manager, self->layout_index);
|
|
- }
|
|
-#endif
|
|
-
|
|
- if (!keymap_already_set) {
|
|
- g_debug ("KioskInputSourceGroup: Setting keyboard mapping to [%s] (%s) [%s]",
|
|
- layouts, variants, self->options);
|
|
-
|
|
- meta_backend_set_keymap_async (self->backend,
|
|
- layouts,
|
|
- variants,
|
|
- self->options,
|
|
- KIOSK_INPUT_SOURCE_KEYBOARD_MODEL,
|
|
- NULL,
|
|
- set_keymap_cb,
|
|
- NULL);
|
|
- }
|
|
-
|
|
- if (!layout_group_already_locked) {
|
|
- g_debug ("KioskInputSourceGroup: Locking layout to index %d", self->layout_index);
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
- }
|
|
-
|
|
- if (keymap_already_set && layout_group_already_locked) {
|
|
- g_debug ("KioskInputSourceGroup: Input source already active");
|
|
- }
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -410,11 +389,12 @@ kiosk_input_source_group_switch_to_layout (KioskInputSourceGroup *self,
|
|
g_debug ("KioskInputSourceGroup: Switching from layout '%s' to next layout '%s'",
|
|
active_layout, layout_name);
|
|
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -438,11 +418,12 @@ kiosk_input_source_group_switch_to_first_layout (KioskInputSourceGroup *self)
|
|
layout_to_activate = kiosk_input_source_group_get_selected_layout (self);
|
|
|
|
g_debug ("KioskInputSourceGroup: First layout is '%s'", layout_to_activate);
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
}
|
|
|
|
void
|
|
@@ -464,11 +445,12 @@ kiosk_input_source_group_switch_to_last_layout (KioskInputSourceGroup *self)
|
|
layout_to_activate = kiosk_input_source_group_get_selected_layout (self);
|
|
|
|
g_debug ("KioskInputSourceGroup: Last layout is '%s'", layout_to_activate);
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
}
|
|
|
|
gboolean
|
|
@@ -503,11 +485,12 @@ kiosk_input_source_group_switch_to_next_layout (KioskInputSourceGroup *self)
|
|
g_debug ("KioskInputSourceGroup: Switching from layout '%s' to next layout '%s'",
|
|
active_layout, layout_to_activate);
|
|
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -542,11 +525,12 @@ kiosk_input_source_group_switch_to_previous_layout (KioskInputSourceGroup *self)
|
|
g_debug ("KioskInputSourceGroup: Switching from layout '%s' to previous layout '%s'",
|
|
active_layout, layout_to_activate);
|
|
|
|
- meta_backend_set_keymap_layout_group_async (self->backend,
|
|
- self->layout_index,
|
|
- NULL,
|
|
- set_keymap_layout_group_cb,
|
|
- NULL);
|
|
+ meta_backend_set_keymap_async (self->backend,
|
|
+ self->keymap_description,
|
|
+ self->layout_index,
|
|
+ NULL,
|
|
+ set_keymap_cb,
|
|
+ NULL);
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -630,6 +614,22 @@ kiosk_input_source_group_init (KioskInputSourceGroup *self)
|
|
g_ptr_array_add (self->variants, NULL);
|
|
}
|
|
|
|
+static MetaKeymapDescription *
|
|
+on_reset_keymap_description (MetaBackend *backend,
|
|
+ KioskInputSourceGroup *self)
|
|
+{
|
|
+ g_return_val_if_fail (self->keymap_description, NULL);
|
|
+
|
|
+ return meta_keymap_description_ref (self->keymap_description);
|
|
+}
|
|
+
|
|
+static uint32_t
|
|
+on_reset_keymap_layout_index (MetaBackend *backend,
|
|
+ KioskInputSourceGroup *self)
|
|
+{
|
|
+ return self->layout_index;
|
|
+}
|
|
+
|
|
static void
|
|
kiosk_input_source_group_constructed (GObject *object)
|
|
{
|
|
@@ -644,6 +644,11 @@ kiosk_input_source_group_constructed (GObject *object)
|
|
g_set_weak_pointer (&self->display, meta_plugin_get_display (META_PLUGIN (self->compositor)));
|
|
g_set_weak_pointer (&self->context, meta_display_get_context (self->display));
|
|
g_set_weak_pointer (&self->backend, meta_context_get_backend (self->context));
|
|
+
|
|
+ g_signal_connect (self->backend, "reset-keymap-description",
|
|
+ G_CALLBACK (on_reset_keymap_description), self);
|
|
+ g_signal_connect (self->backend, "reset-keymap-layout-index",
|
|
+ G_CALLBACK (on_reset_keymap_layout_index), self);
|
|
}
|
|
|
|
static void
|
|
@@ -653,6 +658,8 @@ kiosk_input_source_group_dispose (GObject *object)
|
|
|
|
g_debug ("KioskInputSourceGroup: Disposing");
|
|
|
|
+ g_clear_pointer (&self->keymap_description, meta_keymap_description_unref);
|
|
+
|
|
g_clear_pointer (&self->options, g_free);
|
|
|
|
g_clear_pointer (&self->variants, g_ptr_array_unref);
|
|
--
|
|
2.54.0
|
|
|