@@ -255,8 +255,8 @@ AbstractStage {
255255 focus: appId === priv.focusedAppId
256256 width: decoratedWindow.width
257257 height: decoratedWindow.height
258− property alias requestedWidth: decoratedWindow.requestedWidth
259− property alias requestedHeight: decoratedWindow.requestedHeight
258+ property int requestedWidth: -1
259+ property int requestedHeight: -1
260260 property alias minimumWidth: decoratedWindow.minimumWidth
261261 property alias minimumHeight: decoratedWindow.minimumHeight
262262 property alias maximumWidth: decoratedWindow.maximumWidth
@@ -369,8 +369,10 @@ AbstractStage {
369369 name: "fullscreen"; when: decoratedWindow.fullscreen
370370 PropertyChanges {
371371 target: appDelegate;
372− x: 0; y: -PanelState.panelHeight
373− requestedWidth: appContainer.width; requestedHeight: appContainer.height;
372+ x: 0;
373+ y: -PanelState.panelHeight
374+ requestedWidth: appContainer.width;
375+ requestedHeight: appContainer.height;
374376 }
375377 },
376378 State {
@@ -387,21 +389,42 @@ AbstractStage {
387389 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
388390 PropertyChanges {
389391 target: appDelegate;
390− x: root.leftMargin; y: 0;
391− requestedWidth: appContainer.width - root.leftMargin; requestedHeight: appContainer.height;
392+ x: root.leftMargin;
393+ y: 0;
392394 visuallyMinimized: false;
393395 visuallyMaximized: true
394396 }
397+ PropertyChanges {
398+ target: decoratedWindow
399+ requestedWidth: appContainer.width - root.leftMargin;
400+ requestedHeight: appContainer.height;
401+ }
395402 },
396403 State {
397404 name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
398− PropertyChanges { target: appDelegate; x: root.leftMargin; y: PanelState.panelHeight;
399− requestedWidth: (appContainer.width - root.leftMargin)/2; requestedHeight: appContainer.height - PanelState.panelHeight }
405+ PropertyChanges {
406+ target: appDelegate
407+ x: root.leftMargin
408+ y: PanelState.panelHeight
409+ }
410+ PropertyChanges {
411+ target: decoratedWindow
412+ requestedWidth: (appContainer.width - root.leftMargin)/2
413+ requestedHeight: appContainer.height - PanelState.panelHeight
414+ }
400415 },
401416 State {
402417 name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
403− PropertyChanges { target: appDelegate; x: (appContainer.width + root.leftMargin)/2; y: PanelState.panelHeight;
404− requestedWidth: (appContainer.width - root.leftMargin)/2; requestedHeight: appContainer.height - PanelState.panelHeight }
418+ PropertyChanges {
419+ target: appDelegate;
420+ x: (appContainer.width + root.leftMargin)/2
421+ y: PanelState.panelHeight
422+ }
423+ PropertyChanges {
424+ target: decoratedWindow
425+ requestedWidth: (appContainer.width - root.leftMargin)/2
426+ requestedHeight: appContainer.height - PanelState.panelHeight
427+ }
405428 },
406429 State {
407430 name: "minimized"; when: appDelegate.minimized
@@ -421,13 +444,17 @@ AbstractStage {
421444 enabled: appDelegate.animationsEnabled
422445 PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
423446 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,requestedWidth,requestedHeight,scale"; duration: UbuntuAnimation.FastDuration }
447+ UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
424448 },
425449 Transition {
426450 to: "minimized"
427451 enabled: appDelegate.animationsEnabled
428452 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
429453 SequentialAnimation {
430− UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,requestedWidth,requestedHeight,scale"; duration: UbuntuAnimation.FastDuration }
454+ ParallelAnimation {
455+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,scale"; duration: UbuntuAnimation.FastDuration }
456+ UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
457+ }
431458 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
432459 ScriptAction {
433460 script: {
@@ -443,7 +470,10 @@ AbstractStage {
443470 enabled: appDelegate.animationsEnabled
444471 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
445472 SequentialAnimation {
446− UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,requestedWidth,requestedHeight,scale"; duration: UbuntuAnimation.FastDuration }
473+ ParallelAnimation {
474+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,scale"; duration: UbuntuAnimation.FastDuration }
475+ UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
476+ }
447477 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
448478 }
449479 }
@@ -458,6 +488,7 @@ AbstractStage {
458488 }
459489
460490 WindowResizeArea {
491+ id: resizeArea
461492 objectName: "windowResizeArea"
462493 target: appDelegate
463494 minWidth: units.gu(10)
@@ -469,6 +500,25 @@ AbstractStage {
469500 leftMargin: root.leftMargin
470501
471502 onPressed: { ApplicationManager.focusApplication(model.appId) }
503+
504+ Component.onCompleted: {
505+ loadWindowState();
506+ }
507+
508+ property bool saveStateOnDestruction: true
509+ Connections {
510+ target: root
511+ onStageAboutToBeUnloaded: {
512+ resizeArea.saveWindowState();
513+ resizeArea.saveStateOnDestruction = false;
514+ fullscreenPolicy.active = false;
515+ }
516+ }
517+ Component.onDestruction: {
518+ if (saveStateOnDestruction) {
519+ saveWindowState();
520+ }
521+ }
472522 }
473523
474524 DecoratedWindow {
@@ -480,12 +530,21 @@ AbstractStage {
480530 active: ApplicationManager.focusedApplicationId === model.appId
481531 focus: true
482532
533+ requestedWidth: appDelegate.requestedWidth
534+ requestedHeight: appDelegate.requestedHeight
535+
483536 onClose: ApplicationManager.stopApplication(model.appId)
484537 onMaximize: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
485538 ? appDelegate.restoreFromMaximized() : appDelegate.maximize()
486539 onMinimize: appDelegate.minimize()
487540 onDecorationPressed: { ApplicationManager.focusApplication(model.appId) }
488541 }
542+
543+ WindowedFullscreenPolicy {
544+ id: fullscreenPolicy
545+ active: true
546+ application: decoratedWindow.application
547+ }
489548 }
490549 }
491550 }