@@ -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,20 @@ FocusScope {
945946 }
946947 }
947948
949+ readonly property bool windowReady: clientAreaItem.surfaceInitialized
950+ property int requestedWindowState: Mir.RestoredState
951+ onWindowReadyChanged: {
952+ if (windowReady) {
953+ // need to apply the shell chrome policy on top the saved window state
954+ if (root.mode == "windowed") {
955+ requestedWindowState = windowedFullscreenPolicy.applyPolicy(requestedWindowState, surface.shellChrome);
956+ } else {
957+ requestedWindowState = stagedFullscreenPolicy.applyPolicy(requestedWindowState, surface.shellChrome);
958+ }
959+ window.requestState(requestedWindowState);
960+ }
961+ }
962+
948963 Component.onCompleted: {
949964 if (application && application.rotatesWindowContents) {
950965 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -956,8 +971,7 @@ FocusScope {
956971 windowedX = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedX + units.gu(3) : (normalZ - 1) * units.gu(3)
957972 windowedY = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedY + units.gu(3) : normalZ * units.gu(3)
958973 // Now load any saved state. This needs to happen *after* the cascading!
959− windowStateSaver.load();
960− model.window.requestState(WindowStateStorage.toMirState(windowState));
974+ requestedWindowState = WindowStateStorage.toMirState(windowStateSaver.load());
961975
962976 updateQmlFocusFromMirSurfaceFocus();
963977
@@ -965,7 +979,9 @@ FocusScope {
965979 _constructing = false;
966980 }
967981 Component.onDestruction: {
968− windowStateSaver.save();
982+ if (root.mode == "windowed") {
983+ windowStateSaver.save();
984+ }
969985
970986 if (!root.parent) {
971987 // This stage is about to be destroyed. Don't mess up with the model at this point
@@ -1441,7 +1457,7 @@ FocusScope {
14411457 ]
14421458 transitions: [
14431459 Transition {
1444− from: "staged,stagedWithSideStage"; to: "normal"
1460+ from: "staged,stagedWithSideStage"
14451461 enabled: appDelegate.animationsEnabled
14461462 PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
14471463 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,opacity,requestedWidth,requestedHeight,scale"; duration: priv.animationDuration }
@@ -1462,8 +1478,7 @@ FocusScope {
14621478 },
14631479 Transition {
14641480 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 }
1481+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedWidth,requestedHeight"; duration: priv.animationDuration }
14671482 },
14681483 Transition {
14691484 to: "windowedRightEdge"
@@ -1503,7 +1518,6 @@ FocusScope {
15031518 from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
15041519 to: "minimized"
15051520 SequentialAnimation {
1506− ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
15071521 ScriptAction { script: { fakeRectangle.stop(); } }
15081522 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
15091523 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,scale,opacity"; duration: priv.animationDuration }
@@ -1514,7 +1528,6 @@ FocusScope {
15141528 from: "minimized"
15151529 to: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
15161530 SequentialAnimation {
1517− ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
15181531 PropertyAction { target: appDelegate; property: "visuallyMinimized,z" }
15191532 ParallelAnimation {
15201533 UbuntuNumberAnimation { target: appDelegate; properties: "x"; from: -appDelegate.width / 2; duration: priv.animationDuration }
@@ -1661,8 +1674,6 @@ FocusScope {
16611674
16621675 WindowedFullscreenPolicy {
16631676 id: windowedFullscreenPolicy
1664− active: root.mode == "windowed"
1665− surface: model.window.surface
16661677 }
16671678 StagedFullscreenPolicy {
16681679 id: stagedFullscreenPolicy