From b8673b8468e997c687450c664e97098d0ed37abf Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Tue, 14 May 2013 16:08:14 +0200 Subject: [PATCH] Fix ambiguity in shortcut matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comparing to the Qt4 implementation, possibleKeys() should skip records where qtKeys are equal. Task-number: QTBUG-31132 Change-Id: I2fb073b4dc7291f909cce616f40f7c2491e7cf26 Reviewed-by: Friedemann Kleint Reviewed-by: Samuel Rødal Reviewed-by: Tobias Hunger --- src/plugins/platforms/xcb/qxcbkeyboard.cpp | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index 18270d3cd51..155b3273156 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -815,27 +815,27 @@ QList QXcbKeyboard::possibleKeys(const QKeyEvent *event) const xkb_state_update_mask(kb_state, 0, latchedMods, lockedMods, baseLayout, latchedLayout, lockedLayout); - xkb_keysym_t baseKeysym = xkb_state_key_get_one_sym(kb_state, event->nativeScanCode()); - if (baseKeysym == XKB_KEY_NoSymbol) { + xkb_keysym_t sym = xkb_state_key_get_one_sym(kb_state, event->nativeScanCode()); + if (sym == XKB_KEY_NoSymbol) return QList(); - } QList result; - int qtKey = keysymToQtKey(baseKeysym, modifiers, keysymToUnicode(baseKeysym)); - result += (qtKey + modifiers); // The base key is _always_ valid, of course + int baseQtKey = keysymToQtKey(sym, modifiers, keysymToUnicode(sym)); + result += (baseQtKey + modifiers); // The base key is _always_ valid, of course xkb_mod_index_t shiftMod = xkb_keymap_mod_get_index(xkb_keymap, "Shift"); xkb_mod_index_t altMod = xkb_keymap_mod_get_index(xkb_keymap, "Alt"); xkb_mod_index_t controlMod = xkb_keymap_mod_get_index(xkb_keymap, "Control"); - xkb_keysym_t sym; - xkb_mod_mask_t depressed = 0; + xkb_mod_mask_t depressed; + int qtKey = 0; //obtain a list of possible shortcuts for the given key event for (uint i = 1; i < sizeof(ModsTbl) / sizeof(*ModsTbl) ; ++i) { Qt::KeyboardModifiers neededMods = ModsTbl[i]; if ((modifiers & neededMods) == neededMods) { + depressed = 0; if (neededMods & Qt::AltModifier) depressed |= (1 << altMod); if (neededMods & Qt::ShiftModifier) @@ -848,13 +848,16 @@ QList QXcbKeyboard::possibleKeys(const QKeyEvent *event) const baseLayout, latchedLayout, lockedLayout); sym = xkb_state_key_get_one_sym(kb_state, event->nativeScanCode()); - if (sym == XKB_KEY_NoSymbol || sym == baseKeysym) - continue; + if (sym == XKB_KEY_NoSymbol) + continue; Qt::KeyboardModifiers mods = modifiers & ~neededMods; qtKey = keysymToQtKey(sym, mods, keysymToUnicode(sym)); + + if (qtKey == baseQtKey) + continue; + result += (qtKey + mods); - depressed = 0; } }