@@ -68,21 +68,16 @@ Rectangle {
70 onApplicationRemoved: {
70 onApplicationRemoved: {
71− priv.removeAndFocusPreviousInStack(appId);
71+ priv.focusNext();
74− onFocusedApplicationIdChanged: {
75− priv.addToFocusStack(priv.focusedAppId);
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)
84 if (spread.state == "altTab") {
79 if (spread.state == "altTab") {
85− spread.cancel()
80+ spread.cancel();
@@ -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.minimized ? priv.focusedAppDelegate.restoreFromMinimized() : priv.focusedAppDelegate.maximize()
113 active: priv.focusedAppDelegate !== null
108 active: priv.focusedAppDelegate !== null
@@ -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
@@ -157,43 +153,25 @@ Rectangle {
157 return -1;
153 return -1;
160− property var focusStack: [] // focus stack of appIds
156+ function minimizeAllWindows() {
161−
157+ for (var i = 0; i < appRepeater.count; i++) {
162− function addToFocusStack(appId) {
158+ var appDelegate = appRepeater.itemAt(i);
163− var oldIndex = focusStack.indexOf(appId);
159+ if (appDelegate && !appDelegate.minimized) {
164− if (oldIndex != -1) {
160+ appDelegate.minimize(false);
165− // remove the old item
161+ }
166− focusStack.splice(oldIndex, 1);
168− // insert to the top of the focus stack
169− focusStack.unshift(appId);
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
180− function focusFirstInStack() {
164+ ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
181− var newHead = focusStack[0];
182− if (newHead !== "") {
183− ApplicationManager.focusApplication(newHead);
187− function minimizeAllWindows() {
167+ function focusNext() {
188− focusStack.forEach(function(appId) {
168+ for (var i = 0; i < appRepeater.count; i++) {
189− var appDelegate = appRepeater.itemAt(indexOf(appId));
169+ var appDelegate = appRepeater.itemAt(i);
190 if (appDelegate && !appDelegate.minimized) {
170 if (appDelegate && !appDelegate.minimized) {
191− // we don't want to change the focus to a different window
171+ ApplicationManager.focusApplication(appDelegate.appId);
192− appDelegate.minimized = true;
172+ return;
195− ApplicationManager.unfocusCurrentApplication(); // no app should have focus at this point
@@ -202,7 +180,7 @@ Rectangle {
202 onClose: {
180 onClose: {
203 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
181 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
205− onMinimize: appRepeater.itemAt(0).minimize();
183+ onMinimize: appRepeater.itemAt(0).minimize(true);
206 onMaximize: appRepeater.itemAt(0).restore();
184 onMaximize: appRepeater.itemAt(0).restore();
@@ -294,11 +272,11 @@ Rectangle {
295 function minimize(animated) {
273 function minimize(animated) {
296 animationsEnabled = (animated === undefined) || animated;
274 animationsEnabled = (animated === undefined) || animated;
298 minimized = true;
275 minimized = true;
299− maximizedLeft = false;
276+ if (!!animated) {
300− maximizedRight = false;
277+ ApplicationManager.unfocusCurrentApplication();
301− priv.removeAndFocusPreviousInStack(appId);
278+ priv.focusNext();
303 function restore(animated) {
281 function restore(animated) {
304 animationsEnabled = (animated === undefined) || animated;
282 animationsEnabled = (animated === undefined) || animated;
@@ -306,7 +284,17 @@ Rectangle {
306 maximized = false;
284 maximized = false;
307 maximizedLeft = false;
285 maximizedLeft = false;
308 maximizedRight = false;
286 maximizedRight = false;
309− priv.addToFocusStack(appId);
287+ }
288+ function restoreFromMinimized(animated) {
289+ animationsEnabled = (animated === undefined) || animated;
293+ else if (maximizedLeft)
295+ else if (maximizedRight)
297+ ApplicationManager.focusApplication(appId);
312 states: [
300 states: [
@@ -315,15 +303,15 @@ Rectangle {
315 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
303 && !appDelegate.maximizedLeft && !appDelegate.maximizedRight
318− name: "maximized"; when: appDelegate.maximized
306+ name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
319 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
307 PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
322− name: "maximized_left"; when: appDelegate.maximizedLeft
310+ name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
323 PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height }
311 PropertyChanges { target: appDelegate; x: 0; y: units.gu(3); width: root.width/2; height: root.height }
326− name: "maximized_right"; when: appDelegate.maximizedRight
314+ 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 }
315 PropertyChanges { target: appDelegate; x: root.width/2; y: units.gu(3); width: root.width/2; height: root.height }
@@ -333,8 +321,8 @@ Rectangle {
334 transitions: [
322 transitions: [
335 Transition {
323 Transition {
336− from: "maximized,maximized_left,maximized_right,minimized,normal,"
324+ from: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
337− to: "maximized,maximized_left,maximized_right,minimized,normal,"
325+ to: "maximized,maximizedLeft,maximizedRight,minimized,normal,"
338 enabled: appDelegate.animationsEnabled
326 enabled: appDelegate.animationsEnabled
339 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
327 PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
@@ -382,8 +370,9 @@ Rectangle {
382 focus: true
370 focus: true
384 onClose: ApplicationManager.stopApplication(model.appId)
372 onClose: ApplicationManager.stopApplication(model.appId)
373+ onMaximize: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
385− onMaximize: appDelegate.maximized ? appDelegate.restore() : appDelegate.maximize()
374+ ? appDelegate.restore() : appDelegate.maximize()
386− onMinimize: appDelegate.minimize()
375+ onMinimize: appDelegate.minimize(true)
387 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
376 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }