From 1e1d2cc809bf8a95d26e01e0f84e18772d68ef18 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 27 Jul 2012 23:38:24 -0700 Subject: [PATCH] Partial workaround for the Gtk bug with Shift key: make Shift-Fn key combinations work as global shortcuts --- moo/mooutils/mooaccel.c | 58 ++++++++++++++++++++++++++++++++++- moo/mooutils/mooaccel.h | 9 ++++++ moo/mooutils/mooaccelbutton.c | 3 +- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/moo/mooutils/mooaccel.c b/moo/mooutils/mooaccel.c index 4013efb1..82d83d31 100644 --- a/moo/mooutils/mooaccel.c +++ b/moo/mooutils/mooaccel.c @@ -411,6 +411,62 @@ _moo_get_accel_label (const char *accel) return g_strdup (""); } +static gboolean +need_workaround_for_671562 (guint keyval) +{ + switch (keyval) + { + case GDK_KEY_F1: + case GDK_KEY_F2: + case GDK_KEY_F3: + case GDK_KEY_F4: + case GDK_KEY_F5: + case GDK_KEY_F6: + case GDK_KEY_F7: + case GDK_KEY_F8: + case GDK_KEY_F9: + case GDK_KEY_F10: + case GDK_KEY_F11: + case GDK_KEY_F12: + return TRUE; + + default: + return FALSE; + } +} + +/* Wrapper for gdk_keymap_translate_keyboard_state with a workaround + for https://bugzilla.gnome.org/show_bug.cgi?id=671562 */ +gboolean +moo_keymap_translate_keyboard_state (GdkKeymap *keymap, + guint hardware_keycode, + GdkModifierType state, + gint group, + guint *keyval_p, + gint *effective_group, + gint *level, + GdkModifierType *consumed_modifiers_p) +{ + guint keyval = 0; + GdkModifierType consumed_modifiers = 0; + gboolean retval = + gdk_keymap_translate_keyboard_state (keymap, hardware_keycode, state, group, + &keyval, effective_group, level, + &consumed_modifiers); + + /* Check whether Shift mask needs to be added back */ + if ((state & GDK_SHIFT_MASK) && (consumed_modifiers & GDK_SHIFT_MASK) && + need_workaround_for_671562 (keyval)) + { + consumed_modifiers &= ~GDK_SHIFT_MASK; + } + + if (keyval_p) + *keyval_p = keyval; + if (consumed_modifiers_p) + *consumed_modifiers_p = consumed_modifiers; + return retval; +} void moo_accel_translate_event (GtkWidget *widget, @@ -433,7 +489,7 @@ moo_accel_translate_event (GtkWidget *widget, else keymap = gdk_keymap_get_default (); - gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode, + moo_keymap_translate_keyboard_state (keymap, event->hardware_keycode, (GdkModifierType) event->state, event->group, keyval, NULL, NULL, &consumed); if (mods) diff --git a/moo/mooutils/mooaccel.h b/moo/mooutils/mooaccel.h index a15c9457..a1afd4b9 100644 --- a/moo/mooutils/mooaccel.h +++ b/moo/mooutils/mooaccel.h @@ -48,6 +48,15 @@ gboolean moo_accel_check_event (GtkWidget *widget, guint keyval, GdkModifierType mods); +gboolean moo_keymap_translate_keyboard_state (GdkKeymap *keymap, + guint hardware_keycode, + GdkModifierType state, + gint group, + guint *keyval, + gint *effective_group, + gint *level, + GdkModifierType *consumed_modifiers); + #define MOO_ACCEL_MODS_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK | GDK_META_MASK) diff --git a/moo/mooutils/mooaccelbutton.c b/moo/mooutils/mooaccelbutton.c index 0ad627b5..0a456a75 100644 --- a/moo/mooutils/mooaccelbutton.c +++ b/moo/mooutils/mooaccelbutton.c @@ -18,6 +18,7 @@ #include "mooutils/moodialogs.h" #include "mooutils/mooi18n.h" #include "mooutils/mooaccelbutton-gxml.h" +#include "mooutils/mooaccel.h" #include #include @@ -277,7 +278,7 @@ key_event (GtkWidget *widget, int mods; keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget)); - gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode, + moo_keymap_translate_keyboard_state (keymap, event->hardware_keycode, (GdkModifierType) event->state, event->group, NULL, NULL, NULL, &consumed_modifiers);