@@ -470,7 +470,7 @@ FocusScope {
470470 extend: "stagedRightEdge"
471471 PropertyChanges {
472472 target: sideStage
473− opacity: priv.sideStageDelegate.x === sideStage.x ? 1 : 0
473+ opacity: priv.sideStageDelegate && priv.sideStageDelegate.x === sideStage.x ? 1 : 0
474474 visible: true
475475 }
476476 },
@@ -723,6 +723,7 @@ FocusScope {
723723 // miral doesn't know about our window decorations. So we have to deduct them
724724 value: Qt.point(appDelegate.requestedX + appDelegate.clientAreaItem.x,
725725 appDelegate.requestedY + appDelegate.clientAreaItem.y)
726+ when: root.mode == "windowed"
726727 }
727728
728729 // In those are for windowed mode. Those values basically store the window's properties
@@ -768,7 +769,6 @@ FocusScope {
768769 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
769770 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
770771 && root.inputMethodRect.height > 0
771−
772772 }
773773
774774 Behavior on x { id: xBehavior; enabled: priv.closingIndex >= 0; UbuntuNumberAnimation { onRunningChanged: if (!running) priv.closingIndex = -1} }
@@ -933,7 +933,8 @@ FocusScope {
933933 } else if (model.window.state === Mir.MaximizedBottomRightState) {
934934 appDelegate.maximizeBottomRight();
935935 } else if (model.window.state === Mir.RestoredState) {
936− if (appDelegate.fullscreen && appDelegate.prevWindowState != WindowStateStorage.WindowStateRestored) {
936+ if (appDelegate.fullscreen && appDelegate.prevWindowState != WindowStateStorage.WindowStateRestored
937+ && appDelegate.prevWindowState != WindowStateStorage.WindowStateNormal) {
937938 model.window.requestState(WindowStateStorage.toMirState(appDelegate.prevWindowState));
938939 } else {
939940 appDelegate.restore();
@@ -945,6 +946,22 @@ FocusScope {
945946 }
946947 }
947948
949+ // queue the requests to change the window/surface state
950+ Timer {
951+ id: delayedStateTimer
952+ property int windowState: -1 // Mir::State
953+ interval: 1000
954+ onTriggered: {
955+ if (delayedStateTimer.windowState != -1) {
956+ if (windowedFullscreenPolicy.active) { // need to apply the windowed shell chrome policy on top the saved window state
957+ delayedStateTimer.windowState = windowedFullscreenPolicy.applyPolicy(delayedStateTimer.windowState, appDelegate.surface.shellChrome);
958+ }
959+ appDelegate.window.requestState(delayedStateTimer.windowState);
960+ delayedStateTimer.windowState = -1;
961+ }
962+ }
963+ }
964+
948965 Component.onCompleted: {
949966 if (application && application.rotatesWindowContents) {
950967 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -955,9 +972,12 @@ FocusScope {
955972 // First, cascade the newly created window, relative to the currently/old focused window.
956973 windowedX = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedX + units.gu(3) : (normalZ - 1) * units.gu(3)
957974 windowedY = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedY + units.gu(3) : normalZ * units.gu(3)
958− // Now load any saved state. This needs to happen *after* the cascading!
959− windowStateSaver.load();
960− model.window.requestState(WindowStateStorage.toMirState(windowState));
975+
976+ if (root.mode == "windowed") {
977+ // Now load any saved state. This needs to happen *after* the cascading!
978+ delayedStateTimer.windowState = WindowStateStorage.toMirState(windowStateSaver.load());
979+ delayedStateTimer.restart();
980+ }
961981
962982 updateQmlFocusFromMirSurfaceFocus();
963983
@@ -965,7 +985,9 @@ FocusScope {
965985 _constructing = false;
966986 }
967987 Component.onDestruction: {
968− windowStateSaver.save();
988+ if (root.mode == "windowed") {
989+ windowStateSaver.save();
990+ }
969991
970992 if (!root.parent) {
971993 // This stage is about to be destroyed. Don't mess up with the model at this point
@@ -1441,7 +1463,7 @@ FocusScope {
14411463 ]
14421464 transitions: [
14431465 Transition {
1444− from: "staged,stagedWithSideStage"; to: "normal"
1466+ from: "staged,stagedWithSideStage"
14451467 enabled: appDelegate.animationsEnabled
14461468 PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
14471469 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,opacity,requestedWidth,requestedHeight,scale"; duration: priv.animationDuration }
@@ -1462,8 +1484,7 @@ FocusScope {
14621484 },
14631485 Transition {
14641486 from: "normal,staged"; to: "stagedWithSideStage"
1465− UbuntuNumberAnimation { target: appDelegate; properties: "x,y"; duration: priv.animationDuration }
1466− UbuntuNumberAnimation { target: appDelegate; properties: "requestedWidth,requestedHeight"; duration: priv.animationDuration }
1487+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedWidth,requestedHeight"; duration: priv.animationDuration }
14671488 },
14681489 Transition {
14691490 to: "windowedRightEdge"
@@ -1503,7 +1524,6 @@ FocusScope {
15031524 from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
15041525 to: "minimized"
15051526 SequentialAnimation {
1506− ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
15071527 ScriptAction { script: { fakeRectangle.stop(); } }
15081528 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
15091529 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,scale,opacity"; duration: priv.animationDuration }
@@ -1514,7 +1534,6 @@ FocusScope {
15141534 from: "minimized"
15151535 to: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
15161536 SequentialAnimation {
1517− ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
15181537 PropertyAction { target: appDelegate; property: "visuallyMinimized,z" }
15191538 ParallelAnimation {
15201539 UbuntuNumberAnimation { target: appDelegate; properties: "x"; from: -appDelegate.width / 2; duration: priv.animationDuration }
@@ -1662,12 +1681,15 @@ FocusScope {
16621681 WindowedFullscreenPolicy {
16631682 id: windowedFullscreenPolicy
16641683 active: root.mode == "windowed"
1665− surface: model.window.surface
16661684 }
16671685 StagedFullscreenPolicy {
16681686 id: stagedFullscreenPolicy
16691687 active: root.mode == "staged" || root.mode == "stagedWithSideStage"
16701688 surface: model.window.surface
1689+ onStateRequested: {
1690+ delayedStateTimer.windowState = requestedState;
1691+ delayedStateTimer.restart();
1692+ }
16711693 }
16721694
16731695 SpreadDelegateInputArea {