[gnome-control-center] keyboard: Track all key combos
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] keyboard: Track all key combos
- Date: Mon, 10 Jul 2017 17:42:07 +0000 (UTC)
commit 5e4fa7bd39734bcfb9d66fd9b172bad826708124
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 27 00:59:11 2013 +0200
keyboard: Track all key combos
For shortcuts that support more than one binding, we currently simply
ignore all but the first. This makes some sense as we only expose a
single binding in the UI anyway, however it means that any extra
bindings are not taken into account for conflict resolution. In order
to address this in the future, start tracking all bindings of an item.
https://bugzilla.gnome.org/show_bug.cgi?id=673078
panels/keyboard/cc-keyboard-item.c | 60 ++++++++++++++++++++++++++++++++++++
panels/keyboard/cc-keyboard-item.h | 2 +
2 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-item.c b/panels/keyboard/cc-keyboard-item.c
index 0810c7b..f68d64a 100644
--- a/panels/keyboard/cc-keyboard-item.c
+++ b/panels/keyboard/cc-keyboard-item.c
@@ -371,6 +371,8 @@ cc_keyboard_item_finalize (GObject *object)
g_free (item->command);
g_free (item->schema);
g_free (item->key);
+ g_list_free_full (item->key_combos, g_free);
+ g_list_free_full (item->default_combos, g_free);
G_OBJECT_CLASS (cc_keyboard_item_parent_class)->finalize (object);
}
@@ -387,6 +389,52 @@ cc_keyboard_item_new (CcKeyboardItemType type)
return CC_KEYBOARD_ITEM (object);
}
+static GList *
+variant_get_key_combos (GVariant *variant)
+{
+ GList *combos = NULL;
+ char **bindings = NULL, **str;
+
+ if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING))
+ {
+ bindings = g_malloc0_n (2, sizeof(char *));
+ bindings[0] = g_variant_dup_string (variant, NULL);
+ }
+ else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING_ARRAY))
+ {
+ bindings = g_variant_dup_strv (variant, NULL);
+ }
+
+ for (str = bindings; *str; str++)
+ {
+ CcKeyCombo *combo = g_new (CcKeyCombo, 1);
+
+ binding_from_string (*str, combo);
+ combos = g_list_prepend (combos, combo);
+ }
+ g_strfreev (bindings);
+
+ return g_list_reverse (combos);
+}
+
+static GList *
+settings_get_key_combos (GSettings *settings,
+ const char *key,
+ gboolean use_default)
+{
+ GList *key_combos;
+ GVariant *variant;
+
+ if (use_default)
+ variant = g_settings_get_default_value (settings, key);
+ else
+ variant = g_settings_get_value (settings, key);
+ key_combos = variant_get_key_combos (variant);
+ g_variant_unref (variant);
+
+ return key_combos;
+}
+
/* wrapper around g_settings_get_str[ing|v] */
static char *
settings_get_binding (GSettings *settings,
@@ -418,6 +466,9 @@ binding_changed (GSettings *settings,
{
char *value;
+ g_list_free_full (item->key_combos, g_free);
+ item->key_combos = settings_get_key_combos (item->settings, item->key, FALSE);
+
value = settings_get_binding (item->settings, item->key);
item->editable = g_settings_is_writable (item->settings, item->key);
_set_binding (item, value, FALSE);
@@ -450,6 +501,9 @@ cc_keyboard_item_load_from_gsettings_path (CcKeyboardItem *item,
g_settings_bind (item->settings, "command",
G_OBJECT (item), "command", G_SETTINGS_BIND_DEFAULT);
+ g_list_free_full (item->key_combos, g_free);
+ item->key_combos = settings_get_key_combos (item->settings, item->key, FALSE);
+
g_free (item->priv->binding);
item->priv->binding = settings_get_binding (item->settings, item->key);
binding_from_string (item->priv->binding, item->primary_combo);
@@ -477,6 +531,12 @@ cc_keyboard_item_load_from_gsettings (CcKeyboardItem *item,
item->editable = g_settings_is_writable (item->settings, item->key);
binding_from_string (item->priv->binding, item->primary_combo);
+ g_list_free_full (item->key_combos, g_free);
+ item->key_combos = settings_get_key_combos (item->settings, item->key, FALSE);
+
+ g_list_free_full (item->default_combos, g_free);
+ item->default_combos = settings_get_key_combos (item->settings, item->key, TRUE);
+
signal_name = g_strdup_printf ("changed::%s", item->key);
g_signal_connect (G_OBJECT (item->settings), signal_name,
G_CALLBACK (binding_changed), item);
diff --git a/panels/keyboard/cc-keyboard-item.h b/panels/keyboard/cc-keyboard-item.h
index 22ffd1b..755d46d 100644
--- a/panels/keyboard/cc-keyboard-item.h
+++ b/panels/keyboard/cc-keyboard-item.h
@@ -69,6 +69,8 @@ typedef struct
GtkTreeModel *model;
char *description;
gboolean editable;
+ GList *key_combos;
+ GList *default_combos;
/* GSettings path */
char *gsettings_path;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]