@@ -263,32 +263,47 @@ Item {
263263
264264 var isActive = app.appId == priv.mainStageAppId || app.appId == priv.sideStageAppId;
265265 if (isActive && app.stage == ApplicationInfoInterface.MainStage) {
266+ // if this app is active, and its the MainStage, always put it to index 0
266267 return 0;
267268 }
268269 if (isActive && app.stage == ApplicationInfoInterface.SideStage) {
269270 if (!priv.mainStageAppId) {
270− // only have SS apps running
271+ // Only have SS apps running. Put the active one at 0
271272 return 0;
272273 }
273274
275+ // Precondition now: There's an active MS app and this is SS app:
274276 if (spreadView.nextInStack >= 0 && ApplicationManager.get(spreadView.nextInStack).stage == ApplicationInfoInterface.MainStage) {
277+ // If the next app coming from the right is a MS app, we need to elevate this SS ap above it.
278+ // Put it to at least level 2, or higher if there's more apps coming in before this one.
275279 return Math.max(index, 2);
276280 } else {
281+ // if this is no next app to come in from the right, place this one at index 1, just on top the active MS app.
277282 return 1;
278283 }
279284 }
280285 if (index <= 2 && app.stage == ApplicationInfoInterface.MainStage && priv.sideStageAppId) {
286+ // Ok, this is an inactive MS app. If there's an active SS app around, we need to place this one
287+ // in between the active MS app and the active SS app, so that it comes in from there when dragging from the right.
288+ // If there's now active SS app, just leave it where it is.
281289 return priv.indexOf(priv.sideStageAppId) < index ? index - 1 : index;
282290 }
283291 if (index == spreadView.nextInStack && app.stage == ApplicationInfoInterface.SideStage) {
292+ // This is a SS app and the next one to come in from the right:
284293 if (priv.sideStageAppId && priv.mainStageAppId) {
294+ // If there's both, an active MS and an active SS app, put this one right on top of that
285295 return 2;
286296 }
297+ // Or if there's only one other active app, put it on top of that.
298+ // The case that there isn't any other active app is already handled above.
287299 return 1;
288300 }
289301 if (index == 2 && spreadView.nextInStack == 1 && priv.sideStageAppId) {
302+ // If its index 2 but not the next one to come in, it means
303+ // we've pulled another one down to index 2. Move this one up to 2 instead.
290304 return 3;
291305 }
306+ // don't touch all others... (mostly index > 3 + simple cases where the above doesn't shuffle much)
292307 return index;
293308 }
294309