@@ -180,7 +180,7 @@ AbstractStage {
180180
181181 for (var i = 0; i < spreadRepeater.count && (!choseMainStage || !choseSideStage); ++i) {
182182 var spreadDelegate = spreadRepeater.itemAt(i);
183− if (!spreadView.sideStageHidden && spreadDelegate.stage == ApplicationInfoInterface.SideStage
183+ if (sideStage.shown && spreadDelegate.stage == ApplicationInfoInterface.SideStage
184184 && !choseSideStage) {
185185 priv.sideStageDelegate = spreadDelegate
186186 priv.sideStageItemId = root.topLevelSurfaceList.idAt(i);
@@ -537,6 +537,7 @@ AbstractStage {
537537 if (!app) {
538538 return index;
539539 }
540+ var stage = spreadRepeater.itemAt(index) ? spreadRepeater.itemAt(index).stage : app.stage;
540541
541542 // don't shuffle indexes greater than "actives or next"
542543 if (index > 2) return index;
@@ -549,18 +550,18 @@ AbstractStage {
549550 }
550551
551552 if (spreadView.nextInStack > 0) {
552− var nextAppInStack = root.topLevelSurfaceList.applicationAt(spreadView.nextInStack);
553+ var stageOfNextInStack = spreadRepeater.itemAt(spreadView.nextInStack).stage;
553554
554555 if (index === spreadView.nextInStack) {
555556 // this is the next app in stack.
556557
557− if (app.stage === ApplicationInfoInterface.SideStage) {
558+ if (stage === ApplicationInfoInterface.SideStage) {
558559 // if the next app in stack is a sidestage app, it must order on top of other side stage app
559560 return Math.min(2, root.topLevelSurfaceList.count-1);
560561 }
561562 return 1;
562563 }
563− if (nextAppInStack.stage === ApplicationInfoInterface.SideStage) {
564+ if (stageOfNextInStack === ApplicationInfoInterface.SideStage) {
564565 // if the next app in stack is a sidestage app, it must order on top of other side stage app
565566 return 1;
566567 }
@@ -639,9 +640,9 @@ AbstractStage {
639640 if (!priv.mainStageItemId) return 0;
640641
641642 if (priv.sideStageItemId && spreadView.nextInStack > 0) {
642− var nextAppInStack = root.topLevelSurfaceList.applicationAt(spreadView.nextInStack);
643+ var nextDelegateInStack = spreadRepeater.itemAt(spreadView.nextInStack);
643644
644− if (nextAppInStack.stage === ApplicationInfoInterface.MainStage) {
645+ if (nextDelegateInStack.stage === ApplicationInfoInterface.MainStage) {
645646 // if the next app in stack is a main stage app, put the sidestage on top of it.
646647 return 2;
647648 }
@@ -944,10 +945,6 @@ AbstractStage {
944945 priv.sideStageEnabled && !sideStage.shown) {
945946 // Sidestage was focused, so show the side stage.
946947 sideStage.show();
947− // if we've switched to a main app which doesnt support portrait, hide the side stage.
948− } else if (priv.sideStageDelegate === spreadTile &&
949− mainApp && (mainApp.supportedOrientations & (Qt.PortraitOrientation|Qt.InvertedPortraitOrientation)) == 0) {
950− sideStage.hideNow();
951948 }
952949 }
953950 }