on xenial help sign in
merge prereq
commit4ea940f86eacd2fd8d9558e444036cf9ebc361fd authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 2 Nov 2015, 23:11 (11 years ago) parent479b8b1961a4e5
3 files changed+58−62
qml/Stages/DesktopSpread.qml+1−1 qml/Stages/DesktopStage.qml+45−61 tests/qmltests/Stages/tst_DesktopStage.qml+12
qml/Stages/DesktopSpread.qml+1−1
@@ -87,7 +87,7 @@ FocusScope {
8787 function focusSelected() {
8888 if (spreadRepeater.highlightedIndex != -1) {
8989 var application = ApplicationManager.get(spreadRepeater.highlightedIndex);
90− ApplicationManager.focusApplication(application.appId);
90+ ApplicationManager.requestFocusApplication(application.appId);
9191 }
9292 }
9393
qml/Stages/DesktopStage.qml+45−61
@@ -68,21 +68,16 @@ Rectangle {
6868 }
6969
7070 onApplicationRemoved: {
71− priv.removeAndFocusPreviousInStack(appId);
72− }
73−
74− onFocusedApplicationIdChanged: {
75− priv.addToFocusStack(priv.focusedAppId);
71+ priv.focusNext();
7672 }
7773
7874 onFocusRequested: {
7975 var appIndex = priv.indexOf(appId);
8076 var appDelegate = appRepeater.itemAt(appIndex);
81− appDelegate.minimized = false;
82− ApplicationManager.focusApplication(appId)
77+ appDelegate.restoreFromMinimized();
8378
8479 if (spread.state == "altTab") {
85− spread.cancel()
80+ spread.cancel();
8681 }
8782 }
8883 }
@@ -109,7 +104,7 @@ Rectangle {
109104 GlobalShortcut {
110105 id: maximizeWindowShortcut
111106 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
112− onTriggered: priv.focusedAppDelegate.minimized ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.maximize()
107+ onTriggered: priv.focusedAppDelegate.maximize()
113108 active: priv.focusedAppDelegate !== null
114109 }
115110
@@ -130,7 +125,8 @@ Rectangle {
130125 GlobalShortcut {
131126 id: minimizeRestoreShortcut
132127 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
133− onTriggered: priv.focusedAppDelegate.maximized ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.minimize()
128+ onTriggered: priv.focusedAppDelegate.maximized || priv.focusedAppDelegate.maximizedLeft || priv.focusedAppDelegate.maximizedRight
129+ ? priv.focusedAppDelegate.restore() : priv.focusedAppDelegate.minimize(true)
134130 active: priv.focusedAppDelegate !== null
135131 }
136132
@@ -142,11 +138,6 @@ Rectangle {
142138 var index = indexOf(focusedAppId);
143139 return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null
144140 }
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− }
150141
151142 function indexOf(appId) {
152143 for (var i = 0; i < ApplicationManager.count; i++) {
@@ -157,43 +148,26 @@ Rectangle {
157148 return -1;
158149 }
159150
160− property var focusStack: [] // focus stack of appIds
161−
162− function addToFocusStack(appId) {
163− var oldIndex = focusStack.indexOf(appId);
164− if (oldIndex != -1) {
165− // remove the old item
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
151+ function minimizeAllWindows() {
152+ for (var i = 0; i < appRepeater.count; i++) {
153+ var appDelegate = appRepeater.itemAt(i);
154+ if (appDelegate && !appDelegate.minimized) {
155+ appDelegate.minimize(false); // minimize but don't switch focus
156+ }
177157 }
178− }
179158
180− function focusFirstInStack() {
181− var newHead = focusStack[0];
182− if (newHead !== "") {
183− ApplicationManager.focusApplication(newHead);
184− }
159+ ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
185160 }
186161
187− function minimizeAllWindows() {
188− focusStack.forEach(function(appId) {
189− var appDelegate = appRepeater.itemAt(indexOf(appId));
162+ function focusNext() {
163+ ApplicationManager.unfocusCurrentApplication();
164+ for (var i = 0; i < appRepeater.count; i++) {
165+ var appDelegate = appRepeater.itemAt(i);
190166 if (appDelegate && !appDelegate.minimized) {
191− // we don't want to change the focus to a different window
192− appDelegate.minimized = true;
167+ ApplicationManager.focusApplication(appDelegate.appId);
168+ return;
193169 }
194− });
195− ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
196− focusStack = [];
170+ }
197171 }
198172 }
199173
@@ -202,7 +176,7 @@ Rectangle {
202176 onClose: {
203177 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
204178 }
205− onMinimize: appRepeater.itemAt(0).minimize();
179+ onMinimize: appRepeater.itemAt(0).minimize(true);
206180 onMaximize: appRepeater.itemAt(0).restore();
207181 }
208182
@@ -294,11 +268,10 @@ Rectangle {
294268 }
295269 function minimize(animated) {
296270 animationsEnabled = (animated === undefined) || animated;
297− maximized = false;
298271 minimized = true;
299− maximizedLeft = false;
300− maximizedRight = false;
301− priv.removeAndFocusPreviousInStack(appId);
272+ if (!!animated) {
273+ priv.focusNext();
274+ }
302275 }
303276 function restore(animated) {
304277 animationsEnabled = (animated === undefined) || animated;
@@ -306,7 +279,17 @@ Rectangle {
306279 maximized = false;
307280 maximizedLeft = false;
308281 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);
310293 }
311294
312295 states: [
@@ -315,16 +298,16 @@ Rectangle {
315298 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
316299 },
317300 State {
318− name: "maximized"; when: appDelegate.maximized
301+ name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
319302 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
320303 },
321304 State {
322− name: "maximized_left"; when: appDelegate.maximizedLeft
323− PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height }
305+ name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
306+ PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height - units.gu(3) }
324307 },
325308 State {
326− name: "maximized_right"; when: appDelegate.maximizedRight
327− PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height }
309+ name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
310+ PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height - units.gu(3) }
328311 },
329312 State {
330313 name: "minimized"; when: appDelegate.minimized
@@ -333,8 +316,8 @@ Rectangle {
333316 ]
334317 transitions: [
335318 Transition {
336− from: "maximized,maximized_left,maximized_right,minimized,normal,"
337− to: "maximized,maximized_left,maximized_right,minimized,normal,"
319+ from: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
320+ to: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
338321 enabled: appDelegate.animationsEnabled
339322 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
340323 },
@@ -384,8 +367,9 @@ Rectangle {
384367 focus: true
385368
386369 onClose: ApplicationManager.stopApplication(model.appId)
387− onMaximize: appDelegate.maximized ? appDelegate.restore() : appDelegate.maximize()
388− onMinimize: appDelegate.minimize()
370+ onMaximize: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
371+ ? appDelegate.restore() : appDelegate.maximize()
372+ onMinimize: appDelegate.minimize(true)
389373 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
390374 }
391375 }
tests/qmltests/Stages/tst_DesktopStage.qml+12
@@ -305,5 +305,17 @@ Item {
305305 verify(ApplicationManager.count == 2); // verify the app is gone
306306 verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
307307 }
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+ }
308320 }
309321}