@@ -71,6 +71,10 @@ Rectangle {
7171 priv.removeAndFocusPreviousInStack(appId);
7272 }
7373
74+ onFocusedApplicationIdChanged: {
75+ priv.addToFocusStack(priv.focusedAppId);
76+ }
77+
7478 onFocusRequested: {
7579 var appIndex = priv.indexOf(appId);
7680 var appDelegate = appRepeater.itemAt(appIndex);
@@ -94,7 +98,7 @@ Rectangle {
9498 }
9599 onFocusedAppDelegateChanged: { // restore the window from minimization when we focus it (e.g. using spread)
96100 if (priv.focusedAppDelegate && priv.focusedAppDelegate.minimized) {
97− priv.focusedAppDelegate.restore()
101+ priv.focusedAppDelegate.restore();
98102 }
99103 }
100104
@@ -107,12 +111,19 @@ Rectangle {
107111 return -1;
108112 }
109113
110− property var focusStack: []
114+ property var focusStack: [] // focus stack of appIds
111115
112116 function addToFocusStack(appId) {
113117 if (appId === "unity8-dash")
114118 return;
115− priv.focusStack.unshift(appId); // append to the top of the focus stack
119+
120+ var oldIndex = priv.focusStack.indexOf(appId);
121+ if (oldIndex != -1) {
122+ // remove the old item
123+ priv.focusStack.splice(oldIndex, 1);
124+ }
125+ // append to the top of the focus stack
126+ priv.focusStack.unshift(appId);
116127 }
117128
118129 function removeAndFocusPreviousInStack(appId) {