@@ -848,35 +848,13 @@ FocusScope {
848848 }
849849 }
850850
851− function loadWindowState() {
852− var defaultWidth = units.gu(60);
853− var defaultHeight = units.gu(50);
854− var windowGeometry = WindowStateStorage.getGeometry(appDelegate.appId,
855− Qt.rect(appDelegate.windowedX, appDelegate.windowedY, defaultWidth, defaultHeight));
856−
857− appDelegate.windowedWidth = Qt.binding(function() { return Math.min(Math.max(windowGeometry.width, appDelegate.minimumWidth), appContainer.width - root.leftMargin); });
858− appDelegate.windowedHeight = Qt.binding(function() { return Math.min(Math.max(windowGeometry.height, appDelegate.minimumHeight),
859− appContainer.height - (appDelegate.fullscreen ? 0 : PanelState.panelHeight)); });
860− appDelegate.windowedX = Qt.binding(function() { return Math.max(Math.min(windowGeometry.x, appContainer.width - root.leftMargin - appDelegate.windowedWidth),
861− (appDelegate.fullscreen ? 0 : root.leftMargin)); });
862− appDelegate.windowedY = Qt.binding(function() { return Math.max(Math.min(windowGeometry.y, appContainer.height - appDelegate.windowedHeight), PanelState.panelHeight); });
863−
864− var windowState = WindowStateStorage.getState(appDelegate.appId, WindowStateStorage.WindowStateNormal)
865− appDelegate.restore(false /* animated */, windowState);
866−
867− // initialize the x/y to restore to
868− appDelegate.restoredX = windowGeometry.x;
869− appDelegate.restoredY = windowGeometry.y;
870− }
871− function saveWindowState() {
872− var state = appDelegate.windowState;
873− if (state === WindowStateStorage.WindowStateRestored) {
874− state = WindowStateStorage.WindowStateNormal;
875− }
876−
877− WindowStateStorage.saveState(appDelegate.appId, state & ~WindowStateStorage.WindowStateMinimized); // clear the minimized bit when saving
878− WindowStateStorage.saveGeometry(appDelegate.appId, Qt.rect(appDelegate.windowedX, appDelegate.windowedY,
879− appDelegate.windowedWidth, appDelegate.windowedHeight));
851+ WindowStateSaver {
852+ id: windowStateSaver
853+ target: appDelegate
854+ screenWidth: appContainer.width
855+ screenHeight: appContainer.height
856+ leftMargin: root.leftMargin
857+ minimumY: PanelState.panelHeight
880858 }
881859
882860 Component.onCompleted: {
@@ -890,7 +868,7 @@ FocusScope {
890868 windowedX = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedX + units.gu(3) : (normalZ - 1) * units.gu(3)
891869 windowedY = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedY + units.gu(3) : normalZ * units.gu(3)
892870 // Now load any saved state. This needs to happen *after* the cascading!
893− loadWindowState();
871+ windowStateSaver.load();
894872 resizeArea.init();
895873
896874 // NB: We're differentiating if this delegate was created in response to a new entry in the model
@@ -908,7 +886,7 @@ FocusScope {
908886 _constructing = false;
909887 }
910888 Component.onDestruction: {
911− saveWindowState();
889+ windowStateSaver.save();
912890
913891 if (!root.parent) {
914892 // This stage is about to be destroyed. Don't mess up with the model at this point