From 22ebca106794af153c01eae7e0175eb9f1a27648 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Fri, 8 Jun 2012 10:28:33 -0400 Subject: [PATCH] Fix issue - keybinding with Super, Hyper and Meta Modifiers does not work. BUG=None TEST=Manually Review URL: https://codereview.appspot.com/6302047 --- ui/gtk3/grabkeycode.c | 16 ++++++++-------- ui/gtk3/keybindingmanager.vala | 18 ++++++++++++------ ui/gtk3/panel.vala | 26 +++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/ui/gtk3/grabkeycode.c b/ui/gtk3/grabkeycode.c index 200f956..6a2d02f 100644 --- a/ui/gtk3/grabkeycode.c +++ b/ui/gtk3/grabkeycode.c @@ -42,14 +42,14 @@ gboolean grab_keycode (GdkDisplay *display, XISetMask (mask.mask, XI_KeyRelease); XIGrabModifiers ximodifiers[] = { - {modifiers, 0}, - {Mod2Mask | modifiers, 0}, - {LockMask | modifiers, 0}, - {Mod5Mask | modifiers, 0}, - {Mod2Mask | LockMask | modifiers, 0}, - {Mod2Mask | Mod5Mask | modifiers, 0}, - {LockMask | Mod5Mask | modifiers, 0}, - {Mod2Mask | LockMask | Mod5Mask | modifiers, 0}, + { modifiers, 0 }, + { LockMask | modifiers, 0 }, + { Mod2Mask | modifiers, 0 }, + { Mod5Mask | modifiers, 0 }, + { LockMask | Mod2Mask | modifiers, 0 }, + { Mod2Mask | Mod5Mask | modifiers, 0 }, + { LockMask | Mod5Mask | modifiers, 0 }, + { LockMask | Mod2Mask | Mod5Mask | modifiers, 0 }, }; int retval = XIGrabKeycode (xdisplay, diff --git a/ui/gtk3/keybindingmanager.vala b/ui/gtk3/keybindingmanager.vala index d2821ad..2e1be4a 100644 --- a/ui/gtk3/keybindingmanager.vala +++ b/ui/gtk3/keybindingmanager.vala @@ -33,15 +33,20 @@ public class KeybindingManager : GLib.Object { public static const uint MODIFIER_FILTER = Gdk.ModifierType.MODIFIER_MASK & ~( - Gdk.ModifierType.MOD2_MASK | - Gdk.ModifierType.LOCK_MASK | - Gdk.ModifierType.MOD4_MASK | - Gdk.ModifierType.MOD5_MASK | + Gdk.ModifierType.LOCK_MASK | // Caps Lock + // Gdk.ModifierType.MOD1_MASK | // Alt + Gdk.ModifierType.MOD2_MASK | // Num Lock + // Gdk.ModifierType.MOD3_MASK | + // Gdk.ModifierType.MOD4_MASK | // Super, Hyper + // Gdk.ModifierType.MOD5_MASK | // Gdk.ModifierType.BUTTON1_MASK | Gdk.ModifierType.BUTTON2_MASK | Gdk.ModifierType.BUTTON3_MASK | Gdk.ModifierType.BUTTON4_MASK | - Gdk.ModifierType.BUTTON5_MASK); + Gdk.ModifierType.BUTTON5_MASK | + Gdk.ModifierType.SUPER_MASK | + Gdk.ModifierType.HYPER_MASK | + Gdk.ModifierType.META_MASK); /** * Helper class to store keybinding @@ -196,8 +201,9 @@ public class KeybindingManager : GLib.Object { private void event_handler(Gdk.Event event) { do { - if (event.any.window != Gdk.get_default_root_window()) + if (event.any.window != Gdk.get_default_root_window()) { break; + } if (event.type == Gdk.EventType.KEY_PRESS) { uint modifiers = event.key.state & MODIFIER_FILTER; diff --git a/ui/gtk3/panel.vala b/ui/gtk3/panel.vala index d539dde..25d705d 100644 --- a/ui/gtk3/panel.vala +++ b/ui/gtk3/panel.vala @@ -84,12 +84,32 @@ class Panel : IBus.PanelService { private void bind_switch_shortcut() { var keybinding_manager = KeybindingManager.get_instance(); - Gtk.accelerator_parse(ACCELERATOR_SWITCH_IME_FOREWARD, + var accelerator = ACCELERATOR_SWITCH_IME_FOREWARD; + Gtk.accelerator_parse(accelerator, out m_switch_keysym, out m_switch_modifiers); + // Map virtual modifiers to (i.e.Mod2, Mod3, ...) + const Gdk.ModifierType VIRTUAL_MODIFIERS = ( + Gdk.ModifierType.SUPER_MASK | + Gdk.ModifierType.HYPER_MASK | + Gdk.ModifierType.META_MASK); + if ((m_switch_modifiers & VIRTUAL_MODIFIERS) != 0) { + // workaround a bug in gdk vapi vala > 0.18 + // https://bugzilla.gnome.org/show_bug.cgi?id=677559 +#if VALA_0_18 + Gdk.Keymap.get_default().map_virtual_modifiers( + ref m_switch_modifiers); +#else + if ((m_switch_modifiers & Gdk.ModifierType.SUPER_MASK) != 0) + m_switch_modifiers |= Gdk.ModifierType.MOD4_MASK; + if ((m_switch_modifiers & Gdk.ModifierType.HYPER_MASK) != 0) + m_switch_modifiers |= Gdk.ModifierType.MOD4_MASK; +#endif + m_switch_modifiers &= ~VIRTUAL_MODIFIERS; + } + if (m_switch_keysym == 0 && m_switch_modifiers == 0) { - warning("Parse accelerator '%s' failed!", - ACCELERATOR_SWITCH_IME_FOREWARD); + warning("Parse accelerator '%s' failed!", accelerator); return; } -- 2.7.4