@@ -63,17 +63,23 @@ Rectangle {
63 spread.state = "";
63 spread.state = "";
66− ApplicationManager.requestFocusApplication(appId)
66+ priv.addToFocusStack(appId);
67+ priv.focusFirstInStack();
70+ onApplicationRemoved: {
71+ priv.removeAndFocusPreviousInStack(appId);
69 onFocusRequested: {
74 onFocusRequested: {
70 var appIndex = priv.indexOf(appId);
75 var appIndex = priv.indexOf(appId);
71 var appDelegate = appRepeater.itemAt(appIndex);
76 var appDelegate = appRepeater.itemAt(appIndex);
72 appDelegate.minimized = false;
77 appDelegate.minimized = false;
73− ApplicationManager.focusApplication(appId)
78+ ApplicationManager.focusApplication(appId);
79+ priv.addToFocusStack(appId);
75 if (spread.state == "altTab") {
81 if (spread.state == "altTab") {
76− spread.cancel()
82+ spread.cancel();
@@ -88,7 +94,7 @@ Rectangle {
89 onFocusedAppDelegateChanged: { // restore the window from minimization when we focus it (e.g. using spread)
95 onFocusedAppDelegateChanged: { // restore the window from minimization when we focus it (e.g. using spread)
90 if (priv.focusedAppDelegate && priv.focusedAppDelegate.minimized) {
96 if (priv.focusedAppDelegate && priv.focusedAppDelegate.minimized) {
91− priv.focusedAppDelegate.unmaximize()
97+ priv.focusedAppDelegate.restore()
@@ -100,6 +106,35 @@ Rectangle {
101 return -1;
107 return -1;
110+ property var focusStack: []
112+ function addToFocusStack(appId) {
113+ if (appId === "unity8-dash")
115+ priv.focusStack.unshift(appId); // append to the top of the focus stack
118+ function removeAndFocusPreviousInStack(appId) {
119+ if (appId === "unity8-dash")
122+ var removedIndex = priv.focusStack.indexOf(appId);
123+ if (removedIndex != -1) {
124+ priv.focusStack.splice(removedIndex, 1); // remove one item from the focus stack
125+ if (removedIndex > 1)
126+ ApplicationManager.focusApplication(priv.focusStack[removedIndex-1]); // focus the previous one
128+ focusFirstInStack(); // focus the next/first one
132+ function focusFirstInStack() {
133+ var newHead = priv.focusStack[0];
134+ if (newHead !== "") {
135+ ApplicationManager.focusApplication(newHead);
105 Connections {
140 Connections {
@@ -108,7 +143,7 @@ Rectangle {
108 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
143 ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
110 onMinimize: appRepeater.itemAt(0).minimize();
145 onMinimize: appRepeater.itemAt(0).minimize();
111− onMaximize: appRepeater.itemAt(0).unmaximize();
146+ onMaximize: appRepeater.itemAt(0).restore();
114 Binding {
149 Binding {
@@ -170,10 +205,12 @@ Rectangle {
170 function minimize() {
205 function minimize() {
171 maximized = false;
206 maximized = false;
172 minimized = true;
207 minimized = true;
208+ priv.removeAndFocusPreviousInStack(model.appId);
174− function unmaximize() {
210+ function restore() {
175 minimized = false;
211 minimized = false;
176 maximized = false;
212 maximized = false;
213+ priv.addToFocusStack(model.appId);
179 states: [
216 states: [