[gnome-control-center] keyboard: Allow Tab in accels



commit 4beb7cefd4024ce09c70b61783b244e6d38aad59
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Sep 8 14:31:34 2016 +0200

    keyboard: Allow Tab in accels
    
    gtk_accelerator_valid() doesn't accept Tab as keyval, so using it to
    check whether a shortcut is valid breaks commonly used shortcuts like
    Alt+Tab. Unbreak those by adding a small wrapper that special-cases
    Tab-with-modifiers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771058

 panels/keyboard/cc-keyboard-shortcut-editor.c |    2 +-
 panels/keyboard/keyboard-shortcuts.c          |   11 +++++++++++
 panels/keyboard/keyboard-shortcuts.h          |    3 +++
 3 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c
index cb4580f..90063f1 100644
--- a/panels/keyboard/cc-keyboard-shortcut-editor.c
+++ b/panels/keyboard/cc-keyboard-shortcut-editor.c
@@ -282,7 +282,7 @@ setup_custom_shortcut (CcKeyboardShortcutEditor *self)
 
   is_custom = is_custom_shortcut (self);
   accel_valid = is_valid_binding (self->custom_keyval, self->custom_mask, self->custom_keycode) &&
-                gtk_accelerator_valid (self->custom_keyval, self->custom_mask) &&
+                is_valid_accel (self->custom_keyval, self->custom_mask) &&
                 !self->custom_is_modifier;
   if (is_empty_binding (self->custom_keyval, self->custom_mask, self->custom_keycode))
     accel_valid = TRUE;
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c
index 91d8dfb..1c22f5a 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -302,6 +302,17 @@ is_empty_binding (guint                  keyval,
   return FALSE;
 }
 
+gboolean
+is_valid_accel (guint           keyval,
+                GdkModifierType mask)
+{
+  /* Unlike gtk_accelerator_valid(), we want to allow Tab when combined
+   * with some modifiers (Alt+Tab and friends)
+   */
+  return gtk_accelerator_valid (keyval, mask) ||
+         (keyval == GDK_KEY_Tab && mask != 0);
+}
+
 gchar*
 find_free_settings_path (GSettings *settings)
 {
diff --git a/panels/keyboard/keyboard-shortcuts.h b/panels/keyboard/keyboard-shortcuts.h
index 81e7f89..6c98eee 100644
--- a/panels/keyboard/keyboard-shortcuts.h
+++ b/panels/keyboard/keyboard-shortcuts.h
@@ -93,6 +93,9 @@ gboolean is_empty_binding               (guint           keyval,
                                          GdkModifierType mask,
                                          guint           keycode);
 
+gboolean is_valid_accel                 (guint           keyval,
+                                         GdkModifierType mask);
+
 KeyList* parse_keylist_from_file        (const gchar *path);
 
 gchar*   convert_keysym_state_to_string (guint           keysym,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]