@@ -54,11 +54,13 @@ Item {
5454
5555 onFocusedAppIdChanged: {
5656 print("focused appid changed", priv.focusedAppId)
57− var focusedApp = ApplicationManager.findApplication(focusedAppId);
58− if (focusedApp.stage == ApplicationInfoInterface.SideStage) {
59− priv.sideStageAppId = focusedAppId;
60− } else {
61− priv.mainStageAppId = focusedAppId;
57+ if (priv.focusedAppId.length > 0) {
58+ var focusedApp = ApplicationManager.findApplication(focusedAppId);
59+ if (focusedApp.stage == ApplicationInfoInterface.SideStage) {
60+ priv.sideStageAppId = focusedAppId;
61+ } else {
62+ priv.mainStageAppId = focusedAppId;
63+ }
6264 }
6365
6466 appId0 = ApplicationManager.count >= 1 ? ApplicationManager.get(0).appId : "";
@@ -156,7 +158,6 @@ Item {
156158 property real snapPosition: 0.75
157159
158160 property int selectedIndex: -1
159− onSelectedIndexChanged: print("selected index changed", selectedIndex)
160161 property int draggedIndex: -1
161162 property int closingIndex: -1
162163
@@ -198,7 +199,6 @@ Item {
198199
199200 }
200201 property int nextZInStack: indexToZIndex(nextInStack)
201− onNextInStackChanged: print("next in stack is", nextInStack)
202202
203203 states: [
204204 State {
@@ -272,7 +272,9 @@ Item {
272272 }
273273
274274 var isActive = app.appId == priv.mainStageAppId || app.appId == priv.sideStageAppId;
275− if (isActive && app.stage == ApplicationInfoInterface.MainStage) return 0;
275+ if (isActive && app.stage == ApplicationInfoInterface.MainStage) {
276+ return 0;
277+ }
276278 if (isActive && app.stage == ApplicationInfoInterface.SideStage) {
277279 if (!priv.mainStageAppId) {
278280 // only have SS apps running
@@ -438,6 +440,18 @@ Item {
438440 UbuntuNumberAnimation {}
439441 }
440442
443+ // This is required because none of the bindings are triggered in some cases:
444+ // When an app is closed, it might happen that ApplicationManager.get(nextInStack)
445+ // returns a different app even though the nextInStackIndex and all the related
446+ // bindings (index, mainStageApp, sideStageApp, etc) don't change. Let's force a
447+ // binding update in that case.
448+ Connections {
449+ target: ApplicationManager
450+ onApplicationRemoved: spreadTile.z = Qt.binding(function() {
451+ return spreadView.indexToZIndex(index)
452+ })
453+ }
454+
441455 progress: {
442456 var tileProgress = (spreadView.contentX - behavioredZIndex * spreadView.tileDistance) / spreadView.width;
443457 // Some tiles (nextInStack, active) need to move directly from the beginning, normalize progress to immediately start at 0