From b212fc80a7be8877ddbdf99f95a4f7663293f551 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Mon, 1 Jul 2013 14:08:32 +0200 Subject: Resolve modifier mask conflicts on X11 On X11 key codes and modifiers can have many-to-many relationship, i.e. a key can activate several modifiers, and a modifier may be activated by several keys. This patch handles these cases, the logic is borrowed from Qt4. Task-number: QTBUG-31572 Change-Id: Ide4eb890ec723c68afafe0576d8285440a47d7b0 Reviewed-by: Nikolai Kosjar Reviewed-by: Lars Knoll --- src/plugins/platforms/xcb/qxcbkeyboard.cpp | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/xcb/qxcbkeyboard.cpp') diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index 6e5a9ccbb4..ae8bcb802b 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -1035,6 +1035,10 @@ void QXcbKeyboard::updateVModMapping() vmod_masks.meta = bit; else if (qstrcmp(vmod_name, "AltGr") == 0) vmod_masks.altgr = bit; + else if (qstrcmp(vmod_name, "Super") == 0) + vmod_masks.super = bit; + else if (qstrcmp(vmod_name, "Hyper") == 0) + vmod_masks.hyper = bit; } free(name_reply); @@ -1096,9 +1100,14 @@ void QXcbKeyboard::updateVModToRModMapping() rmod_masks.meta = modmap; else if (vmod_masks.altgr == bit) rmod_masks.altgr = modmap; + else if (vmod_masks.super == bit) + rmod_masks.super = modmap; + else if (vmod_masks.hyper == bit) + rmod_masks.hyper = modmap; } free(map_reply); + resolveMaskConflicts(); } #else void QXcbKeyboard::updateModifiers() @@ -1123,7 +1132,8 @@ void QXcbKeyboard::updateModifiers() // for Alt and Meta L and R are the same static const xcb_keysym_t symbols[] = { - XK_Alt_L, XK_Meta_L, XK_Mode_switch + XK_Alt_L, XK_Meta_L, XK_Mode_switch, XK_Super_L, XK_Super_R, + XK_Hyper_L, XK_Hyper_R }; static const size_t numSymbols = sizeof symbols / sizeof *symbols; @@ -1149,6 +1159,10 @@ void QXcbKeyboard::updateModifiers() rmod_masks.meta = mask; if (sym == XK_Mode_switch) rmod_masks.altgr = mask; + if ((sym == XK_Super_L) || (sym == XK_Super_R)) + rmod_masks.super = mask; + if ((sym == XK_Hyper_L) || (sym == XK_Hyper_R)) + rmod_masks.hyper = mask; } } } @@ -1157,9 +1171,28 @@ void QXcbKeyboard::updateModifiers() for (size_t i = 0; i < numSymbols; ++i) free(modKeyCodes[i]); free(modMapReply); + resolveMaskConflicts(); } #endif +void QXcbKeyboard::resolveMaskConflicts() +{ + // if we don't have a meta key (or it's hidden behind alt), use super or hyper to generate + // Qt::Key_Meta and Qt::MetaModifier, since most newer XFree86/Xorg installations map the Windows + // key to Super + if (rmod_masks.alt == rmod_masks.meta) + rmod_masks.meta = 0; + + if (rmod_masks.meta == 0) { + // no meta keys... s/meta/super, + rmod_masks.meta = rmod_masks.super; + if (rmod_masks.meta == 0) { + // no super keys either? guess we'll use hyper then + rmod_masks.meta = rmod_masks.hyper; + } + } +} + class KeyChecker { public: -- cgit v1.2.3