From 080113e04c5445a7e5fc300d5127d8c3b2806283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 26 Sep 2013 09:31:23 +0200 Subject: [PATCH] Introduce a new backtab test handling in TabBox invokation Our back shortcut is registered as Alt+Shift+Backtab but our converted Qt key coming into the test method is Alt+Shift+Tab. The logic so far made this always fire for the normal Alt+Tab shortcut as at some point the Shift modifier gets removed to do the test. To handle it properly we first have to extract all the modifiers to just get the key. If the key is Tab, we replace it with Backtab, combine it with the extracted mods so it will be Alt+Shift+Backtab which matches the registered shortcut. The existing backtab solution can probably be removed and is clearly wrong as it uses the keys as flags which they aren't. --- tabbox/tabbox.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index f4c3b1b446..62ac95997d 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -1316,6 +1316,34 @@ void TabBox::keyPress(int keyQt) } return false; }; + auto testBacktab = [&forward,&backward,keyQt,contains](const QKeySequence &forwardShortcut, const QKeySequence &backwardShortcut) { + if (forward || backward || !(keyQt & Qt::ShiftModifier)) { + return; + } + // a shortcut containing Shift+Tab will not fire as it is registered as Alt+Backtab + // the keyQt we get does not contain the backtab, so we need to convert it + // extract the modifiers, tests whether the key is tab and create a new test shortcut + // containing the extracted modifiers and backtab instead of tab + Qt::KeyboardModifiers mods = Qt::ShiftModifier; + auto testMod = [&mods,keyQt](Qt::KeyboardModifier modifier) { + if (keyQt & modifier) { + mods |= modifier; + } + }; + // unfortunately we have to test each of the modifiers and cannot just and with ~NoModifier + // we don't need the shift test as we already know that shift is hold + testMod(Qt::ControlModifier); + testMod(Qt::AltModifier); + testMod(Qt::MetaModifier); + testMod(Qt::KeypadModifier); + testMod(Qt::GroupSwitchModifier); + // Do not AND with Key_Tab! Key_Tab is 0x01000001 which would also return true for + // Qt::Key_Backspace which is 0x01000003 and a whole bunch of other keys! + if ((keyQt & ~mods) == Qt::Key_Tab) { + forward = contains(forwardShortcut, mods | Qt::Key_Backtab); + backward = contains(backwardShortcut, mods | Qt::Key_Backtab); + } + }; if (m_tabGrab) { QKeySequence forwardShortcut; @@ -1343,6 +1371,7 @@ void TabBox::keyPress(int keyQt) } forward = contains(forwardShortcut, keyQt); backward = contains(backwardShortcut, keyQt); + testBacktab(forwardShortcut, backwardShortcut); if ((keyQt & Qt::ShiftModifier) && !(forward || backward)) { // if the shortcuts do not match, try matching again after filtering the shift key from keyQt // it is needed to handle correctly the ALT+~ shorcut for example as it is coded as ALT+SHIFT+~ in keyQt @@ -1377,6 +1406,8 @@ void TabBox::keyPress(int keyQt) contains(m_cutWalkThroughDesktopList, keyQt); backward = contains(m_cutWalkThroughDesktopsReverse, keyQt) || contains(m_cutWalkThroughDesktopListReverse, keyQt); + testBacktab(m_cutWalkThroughDesktops, m_cutWalkThroughDesktopsReverse); + testBacktab(m_cutWalkThroughDesktopList, m_cutWalkThroughDesktopListReverse); if ((keyQt & Qt::ShiftModifier) && !(forward || backward)) { // if the shortcuts do not match, try matching again after filtering the shift key from keyQt // it is needed to handle correctly the ALT+~ shorcut for example as it is coded as ALT+SHIFT+~ in keyQt