From f4de54246a677ccc77a9f1efc871beaebe1bec40 Mon Sep 17 00:00:00 2001 From: Konrad Bucheli Date: Wed, 20 Jul 2022 13:18:23 +0200 Subject: support configuring the keyboard layouts of the ~layout indicator --- data/lightdm-gtk-greeter.conf | 3 ++- src/greeterconfiguration.h | 1 + src/lightdm-gtk-greeter.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/data/lightdm-gtk-greeter.conf b/data/lightdm-gtk-greeter.conf index 2a20ef0..5be8343 100644 --- a/data/lightdm-gtk-greeter.conf +++ b/data/lightdm-gtk-greeter.conf @@ -32,7 +32,8 @@ # Panel: # panel-position = top|bottom ("top" by default) # clock-format = strftime-format string, e.g. %H:%M -# indicators = semi-colon ";" separated list of allowed indicator modules. Built-in indicators include "~a11y", "~language", "~session", "~power", "~clock", "~host", "~spacer". Unity indicators can be represented by short name (e.g. "sound", "power"), service file name, or absolute path +# indicators = semi-colon ";" separated list of allowed indicator modules. Built-in indicators include "~a11y", "~language", "~session", "~power", "~clock", "~host", "~spacer", "~layout". Unity indicators can be represented by short name (e.g. "sound", "power"), service file name, or absolute path +# keyboard-layouts = semi-colon ";" separated list keyboard layouts to be listed by the "~layout" indicator (empty by default which provides all available layouts) # # Accessibility: # a11y-states = states of accessibility features: "name" - save state on exit, "-name" - disabled at start (default value for unlisted), "+name" - enabled at start. Allowed names: contrast, font, keyboard, reader. diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index 9e1b452..0d296f4 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -32,6 +32,7 @@ #define CONFIG_KEY_ROUND_USER_IMAGE "round-user-image" #define CONFIG_KEY_HIGHLIGHT_LOGGED_USER "highlight-logged-user" #define CONFIG_KEY_KEYBOARD "keyboard" +#define CONFIG_KEY_KEYBOARD_LAYOUTS "keyboard-layouts" #define CONFIG_KEY_READER "reader" #define CONFIG_KEY_CLOCK_FORMAT "clock-format" #define CONFIG_KEY_ACTIVE_MONITOR "active-monitor" diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 0504ea0..9d59b00 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -1755,6 +1755,13 @@ layout_selected_cb (GtkCheckMenuItem *menuitem, gpointer user_data) static void update_layouts_menu (void) { + gchar **layouts; + gsize num_layouts = 0; + + layouts = config_get_string_list (NULL, CONFIG_KEY_KEYBOARD_LAYOUTS, NULL); + if (layouts) + num_layouts = g_strv_length (layouts); + #ifdef HAVE_LIBXKLAVIER XklConfigRegistry *registry; XklConfigRec *config; @@ -1783,6 +1790,23 @@ update_layouts_menu (void) const gchar *variant = config->variants[i] ? config->variants[i] : ""; gchar *label = strlen (variant) > 0 ? g_strdup_printf ("%s_%s", layout, variant) : g_strdup (layout); + /* is the keyboard layout part of keyboard-layouts? */ + if (num_layouts) { + gboolean layout_in_config = FALSE; + for (gint j = 0; j < num_layouts; ++j) + { + if (g_strcmp0 (layouts[j], label) == 0) + { + layout_in_config = TRUE; + break; + } + } + if (!layout_in_config) { + g_free(label); + continue; + } + } + GtkWidget *menuitem = gtk_radio_menu_item_new (menu_group); menu_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); @@ -1819,6 +1843,23 @@ update_layouts_menu (void) for (item = lightdm_get_layouts (); item; item = g_list_next (item)) { LightDMLayout *layout = item->data; + + /* is the keyboard layout part of keyboard-layouts? */ + if (num_layouts) { + gboolean layout_in_config = FALSE; + for (gint j = 0; j < num_layouts; ++j) + { + if (g_strcmp0 (layouts[j], lightdm_layout_get_name (layout)) == 0) + { + layout_in_config = TRUE; + break; + } + } + if (!layout_in_config) { + continue; + } + } + GtkWidget *menuitem = gtk_radio_menu_item_new (menu_group); menu_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); @@ -1833,6 +1874,9 @@ update_layouts_menu (void) gtk_widget_show (GTK_WIDGET (menuitem)); } #endif + + if (layouts) + g_strfreev (layouts); } static void -- cgit v1.2.1