summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-02 22:22:29 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-04 06:16:43 -0400
commit8e4d5731697cf5532188003189f6e362556b7eb2 (patch)
tree7accc91c1f49b207af11b740c52032e0d92bf2ae
parent01a85d5861bff5dc7f4d838c8767eb86d5b2e9e9 (diff)
downloadgnome-desktop-reparse-xkb-layouts.tar.gz
xkb: Clear cached layouts when necessaryreparse-xkb-layouts
The value of the show-all-sources setting influences what layouts we provide, so monitor the setting, and when it changes, clear the cached layouts and emit the new GnomeXkbInfo::layouts-changed signal. Fixes: #195
-rw-r--r--libgnome-desktop/gnome-xkb-info.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c
index 2bb3036c..c43a2d68 100644
--- a/libgnome-desktop/gnome-xkb-info.c
+++ b/libgnome-desktop/gnome-xkb-info.c
@@ -77,6 +77,7 @@ struct _GnomeXkbInfoPrivate
GHashTable *layouts_by_country;
GHashTable *layouts_by_language;
GHashTable *layouts_table;
+ GSettings *settings;
#ifndef HAVE_XKBREGISTRY
/* Only used while parsing */
@@ -90,6 +91,8 @@ struct _GnomeXkbInfoPrivate
#endif
};
+static guint layouts_changed_signal;
+
G_DEFINE_TYPE_WITH_CODE (GnomeXkbInfo, gnome_xkb_info, G_TYPE_OBJECT,
G_ADD_PRIVATE (GnomeXkbInfo));
@@ -740,7 +743,6 @@ static void
parse_rules (GnomeXkbInfo *self)
{
GnomeXkbInfoPrivate *priv = self->priv;
- GSettings *settings;
gboolean show_all_sources;
/* Make sure the translated strings we get from XKEYBOARD_CONFIG() are
@@ -764,9 +766,7 @@ parse_rules (GnomeXkbInfo *self)
/* Maps layout ids to Layout structs. Owns the Layout structs. */
priv->layouts_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_layout);
- settings = g_settings_new ("org.gnome.desktop.input-sources");
- show_all_sources = g_settings_get_boolean (settings, "show-all-sources");
- g_object_unref (settings);
+ show_all_sources = g_settings_get_boolean (priv->settings, "show-all-sources");
if (!parse_rules_file (self, XKB_RULES_FILE, show_all_sources))
{
@@ -790,9 +790,19 @@ ensure_rules_are_parsed (GnomeXkbInfo *self)
}
static void
+show_all_sources_changed (GnomeXkbInfo *self)
+{
+ g_clear_pointer (&self->priv->layouts_table, g_hash_table_unref);
+ g_signal_emit (self, layouts_changed_signal, 0);
+}
+
+static void
gnome_xkb_info_init (GnomeXkbInfo *self)
{
self->priv = gnome_xkb_info_get_instance_private (self);
+ self->priv->settings = g_settings_new ("org.gnome.desktop.input-sources");
+ g_signal_connect_swapped (self->priv->settings, "changed::show-all-sources",
+ G_CALLBACK (show_all_sources_changed), self);
}
static void
@@ -808,6 +818,7 @@ gnome_xkb_info_finalize (GObject *self)
g_hash_table_destroy (priv->layouts_by_language);
if (priv->layouts_table)
g_hash_table_destroy (priv->layouts_table);
+ g_clear_object (&priv->settings);
G_OBJECT_CLASS (gnome_xkb_info_parent_class)->finalize (self);
}
@@ -818,6 +829,15 @@ gnome_xkb_info_class_init (GnomeXkbInfoClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = gnome_xkb_info_finalize;
+
+ layouts_changed_signal =
+ g_signal_new ("layouts-changed",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
}
/**