on xenial help sign in
merge prereq
9cbab18Michael Zanetti
qml/Stages/DesktopSpread.qml+1−1
@@ -87,7 +87,7 @@ FocusScope {
87 function focusSelected() {
87 function focusSelected() {
88 if (spreadRepeater.highlightedIndex != -1) {
88 if (spreadRepeater.highlightedIndex != -1) {
89 var application = ApplicationManager.get(spreadRepeater.highlightedIndex);
89 var application = ApplicationManager.get(spreadRepeater.highlightedIndex);
90− ApplicationManager.focusApplication(application.appId);
90+ ApplicationManager.requestFocusApplication(application.appId);
91 }
91 }
92 }
92 }
93
93
qml/Stages/DesktopStage.qml+45−61
@@ -68,21 +68,16 @@ Rectangle {
68 }
68 }
69
69
70 onApplicationRemoved: {
70 onApplicationRemoved: {
71− priv.removeAndFocusPreviousInStack(appId);
71+ priv.focusNext();
72− }
73−
74− onFocusedApplicationIdChanged: {
75− priv.addToFocusStack(priv.focusedAppId);
76 }
72 }
77
73
78 onFocusRequested: {
74 onFocusRequested: {
79 var appIndex = priv.indexOf(appId);
75 var appIndex = priv.indexOf(appId);
80 var appDelegate = appRepeater.itemAt(appIndex);
76 var appDelegate = appRepeater.itemAt(appIndex);
81− appDelegate.minimized = false;
77+ appDelegate.restoreFromMinimized();
82− ApplicationManager.focusApplication(appId)
83
78
84 if (spread.state == "altTab") {
79 if (spread.state == "altTab") {
85− spread.cancel()
80+ spread.cancel();
86 }
81 }
87 }
82 }
88 }
83 }
@@ -109,7 +104,7 @@ Rectangle {
109 GlobalShortcut {
104 GlobalShortcut {
110 id: maximizeWindowShortcut
105 id: maximizeWindowShortcut
111 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
106 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
112− onTriggered: priv.focusedAppDelegate.minimized ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.maximize()
107+ onTriggered: priv.focusedAppDelegate.maximize()
113 active: priv.focusedAppDelegate !== null
108 active: priv.focusedAppDelegate !== null
114 }
109 }
115
110
@@ -130,7 +125,8 @@ Rectangle {
130 GlobalShortcut {
125 GlobalShortcut {
131 id: minimizeRestoreShortcut
126 id: minimizeRestoreShortcut
132 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
127 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
128+ onTriggered: priv.focusedAppDelegate.maximized || priv.focusedAppDelegate.maximizedLeft || priv.focusedAppDelegate.maximizedRight
133− onTriggered: priv.focusedAppDelegate.maximized ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.minimize()
129+ ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.minimize(true)
134 active: priv.focusedAppDelegate !== null
130 active: priv.focusedAppDelegate !== null
135 }
131 }
136
132
@@ -142,11 +138,6 @@ Rectangle {
142 var index = indexOf(focusedAppId);
138 var index = indexOf(focusedAppId);
143 return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null
139 return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null
144 }
140 }
145− onFocusedAppDelegateChanged: { // restore the window from minimization when we focus it (e.g. using spread)
146− if (focusedAppDelegate && focusedAppDelegate.minimized) {
147− focusedAppDelegate.restore();
148− }
149− }
150
141
151 function indexOf(appId) {
142 function indexOf(appId) {
152 for (var i = 0; i < ApplicationManager.count; i++) {
143 for (var i = 0; i < ApplicationManager.count; i++) {
@@ -157,43 +148,26 @@ Rectangle {
157 return -1;
148 return -1;
158 }
149 }
159
150
160− property var focusStack: [] // focus stack of appIds
151+ function minimizeAllWindows() {
161−
152+ for (var i = 0; i < appRepeater.count; i++) {
162− function addToFocusStack(appId) {
153+ var appDelegate = appRepeater.itemAt(i);
163− var oldIndex = focusStack.indexOf(appId);
154+ if (appDelegate && !appDelegate.minimized) {
164− if (oldIndex != -1) {
155+ appDelegate.minimize(false); // minimize but don't switch focus
165− // remove the old item
156+ }
166− focusStack.splice(oldIndex, 1);
167− }
168− // insert to the top of the focus stack
169− focusStack.unshift(appId);
170− }
171−
172− function removeAndFocusPreviousInStack(appId) {
173− var removedIndex = focusStack.indexOf(appId);
174− if (removedIndex != -1) {
175− focusStack.splice(removedIndex, 1); // remove one item from the focus stack
176− focusFirstInStack(); // focus the first one
177 }
157 }
178− }
179
158
180− function focusFirstInStack() {
159+ ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
181− var newHead = focusStack[0];
182− if (newHead !== "") {
183− ApplicationManager.focusApplication(newHead);
184− }
185 }
160 }
186
161
187− function minimizeAllWindows() {
162+ function focusNext() {
188− focusStack.forEach(function(appId) {
163+ ApplicationManager.unfocusCurrentApplication();
164+ for (var i = 0; i < appRepeater.count; i++) {
189− var appDelegate = appRepeater.itemAt(indexOf(appId));
165+ var appDelegate = appRepeater.itemAt(i);
190 if (appDelegate && !appDelegate.minimized) {
166 if (appDelegate && !appDelegate.minimized) {
191− // we don't want to change the focus to a different window
167+ ApplicationManager.focusApplication(appDelegate.appId);
192− appDelegate.minimized = true;
168+ return;
193 }
169 }
194− });
170+ }
195− ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
196− focusStack = [];
197 }
171 }
198 }
172 }
199
173
@@ -202,7 +176,7 @@ Rectangle {
202 onClose: {
176 onClose: {
203 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
177 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
204 }
178 }
205− onMinimize: appRepeater.itemAt(0).minimize();
179+ onMinimize: appRepeater.itemAt(0).minimize(true);
206 onMaximize: appRepeater.itemAt(0).restore();
180 onMaximize: appRepeater.itemAt(0).restore();
207 }
181 }
208
182
@@ -294,11 +268,10 @@ Rectangle {
294 }
268 }
295 function minimize(animated) {
269 function minimize(animated) {
296 animationsEnabled = (animated === undefined) || animated;
270 animationsEnabled = (animated === undefined) || animated;
297− maximized = false;
298 minimized = true;
271 minimized = true;
299− maximizedLeft = false;
272+ if (!!animated) {
300− maximizedRight = false;
273+ priv.focusNext();
301− priv.removeAndFocusPreviousInStack(appId);
274+ }
302 }
275 }
303 function restore(animated) {
276 function restore(animated) {
304 animationsEnabled = (animated === undefined) || animated;
277 animationsEnabled = (animated === undefined) || animated;
@@ -306,7 +279,17 @@ Rectangle {
306 maximized = false;
279 maximized = false;
307 maximizedLeft = false;
280 maximizedLeft = false;
308 maximizedRight = false;
281 maximizedRight = false;
309− priv.addToFocusStack(appId);
282+ }
283+ function restoreFromMinimized(animated) {
284+ animationsEnabled = (animated === undefined) || animated;
285+ minimized = false;
286+ if (maximized)
287+ maximize();
288+ else if (maximizedLeft)
289+ maximizeLeft();
290+ else if (maximizedRight)
291+ maximizeRight();
292+ ApplicationManager.focusApplication(appId);
310 }
293 }
311
294
312 states: [
295 states: [
@@ -315,16 +298,16 @@ Rectangle {
315 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
298 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
316 },
299 },
317 State {
300 State {
318− name: "maximized"; when: appDelegate.maximized
301+ name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
319 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
302 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
320 },
303 },
321 State {
304 State {
322− name: "maximized_left"; when: appDelegate.maximizedLeft
305+ name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
323− PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height }
306+ PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height - units.gu(3) }
324 },
307 },
325 State {
308 State {
326− name: "maximized_right"; when: appDelegate.maximizedRight
309+ name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
327− PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height }
310+ PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height - units.gu(3) }
328 },
311 },
329 State {
312 State {
330 name: "minimized"; when: appDelegate.minimized
313 name: "minimized"; when: appDelegate.minimized
@@ -333,8 +316,8 @@ Rectangle {
333 ]
316 ]
334 transitions: [
317 transitions: [
335 Transition {
318 Transition {
336− from: "maximized,maximized_left,maximized_right,minimized,normal,"
319+ from: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
337− to: "maximized,maximized_left,maximized_right,minimized,normal,"
320+ to: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
338 enabled: appDelegate.animationsEnabled
321 enabled: appDelegate.animationsEnabled
339 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
322 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
340 },
323 },
@@ -384,8 +367,9 @@ Rectangle {
384 focus: true
367 focus: true
385
368
386 onClose: ApplicationManager.stopApplication(model.appId)
369 onClose: ApplicationManager.stopApplication(model.appId)
370+ onMaximize: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
387− onMaximize: appDelegate.maximized ? appDelegate.restore() : appDelegate.maximize()
371+ ? appDelegate.restore() : appDelegate.maximize()
388− onMinimize: appDelegate.minimize()
372+ onMinimize: appDelegate.minimize(true)
389 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
373 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
390 }
374 }
391 }
375 }
tests/qmltests/Stages/tst_DesktopStage.qml+12
@@ -305,5 +305,17 @@ Item {
305 verify(ApplicationManager.count == 2); // verify the app is gone
305 verify(ApplicationManager.count == 2); // verify the app is gone
306 verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
306 verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
307 }
307 }
308+
309+ function test_smashCursorKeys() {
310+ var apps = ["unity8-dash", "dialer-app", "camera-app"];
311+ apps.forEach(startApplication);
312+ verify(ApplicationManager.count == 3);
313+ keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
314+ tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
315+
316+ // now try pressing all 4 arrow keys + ctrl + meta
317+ keyClick(Qt.Key_Up | Qt.Key_Down | Qt.Key_Left | Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // smash it!!!
318+ tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify still no app is focused
319+ }
308 }
320 }
309}
321}