From d78de379cc2b5dd7e4f6ed0368c959aca57ab4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 12 Dec 2012 14:03:58 +0100 Subject: [PATCH] keybindings: Give dynamic keybindings a keybindings action https://bugzilla.gnome.org/show_bug.cgi?id=682315 --- src/core/keybindings.c | 30 ++++++++++++++++++------------ src/meta/display.h | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 8bd1ebd5c..e3cec587a 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -610,10 +610,10 @@ add_builtin_keybinding (MetaDisplay *display, * * Use meta_display_remove_keybinding() to remove the binding. * - * Returns: %TRUE if the keybinding was added successfully, - * otherwise %FALSE + * Returns: the corresponding keybinding action if the keybinding was + * added successfully, otherwise %META_KEYBINDING_ACTION_NONE */ -gboolean +guint meta_display_add_keybinding (MetaDisplay *display, const char *name, GSettings *settings, @@ -622,9 +622,15 @@ meta_display_add_keybinding (MetaDisplay *display, gpointer user_data, GDestroyNotify free_data) { - return add_keybinding_internal (display, name, settings, flags, - META_KEYBINDING_ACTION_NONE, - handler, 0, user_data, free_data); + static guint num_dynamic_bindings = 0; + guint new_action = META_KEYBINDING_ACTION_LAST + num_dynamic_bindings; + + if (!add_keybinding_internal (display, name, settings, flags, new_action, + handler, 0, user_data, free_data)) + return META_KEYBINDING_ACTION_NONE; + + ++num_dynamic_bindings; + return new_action; } /** @@ -656,15 +662,15 @@ meta_display_remove_keybinding (MetaDisplay *display, * @keycode: Raw keycode * @mask: Event mask * - * Get the #MetaKeyBindingAction bound to %keycode. Only builtin - * keybindings have an associated #MetaKeyBindingAction, for - * bindings added dynamically with meta_display_add_keybinding() - * the function will always return %META_KEYBINDING_ACTION_NONE. + * Get the keybinding action bound to @keycode. Builtin keybindings + * have a fixed associated #MetaKeyBindingAction, for bindings added + * dynamically the function will return the keybinding action + * meta_display_add_keybinding() returns on registration. * * Returns: The action that should be taken for the given key, or * %META_KEYBINDING_ACTION_NONE. */ -MetaKeyBindingAction +guint meta_display_get_keybinding_action (MetaDisplay *display, unsigned int keycode, unsigned long mask) @@ -689,7 +695,7 @@ meta_display_get_keybinding_action (MetaDisplay *display, binding = display_get_keybinding (display, META_KEY_ABOVE_TAB, keycode, mask); if (binding) - return meta_prefs_get_keybinding_action (binding->name); + return (guint) meta_prefs_get_keybinding_action (binding->name); else return META_KEYBINDING_ACTION_NONE; } diff --git a/src/meta/display.h b/src/meta/display.h index 04d545c36..8dc3dac28 100644 --- a/src/meta/display.h +++ b/src/meta/display.h @@ -127,19 +127,19 @@ void meta_display_end_grab_op (MetaDisplay *display, MetaGrabOp meta_display_get_grab_op (MetaDisplay *display); -gboolean meta_display_add_keybinding (MetaDisplay *display, - const char *name, - GSettings *settings, - MetaKeyBindingFlags flags, - MetaKeyHandlerFunc handler, - gpointer user_data, - GDestroyNotify free_data); +guint meta_display_add_keybinding (MetaDisplay *display, + const char *name, + GSettings *settings, + MetaKeyBindingFlags flags, + MetaKeyHandlerFunc handler, + gpointer user_data, + GDestroyNotify free_data); gboolean meta_display_remove_keybinding (MetaDisplay *display, const char *name); -MetaKeyBindingAction meta_display_get_keybinding_action (MetaDisplay *display, - unsigned int keycode, - unsigned long mask); +guint meta_display_get_keybinding_action (MetaDisplay *display, + unsigned int keycode, + unsigned long mask); /* meta_display_set_input_focus_window is like XSetInputFocus, except * that (a) it can't detect timestamps later than the current time,