mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 15:40:41 -05:00
Keybindings: uniquify the name for non-builtin keybindings
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
This commit is contained in:
parent
53a17185a0
commit
9e2fc32395
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -264,6 +264,7 @@ typedef struct
|
||||
{
|
||||
char *name;
|
||||
GSettings *settings;
|
||||
char *setting_key;
|
||||
char *hardcoded_key;
|
||||
|
||||
MetaKeyBindingAction action;
|
||||
|
Loading…
Reference in New Issue
Block a user