on xenial help sign in
fix issues found by mzanetti

additionally properly restore windows from minimized state to the correct previous state (maximized, maximizedLeft/Right)

commit0e89812104d2b08bf88d319748049a09351739fb authorLukáš Tinkl <lukas.tinkl@canonical.com> dateFri 30 Oct 2015, 17:06 (11 years ago) parent5f3ec2e
1 file changed+43−54
qml/Stages/DesktopStage.qml+43−54
qml/Stages/DesktopStage.qml+43−54
@@ -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.minimized ? priv.focusedAppDelegate.restoreFromMinimized() : 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
@@ -157,43 +153,25 @@ Rectangle {
157153 return -1;
158154 }
159155
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
156+ function minimizeAllWindows() {
157+ for (var i = 0; i < appRepeater.count; i++) {
158+ var appDelegate = appRepeater.itemAt(i);
159+ if (appDelegate && !appDelegate.minimized) {
160+ appDelegate.minimize(false);
161+ }
177162 }
178− }
179163
180− function focusFirstInStack() {
181− var newHead = focusStack[0];
182− if (newHead !== "") {
183− ApplicationManager.focusApplication(newHead);
184− }
164+ ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
185165 }
186166
187− function minimizeAllWindows() {
188− focusStack.forEach(function(appId) {
189− var appDelegate = appRepeater.itemAt(indexOf(appId));
167+ function focusNext() {
168+ for (var i = 0; i < appRepeater.count; i++) {
169+ var appDelegate = appRepeater.itemAt(i);
190170 if (appDelegate && !appDelegate.minimized) {
191− // we don't want to change the focus to a different window
192− appDelegate.minimized = true;
171+ ApplicationManager.focusApplication(appDelegate.appId);
172+ return;
193173 }
194− });
195− ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
196− focusStack = [];
174+ }
197175 }
198176 }
199177
@@ -202,7 +180,7 @@ Rectangle {
202180 onClose: {
203181 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
204182 }
205− onMinimize: appRepeater.itemAt(0).minimize();
183+ onMinimize: appRepeater.itemAt(0).minimize(true);
206184 onMaximize: appRepeater.itemAt(0).restore();
207185 }
208186
@@ -294,11 +272,11 @@ Rectangle {
294272 }
295273 function minimize(animated) {
296274 animationsEnabled = (animated === undefined) || animated;
297− maximized = false;
298275 minimized = true;
299− maximizedLeft = false;
300− maximizedRight = false;
301− priv.removeAndFocusPreviousInStack(appId);
276+ if (!!animated) {
277+ ApplicationManager.unfocusCurrentApplication();
278+ priv.focusNext();
279+ }
302280 }
303281 function restore(animated) {
304282 animationsEnabled = (animated === undefined) || animated;
@@ -306,7 +284,17 @@ Rectangle {
306284 maximized = false;
307285 maximizedLeft = false;
308286 maximizedRight = false;
309− priv.addToFocusStack(appId);
287+ }
288+ function restoreFromMinimized(animated) {
289+ animationsEnabled = (animated === undefined) || animated;
290+ minimized = false;
291+ if (maximized)
292+ maximize();
293+ else if (maximizedLeft)
294+ maximizeLeft();
295+ else if (maximizedRight)
296+ maximizeRight();
297+ ApplicationManager.focusApplication(appId);
310298 }
311299
312300 states: [
@@ -315,15 +303,15 @@ Rectangle {
315303 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
316304 },
317305 State {
318− name: "maximized"; when: appDelegate.maximized
306+ name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
319307 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
320308 },
321309 State {
322− name: "maximized_left"; when: appDelegate.maximizedLeft
310+ name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
323311 PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height }
324312 },
325313 State {
326− name: "maximized_right"; when: appDelegate.maximizedRight
314+ name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
327315 PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height }
328316 },
329317 State {
@@ -333,8 +321,8 @@ Rectangle {
333321 ]
334322 transitions: [
335323 Transition {
336− from: "maximized,maximized_left,maximized_right,minimized,normal,"
337− to: "maximized,maximized_left,maximized_right,minimized,normal,"
324+ from: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
325+ to: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
338326 enabled: appDelegate.animationsEnabled
339327 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
340328 },
@@ -382,8 +370,9 @@ Rectangle {
382370 focus: true
383371
384372 onClose: ApplicationManager.stopApplication(model.appId)
385− onMaximize: appDelegate.maximized ? appDelegate.restore() : appDelegate.maximize()
386− onMinimize: appDelegate.minimize()
373+ onMaximize: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
374+ ? appDelegate.restore() : appDelegate.maximize()
375+ onMinimize: appDelegate.minimize(true)
387376 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
388377 }
389378 }