on xenial help sign in
send a Alt-release event on alt+tab instead of delaying it completely and invoking it later (LP: #1565236)
a56d659Michael Zanetti
qml/Components/PhysicalKeysMapper.qml+2−22
@@ -66,11 +66,6 @@ Item {
66 property bool superTabPressed: false
66 property bool superTabPressed: false
67
67
68 property var powerButtonPressStart: 0
68 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
74 }
69 }
75
70
76 InputEventGenerator {
71 InputEventGenerator {
@@ -78,12 +73,6 @@ Item {
78 }
73 }
79
74
80 function onKeyPressed(event, currentEventTimestamp) {
75 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−
87 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
76 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
88 if (event.isAutoRepeat) {
77 if (event.isAutoRepeat) {
89 if (d.powerButtonPressStart > 0
78 if (d.powerButtonPressStart > 0
@@ -119,12 +108,7 @@ Item {
119 d.volumeUpKeyPressed = true;
108 d.volumeUpKeyPressed = true;
120 }
109 }
121 } else if (event.key == Qt.Key_Alt || (root.controlInsteadOfAlt && event.key == Qt.Key_Control)) {
110 } 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;
111+ d.altPressed = true;
125− event.accepted = true;
126− d.altPressInjected = false;
127− }
128
112
129 // Adding MetaModifier here because that's what keyboards do. Pressing Super_L actually gives
113 // Adding MetaModifier here because that's what keyboards do. Pressing Super_L actually gives
130 // Super_L + MetaModifier. This helps to make sure we only invoke superPressed if no other
114 // Super_L + MetaModifier. This helps to make sure we only invoke superPressed if no other
@@ -135,6 +119,7 @@ Item {
135 d.superPressed = true;
119 d.superPressed = true;
136 } else if (event.key == Qt.Key_Tab) {
120 } else if (event.key == Qt.Key_Tab) {
137 if (d.altPressed && !d.altTabPressed) {
121 if (d.altPressed && !d.altTabPressed) {
122+ inputEventGenerator.generateKeyEvent(Qt.Key_Alt, false, Qt.NoModifier, currentEventTimestamp, 56);
138 d.altTabPressed = true;
123 d.altTabPressed = true;
139 event.accepted = true;
124 event.accepted = true;
140 }
125 }
@@ -161,11 +146,6 @@ Item {
161 if (d.altTabPressed) {
146 if (d.altTabPressed) {
162 d.altTabPressed = false;
147 d.altTabPressed = false;
163 event.accepted = true;
148 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;
169 }
149 }
170 d.altPressed = false;
150 d.altPressed = false;
171 } else if (event.key == Qt.Key_Tab) {
151 } else if (event.key == Qt.Key_Tab) {
tests/qmltests/Components/tst_PhysicalKeysMapper.qml+12−21
@@ -134,40 +134,31 @@ Item {
134 compare(screenshotSpy.count, 1);
134 compare(screenshotSpy.count, 1);
135 }
135 }
136
136
137− function test_altIsDispatchedOnRelease() {
137+ function test_altIsCancelledOnAltTab() {
138− // Press alt, make sure it does *not* end up in inputCatcher (aka, the focused app)
138+ // Press alt, make sure it does end up in inputCatcher (aka, the focused app)
139+ inputCatcher.pressedKeys = [];
139 keyPress(Qt.Key_Alt, Qt.NoModifier)
140 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);
143 compare(inputCatcher.pressedKeys.length, 1);
141 compare(inputCatcher.pressedKeys.length, 1);
144 compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
142 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)
145 compare(inputCatcher.releasedKeys.length, 1);
145 compare(inputCatcher.releasedKeys.length, 1);
146 compare(inputCatcher.releasedKeys[0], Qt.Key_Alt);
146 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);
157
147
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
159 keyRelease(Qt.Key_Tab, Qt.NoModifier);
149 keyRelease(Qt.Key_Tab, Qt.NoModifier);
160 keyRelease(Qt.Key_Alt, Qt.NoModifier);
150 keyRelease(Qt.Key_Alt, Qt.NoModifier);
161− compare(inputCatcher.pressedKeys.length, 0);
151+ compare(inputCatcher.pressedKeys.length, 1);
162− compare(inputCatcher.releasedKeys.length, 0);
152+ compare(inputCatcher.releasedKeys.length, 1);
163 }
153 }
164
154
165 function test_altComboIsDispatched() {
155 function test_altComboIsDispatched() {
166 inputCatcher.pressedKeys = [];
156 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)
168 keyPress(Qt.Key_Alt, Qt.NoModifier)
158 keyPress(Qt.Key_Alt, Qt.NoModifier)
169− compare(inputCatcher.pressedKeys.length, 0);
159+ compare(inputCatcher.pressedKeys.length, 1);
160+ compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
170− // Now press F in order to opening the File menu (Alt+F), now the app should get the full combo
161+ // Now press F in order to opening the File menu (Alt+F), make sure it is dispatched too
171 keyPress(Qt.Key_F, Qt.NoModifier)
162 keyPress(Qt.Key_F, Qt.NoModifier)
172 compare(inputCatcher.pressedKeys.length, 2);
163 compare(inputCatcher.pressedKeys.length, 2);
173 compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
164 compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);