diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2012-06-23 17:16:37 +0200 |
---|---|---|
committer | Giovanni Campagna <gcampagna@src.gnome.org> | 2012-11-10 17:06:29 +0100 |
commit | 9e2fc32395d314bcbc191452f315b813512c581b (patch) | |
tree | c84247a5725fb1f0d3fa52d113f2780d221b03e0 | |
parent | 53a17185a06efb797b7a4b6d639d0da5140785ee (diff) | |
download | mutter-wip/media-keys.tar.gz |
Keybindings: uniquify the name for non-builtin keybindingswip/media-keys
Multiple settings objects could have the same key, so that alone
is not enough to identify the binding. Add also the pointer value
of the GSettings object.
https://bugzilla.gnome.org/show_bug.cgi?id=613543
-rw-r--r-- | src/core/keybindings-private.h | 1 | ||||
-rw-r--r-- | src/core/keybindings.c | 42 | ||||
-rw-r--r-- | src/core/prefs.c | 9 | ||||
-rw-r--r-- | src/meta/display.h | 3 | ||||
-rw-r--r-- | src/meta/prefs.h | 1 |
5 files changed, 43 insertions, 13 deletions
diff --git a/src/core/keybindings-private.h b/src/core/keybindings-private.h index b891d118e..6ce1731a0 100644 --- a/src/core/keybindings-private.h +++ b/src/core/keybindings-private.h @@ -75,6 +75,7 @@ void meta_display_process_mapping_event (MetaDisplay *display, gboolean meta_prefs_add_keybinding (const char *name, GSettings *settings, + const char *setting_key, const char *hardcoded_key, MetaKeyBindingAction action, MetaKeyBindingFlags flags); diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 19a4997eb..9e3190331 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -539,6 +539,7 @@ static gboolean add_keybinding_internal (MetaDisplay *display, const char *name, GSettings *settings, + const char *setting_key, const char *hardcoded_key, MetaKeyBindingFlags flags, MetaKeyBindingAction action, @@ -549,7 +550,7 @@ add_keybinding_internal (MetaDisplay *display, { MetaKeyHandler *handler; - if (!meta_prefs_add_keybinding (name, settings, hardcoded_key, action, flags)) + if (!meta_prefs_add_keybinding (name, settings, setting_key, hardcoded_key, action, flags)) return FALSE; handler = g_new0 (MetaKeyHandler, 1); @@ -568,16 +569,20 @@ add_keybinding_internal (MetaDisplay *display, static gboolean add_builtin_keybinding (MetaDisplay *display, - const char *name, + const char *key, GSettings *settings, MetaKeyBindingFlags flags, MetaKeyBindingAction action, MetaKeyHandlerFunc handler, int handler_arg) { - return add_keybinding_internal (display, name, settings, NULL, + char *name = g_strdup_printf ("internal-keybinding-%s", key); + + return add_keybinding_internal (display, name, settings, key, NULL, flags | META_KEY_BINDING_BUILTIN, action, handler, handler_arg, NULL, NULL); + + g_free (name); } /** @@ -609,16 +614,20 @@ add_builtin_keybinding (MetaDisplay *display, */ gboolean meta_display_add_keybinding (MetaDisplay *display, - const char *name, + const char *key, GSettings *settings, MetaKeyBindingFlags flags, MetaKeyHandlerFunc handler, gpointer user_data, GDestroyNotify free_data) { - return add_keybinding_internal (display, name, settings, NULL, + char *name = g_strdup_printf("custom-keybinding-%p-%s", settings, key); + + return add_keybinding_internal (display, name, settings, key, NULL, flags, META_KEYBINDING_ACTION_NONE, handler, 0, user_data, free_data); + + g_free (name); } /** @@ -644,7 +653,7 @@ meta_display_add_grabbed_key (MetaDisplay *display, gpointer user_data, GDestroyNotify free_data) { - return add_keybinding_internal (display, name, NULL, keyval, + return add_keybinding_internal (display, name, NULL, NULL, keyval, flags, META_KEYBINDING_ACTION_NONE, handler, 0, user_data, free_data); } @@ -672,6 +681,7 @@ meta_display_remove_grabbed_key (MetaDisplay *display, * meta_display_remove_keybinding: * @display: the #MetaDisplay * @name: name of the keybinding to remove + * @settings: (allow-none): the #GSettings object on which the keybinding is registered * * Remove keybinding @name; the function will fail if @name is not a known * keybinding or has not been added with meta_display_add_keybinding(). @@ -681,14 +691,28 @@ meta_display_remove_grabbed_key (MetaDisplay *display, */ gboolean meta_display_remove_keybinding (MetaDisplay *display, - const char *name) + const char *key, + GSettings *settings) { + gboolean retval; + char *name; + + if (settings) + name = g_strdup_printf ("custom-keybinding-%p-%s", settings, key); + else + name = g_strdup (key); + + retval = FALSE; if (!meta_prefs_remove_keybinding (name)) - return FALSE; + goto out; g_hash_table_remove (key_handlers, name); - return TRUE; + retval = TRUE; + + out: + g_free (name); + return retval; } /** diff --git a/src/core/prefs.c b/src/core/prefs.c index c8604073c..8a6e95d3d 100644 --- a/src/core/prefs.c +++ b/src/core/prefs.c @@ -1711,6 +1711,7 @@ meta_key_pref_free (MetaKeyPref *pref) g_free (pref->name); if (pref->settings) g_object_unref (pref->settings); + g_free (pref->setting_key); g_free (pref->hardcoded_key); g_free (pref); @@ -1935,6 +1936,7 @@ meta_prefs_get_visual_bell_type (void) gboolean meta_prefs_add_keybinding (const char *name, GSettings *settings, + const char *setting_key, const char *hardcoded_key, MetaKeyBindingAction action, MetaKeyBindingFlags flags) @@ -1953,6 +1955,7 @@ meta_prefs_add_keybinding (const char *name, pref = g_new0 (MetaKeyPref, 1); pref->name = g_strdup (name); pref->settings = settings ? g_object_ref (settings) : NULL; + pref->setting_key = g_strdup (setting_key); pref->hardcoded_key = g_strdup (hardcoded_key); pref->action = action; pref->bindings = NULL; @@ -1965,12 +1968,12 @@ meta_prefs_add_keybinding (const char *name, { if (pref->is_single) { - static_strokes[0] = g_settings_get_string (settings, name); + static_strokes[0] = g_settings_get_string (settings, setting_key); static_strokes[1] = NULL; strokes = static_strokes; } else - strokes = g_settings_get_strv (settings, name); + strokes = g_settings_get_strv (settings, setting_key); } else { @@ -2001,7 +2004,7 @@ meta_prefs_add_keybinding (const char *name, } else { - char *changed_signal = g_strdup_printf ("changed::%s", name); + char *changed_signal = g_strdup_printf ("changed::%s", setting_key); id = g_signal_connect (settings, changed_signal, G_CALLBACK (bindings_changed), NULL); g_free (changed_signal); diff --git a/src/meta/display.h b/src/meta/display.h index 7af830b22..8d07036c7 100644 --- a/src/meta/display.h +++ b/src/meta/display.h @@ -144,7 +144,8 @@ gboolean meta_display_add_grabbed_key (MetaDisplay *display, gboolean meta_display_remove_grabbed_key(MetaDisplay *display, const char *name); gboolean meta_display_remove_keybinding (MetaDisplay *display, - const char *name); + const char *name, + GSettings *settings); MetaKeyBindingAction meta_display_get_keybinding_action (MetaDisplay *display, unsigned int keycode, diff --git a/src/meta/prefs.h b/src/meta/prefs.h index 0646fc7d6..ffbba4698 100644 --- a/src/meta/prefs.h +++ b/src/meta/prefs.h @@ -264,6 +264,7 @@ typedef struct { char *name; GSettings *settings; + char *setting_key; char *hardcoded_key; MetaKeyBindingAction action; |