on xenial help sign in
send a Alt-release event on alt+tab instead of delaying it completely and invoking it later (LP: #1565236)
commita56d6597eb7b98e6dd6da43ab7643e361df901ac authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 17 Jun 2016, 01:17 (10 years ago) parent400ecad1cbb430
2 files changed+14−43
qml/Components/PhysicalKeysMapper.qml+2−22 tests/qmltests/Components/tst_PhysicalKeysMapper.qml+12−21
qml/Components/PhysicalKeysMapper.qml+2−22
@@ -66,11 +66,6 @@ Item {
6666 property bool superTabPressed: false
6767
6868 property var powerButtonPressStart: 0
69−
70− // We need to eat ALT presses until we know what they're for (Alt+Tab or going to the app?)
71− // Once we know if an ALT keypress is for the app, we need to re-inject the pressed event for it
72− // but we must only do that once.
73− property bool altPressInjected: false
7469 }
7570
7671 InputEventGenerator {
@@ -78,12 +73,6 @@ Item {
7873 }
7974
8075 function onKeyPressed(event, currentEventTimestamp) {
81− if (d.altPressed && !d.altTabPressed && event.key !== Qt.Key_Tab && event.key !== Qt.Key_Alt && !d.altPressInjected) {
82− // ALT is pressed and another key that is not Tab has been received. Re-inject the alt pressed event
83− d.altPressInjected = true;
84− inputEventGenerator.generateKeyEvent(Qt.Key_Alt, true, Qt.NoModifier, currentEventTimestamp - 1, 56);
85− }
86−
8776 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
8877 if (event.isAutoRepeat) {
8978 if (d.powerButtonPressStart > 0
@@ -119,12 +108,7 @@ Item {
119108 d.volumeUpKeyPressed = true;
120109 }
121110 } else if (event.key == Qt.Key_Alt || (root.controlInsteadOfAlt && event.key == Qt.Key_Control)) {
122− if (!d.altPressed || event.isAutoRepeat) {
123− // Only eat it if it's the first time we receive alt pressed (or if it's the autorepeat of the first press)
124− d.altPressed = true;
125− event.accepted = true;
126− d.altPressInjected = false;
127− }
111+ d.altPressed = true;
128112
129113 // Adding MetaModifier here because that's what keyboards do. Pressing Super_L actually gives
130114 // Super_L + MetaModifier. This helps to make sure we only invoke superPressed if no other
@@ -135,6 +119,7 @@ Item {
135119 d.superPressed = true;
136120 } else if (event.key == Qt.Key_Tab) {
137121 if (d.altPressed && !d.altTabPressed) {
122+ inputEventGenerator.generateKeyEvent(Qt.Key_Alt, false, Qt.NoModifier, currentEventTimestamp, 56);
138123 d.altTabPressed = true;
139124 event.accepted = true;
140125 }
@@ -161,11 +146,6 @@ Item {
161146 if (d.altTabPressed) {
162147 d.altTabPressed = false;
163148 event.accepted = true;
164− } else if (d.altPressed && !d.altPressInjected) {
165− // Alt was released but nothing else. Let's inject a pressed event and also forward the release.
166− d.altPressInjected = true;
167− inputEventGenerator.generateKeyEvent(Qt.Key_Alt, true, Qt.AltModifer, currentEventTimestamp, 56);
168− d.altPressInjected = false;
169149 }
170150 d.altPressed = false;
171151 } else if (event.key == Qt.Key_Tab) {
tests/qmltests/Components/tst_PhysicalKeysMapper.qml+12−21
@@ -134,40 +134,31 @@ Item {
134134 compare(screenshotSpy.count, 1);
135135 }
136136
137− function test_altIsDispatchedOnRelease() {
138− // Press alt, make sure it does *not* end up in inputCatcher (aka, the focused app)
137+ function test_altIsCancelledOnAltTab() {
138+ // Press alt, make sure it does end up in inputCatcher (aka, the focused app)
139+ inputCatcher.pressedKeys = [];
139140 keyPress(Qt.Key_Alt, Qt.NoModifier)
140− compare(inputCatcher.pressedKeys.length, 0);
141− // Now release alt. It should cause the previous Alt press to be dispatched along with the release
142− keyRelease(Qt.Key_Alt, Qt.NoModifier);
143141 compare(inputCatcher.pressedKeys.length, 1);
144142 compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
143+ // Now also press tab. As this should trigger the spread, alt needs to be released for the app
144+ keyPress(Qt.Key_Tab, Qt.NoModifier)
145145 compare(inputCatcher.releasedKeys.length, 1);
146146 compare(inputCatcher.releasedKeys[0], Qt.Key_Alt);
147− }
148−
149− function test_altIsNotDispatchedOnAltTab() {
150− // Press alt, make sure it does *not* end up in inputCatcher (aka, the focused app)
151− inputCatcher.pressedKeys = [];
152− keyPress(Qt.Key_Alt, Qt.NoModifier)
153− compare(inputCatcher.pressedKeys.length, 0);
154− // Now also press tab. As this should trigger the spread, neither of them should end up in the app
155− keyPress(Qt.Key_Tab, Qt.NoModifier)
156− compare(inputCatcher.pressedKeys.length, 0);
157147
158− // Also the release events should not be dispatched to the app
148+ // Now release the keys, none of that should get to the app any more
159149 keyRelease(Qt.Key_Tab, Qt.NoModifier);
160150 keyRelease(Qt.Key_Alt, Qt.NoModifier);
161− compare(inputCatcher.pressedKeys.length, 0);
162− compare(inputCatcher.releasedKeys.length, 0);
151+ compare(inputCatcher.pressedKeys.length, 1);
152+ compare(inputCatcher.releasedKeys.length, 1);
163153 }
164154
165155 function test_altComboIsDispatched() {
166156 inputCatcher.pressedKeys = [];
167− // Press alt, make sure it does *not* yet end up in inputCatcher (aka, the focused app)
157+ // Press alt, make sure it does end up in inputCatcher (aka, the focused app)
168158 keyPress(Qt.Key_Alt, Qt.NoModifier)
169− compare(inputCatcher.pressedKeys.length, 0);
170− // Now press F in order to opening the File menu (Alt+F), now the app should get the full combo
159+ compare(inputCatcher.pressedKeys.length, 1);
160+ compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
161+ // Now press F in order to opening the File menu (Alt+F), make sure it is dispatched too
171162 keyPress(Qt.Key_F, Qt.NoModifier)
172163 compare(inputCatcher.pressedKeys.length, 2);
173164 compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);