gnome-kiosk/0003-input-sources-manager-Add-function-to-load-input-sou.patch
2021-04-20 10:10:50 -04:00

220 lines
8.8 KiB
Diff

From 60e52b132e9957452004c85a0999b37a2e46ff55 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Thu, 15 Apr 2021 14:41:41 -0400
Subject: [PATCH 3/4] input-sources-manager: Add function to load input sources
from strings
kiosk_input_sources_manager_set_input_sources_from_system_settings
currently has code to load fetch the strings from localed and then
use them.
This commit moves the "use them" part to its own function so it can
be reused in a subsequent commit for something else.
---
compositor/kiosk-input-sources-manager.c | 73 ++++++++++++++++--------
1 file changed, 48 insertions(+), 25 deletions(-)
diff --git a/compositor/kiosk-input-sources-manager.c b/compositor/kiosk-input-sources-manager.c
index a1a4cfa..4b4ef62 100644
--- a/compositor/kiosk-input-sources-manager.c
+++ b/compositor/kiosk-input-sources-manager.c
@@ -793,147 +793,170 @@ kiosk_input_sources_manager_add_layout (KioskInputSourcesManager *self,
input_source_group = kiosk_input_sources_manager_add_new_input_source_group (self, options);
}
mapping_full = !kiosk_input_source_group_add_layout (input_source_group, xkb_layout, xkb_variant);
if (mapping_full) {
g_debug ("KioskInputSourcesManager: Keyboard mapping full, starting another one");
input_source_group = kiosk_input_sources_manager_add_new_input_source_group (self, options);
kiosk_input_source_group_add_layout (input_source_group, xkb_layout, xkb_variant);
}
}
void
kiosk_input_sources_manager_add_input_engine (KioskInputSourcesManager *self,
const char *engine_name,
const char *options)
{
KioskInputSourceGroup *input_source_group = NULL;
g_debug ("KioskInputSourcesManager: Adding input engine '%s'", engine_name);
input_source_group = kiosk_input_sources_manager_add_new_input_source_group (self, options);
kiosk_input_source_group_set_input_engine (input_source_group, engine_name);
kiosk_input_source_group_set_options (input_source_group, options);
}
-gboolean
-kiosk_input_sources_manager_set_input_sources_from_system_configuration (KioskInputSourcesManager *self)
+static gboolean
+kiosk_input_sources_manager_set_input_sources_from_strings (KioskInputSourcesManager *self,
+ const char *layouts_string,
+ const char *variants_string,
+ const char *options_string)
{
KioskInputSourceGroup *old_input_source_group;
g_autofree char *old_input_engine = NULL;
g_autofree char *old_selected_layout = NULL;
- const char *layouts_string = NULL;
g_auto (GStrv) layouts = NULL;
size_t number_of_layouts = 0;
- const char *variants_string = NULL;
g_auto (GStrv) variants = NULL;
size_t number_of_variants = 0;
- const char *options = NULL;
size_t i, j;
- gboolean input_source_group_active;
+ gboolean input_sources_active;
g_return_val_if_fail (KIOSK_IS_INPUT_SOURCES_MANAGER (self), FALSE);
- if (self->locale_proxy == NULL) {
- return FALSE;
- }
-
- g_debug ("KioskInputSourcesManager: Setting keymap from system configuration");
-
- layouts_string = sd_locale1_get_x11_layout (self->locale_proxy);
- g_debug ("KioskInputSourcesManager: System layout is '%s'", layouts_string);
-
layouts = g_strsplit (layouts_string, ",", -1);
number_of_layouts = g_strv_length (layouts);
- options = sd_locale1_get_x11_options (self->locale_proxy);
- g_debug ("KioskInputSourcesManager: System layout options are '%s'", options);
-
- variants_string = sd_locale1_get_x11_variant (self->locale_proxy);
- g_debug ("KioskInputSourcesManager: System layout variant is '%s'", variants_string);
variants = g_strsplit (variants_string, ",", -1);
number_of_variants = g_strv_length (variants);
if (number_of_layouts < number_of_variants) {
g_debug ("KioskInputSourcesManager: There is a layout variant mismatch");
return FALSE;
}
old_input_source_group = kiosk_input_sources_manager_get_selected_input_source_group (self);
if (old_input_source_group != NULL) {
old_input_engine = g_strdup (kiosk_input_source_group_get_input_engine (old_input_source_group));
old_selected_layout = kiosk_input_source_group_get_selected_layout (old_input_source_group);
}
kiosk_input_sources_manager_clear_input_sources (self);
for (i = 0, j = 0; layouts[i] != NULL; i++) {
char *id = NULL;
const char *layout = layouts[i];
const char *variant = "";
if (variants[j] != NULL) {
variant = variants[j++];
}
if (variant[0] == '\0') {
id = g_strdup (layout);
} else {
id = g_strdup_printf ("%s+%s", layout, variant);
}
- kiosk_input_sources_manager_add_layout (self, id, options);
+ kiosk_input_sources_manager_add_layout (self, id, options_string);
}
- input_source_group_active = activate_best_available_input_source_group (self, old_input_engine, old_selected_layout);
+ input_sources_active = activate_best_available_input_source_group (self, old_input_engine, old_selected_layout);
- if (!input_source_group_active) {
+ if (!input_sources_active) {
+ return FALSE;
+ }
+
+ sync_dbus_service (self);
+
+ return TRUE;
+}
+
+gboolean
+kiosk_input_sources_manager_set_input_sources_from_system_configuration (KioskInputSourcesManager *self)
+{
+ const char *layouts_string = NULL;
+ const char *variants_string = NULL;
+ const char *options = NULL;
+
+ gboolean input_sources_active;
+
+ g_return_val_if_fail (KIOSK_IS_INPUT_SOURCES_MANAGER (self), FALSE);
+
+ if (self->locale_proxy == NULL) {
+ return FALSE;
+ }
+
+ g_debug ("KioskInputSourcesManager: Setting keymap from system configuration");
+
+ layouts_string = sd_locale1_get_x11_layout (self->locale_proxy);
+ g_debug ("KioskInputSourcesManager: System layout is '%s'", layouts_string);
+
+ options = sd_locale1_get_x11_options (self->locale_proxy);
+ g_debug ("KioskInputSourcesManager: System layout options are '%s'", options);
+
+ variants_string = sd_locale1_get_x11_variant (self->locale_proxy);
+ g_debug ("KioskInputSourcesManager: System layout variant is '%s'", variants_string);
+
+ input_sources_active = kiosk_input_sources_manager_set_input_sources_from_strings (self, layouts_string, variants_string, options);
+
+ if (!input_sources_active) {
const char * const *locales;
locales = sd_locale1_get_locale (self->locale_proxy);
- input_source_group_active = kiosk_input_sources_manager_set_input_sources_from_locales (self, locales, options);
+ input_sources_active = kiosk_input_sources_manager_set_input_sources_from_locales (self, locales, options);
}
sync_dbus_service (self);
self->overriding_configuration = FALSE;
- if (!input_source_group_active) {
+ if (!input_sources_active) {
g_debug ("KioskInputSourcesManager: System has no valid configured input sources");
return FALSE;
}
return TRUE;
}
static void
on_session_input_configuration_changed (KioskInputSourcesManager *self)
{
g_debug ("KioskInputSourcesManager: Session input sources configuration changed");
if (self->overriding_configuration) {
g_debug ("KioskInputSourcesManager: Ignoring change, because keymap is overriden");
return;
}
kiosk_input_sources_manager_set_input_sources_from_session_configuration (self);
}
static void
on_session_input_sources_setting_changed (KioskInputSourcesManager *self)
{
kiosk_gobject_utils_queue_defer_callback (G_OBJECT (self),
"[kiosk-input-sources-manager] on_session_input_configuration_changed",
self->cancellable,
KIOSK_OBJECT_CALLBACK (on_session_input_configuration_changed),
NULL);
}
--
2.31.1