From 4beb7cefd4024ce09c70b61783b244e6d38aad59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 8 Sep 2016 14:31:34 +0200 Subject: [PATCH] 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 deletion(-) diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c index cb4580f6f..90063f16e 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 91d8dfb1d..1c22f5a75 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 81e7f896d..6c98eee6a 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,