@@ -45,6 +45,9 @@ AbstractStage {
4545 // Used by TutorialRight
4646 property bool spreadShown: spread.state == "altTab"
4747
48+ // used by the snap windows (edge maximize) feature
49+ readonly property alias previewRectangle: fakeRectangle
50+
4851 mainApp: priv.focusedAppDelegate ? priv.focusedAppDelegate.application : null
4952
5053 // application windows never rotate independently
@@ -73,28 +76,27 @@ AbstractStage {
7376 id: maximizeWindowShortcut
7477 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
7578 onTriggered: priv.focusedAppDelegate.maximize()
76− active: priv.focusedAppDelegate !== null
79+ active: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.canBeMaximized
7780 }
7881
7982 GlobalShortcut {
8083 id: maximizeWindowLeftShortcut
8184 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Left
8285 onTriggered: priv.focusedAppDelegate.maximizeLeft()
83− active: priv.focusedAppDelegate !== null
86+ active: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.canBeMaximizedLeftRight
8487 }
8588
8689 GlobalShortcut {
8790 id: maximizeWindowRightShortcut
8891 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Right
8992 onTriggered: priv.focusedAppDelegate.maximizeRight()
90− active: priv.focusedAppDelegate !== null
93+ active: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.canBeMaximizedLeftRight
9194 }
9295
9396 GlobalShortcut {
9497 id: minimizeRestoreShortcut
9598 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
96− onTriggered: priv.focusedAppDelegate.maximized || priv.focusedAppDelegate.maximizedLeft || priv.focusedAppDelegate.maximizedRight ||
97− priv.focusedAppDelegate.maximizedHorizontally || priv.focusedAppDelegate.maximizedVertically
99+ onTriggered: priv.focusedAppDelegate.anyMaximized
98100 ? priv.focusedAppDelegate.restoreFromMaximized() : priv.focusedAppDelegate.minimize()
99101 active: priv.focusedAppDelegate !== null
100102 }
@@ -170,11 +172,6 @@ AbstractStage {
170172 onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
171173 onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.minimize(); } }
172174 onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.restoreFromMaximized(); } }
173− onFocusMaximizedApp: {
174− if (priv.foregroundMaximizedAppDelegate) {
175− priv.foregroundMaximizedAppDelegate.focus = true;
176− }
177− }
178175 }
179176
180177 Binding {
@@ -279,7 +276,7 @@ AbstractStage {
279276 value: appDelegate.requestedY -
280277 Math.min(appDelegate.requestedY - PanelState.panelHeight,
281278 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
282− when: root.oskEnabled && appDelegate.focus && appDelegate.state == "normal"
279+ when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
283280 && SurfaceManager.inputMethodSurface
284281 && SurfaceManager.inputMethodSurface.state != Mir.HiddenState
285282 && SurfaceManager.inputMethodSurface.state != Mir.MinimizedState
@@ -294,7 +291,7 @@ AbstractStage {
294291 onShellOrientationAngleChanged: {
295292 // at this point decoratedWindow.surfaceOrientationAngle is the old shellOrientationAngle
296293 if (application && application.rotatesWindowContents) {
297− if (state == "normal") {
294+ if (state == "normal" || state == "restored") {
298295 var angleDiff = decoratedWindow.surfaceOrientationAngle - shellOrientationAngle;
299296 angleDiff = (360 + angleDiff) % 360;
300297 if (angleDiff === 90 || angleDiff === 270) {
@@ -320,14 +317,29 @@ AbstractStage {
320317 property int requestedWidth: -1
321318 property int requestedHeight: -1
322319
323− readonly property bool maximized: windowState & WindowStateStorage.WindowStateMaximized
324− readonly property bool maximizedLeft: windowState & WindowStateStorage.WindowStateMaximizedLeft
325− readonly property bool maximizedRight: windowState & WindowStateStorage.WindowStateMaximizedRight
326− readonly property bool maximizedHorizontally: windowState & WindowStateStorage.WindowStateMaximizedHorizontally
327− readonly property bool maximizedVertically: windowState & WindowStateStorage.WindowStateMaximizedVertically
320+ readonly property bool maximized: windowState === WindowStateStorage.WindowStateMaximized
321+ readonly property bool maximizedLeft: windowState === WindowStateStorage.WindowStateMaximizedLeft
322+ readonly property bool maximizedRight: windowState === WindowStateStorage.WindowStateMaximizedRight
323+ readonly property bool maximizedHorizontally: windowState === WindowStateStorage.WindowStateMaximizedHorizontally
324+ readonly property bool maximizedVertically: windowState === WindowStateStorage.WindowStateMaximizedVertically
325+ readonly property bool maximizedTopLeft: windowState === WindowStateStorage.WindowStateMaximizedTopLeft
326+ readonly property bool maximizedTopRight: windowState === WindowStateStorage.WindowStateMaximizedTopRight
327+ readonly property bool maximizedBottomLeft: windowState === WindowStateStorage.WindowStateMaximizedBottomLeft
328+ readonly property bool maximizedBottomRight: windowState === WindowStateStorage.WindowStateMaximizedBottomRight
329+ readonly property bool anyMaximized: maximized || maximizedLeft || maximizedRight || maximizedHorizontally || maximizedVertically ||
330+ maximizedTopLeft || maximizedTopRight || maximizedBottomLeft || maximizedBottomRight
331+
328332 readonly property bool minimized: windowState & WindowStateStorage.WindowStateMinimized
329333 readonly property alias fullscreen: decoratedWindow.fullscreen
330334
335+ readonly property bool canBeMaximized: canBeMaximizedHorizontally && canBeMaximizedVertically
336+ readonly property bool canBeMaximizedLeftRight: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
337+ (maximumHeight == 0 || maximumHeight >= appContainer.height)
338+ readonly property bool canBeCornerMaximized: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
339+ (maximumHeight == 0 || maximumHeight >= appContainer.height/2)
340+ readonly property bool canBeMaximizedHorizontally: maximumWidth == 0 || maximumWidth >= appContainer.width
341+ readonly property bool canBeMaximizedVertically: maximumHeight == 0 || maximumHeight >= appContainer.height
342+
331343 property int windowState: WindowStateStorage.WindowStateNormal
332344 property bool animationsEnabled: true
333345 property alias title: decoratedWindow.title
@@ -338,6 +350,7 @@ AbstractStage {
338350 readonly property var surface: model.surface
339351 readonly property alias resizeArea: resizeArea
340352 readonly property alias focusedSurface: decoratedWindow.focusedSurface
353+ readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
341354
342355 readonly property bool isDash: model.application.appId == "unity8-dash"
343356 readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
@@ -346,7 +359,7 @@ AbstractStage {
346359 if (spread.state == "altTab") {
347360 spread.cancel();
348361 }
349− appDelegate.restore();
362+ appDelegate.restore(true /* animated */, appDelegate.windowState);
350363 }
351364 Connections {
352365 target: model.surface
@@ -454,28 +467,34 @@ AbstractStage {
454467 animationsEnabled = (animated === undefined) || animated;
455468 windowState = WindowStateStorage.WindowStateMaximizedVertically;
456469 }
470+ function maximizeTopLeft(animated) {
471+ animationsEnabled = (animated === undefined) || animated;
472+ windowState = WindowStateStorage.WindowStateMaximizedTopLeft;
473+ }
474+ function maximizeTopRight(animated) {
475+ animationsEnabled = (animated === undefined) || animated;
476+ windowState = WindowStateStorage.WindowStateMaximizedTopRight;
477+ }
478+ function maximizeBottomLeft(animated) {
479+ animationsEnabled = (animated === undefined) || animated;
480+ windowState = WindowStateStorage.WindowStateMaximizedBottomLeft;
481+ }
482+ function maximizeBottomRight(animated) {
483+ animationsEnabled = (animated === undefined) || animated;
484+ windowState = WindowStateStorage.WindowStateMaximizedBottomRight;
485+ }
457486 function minimize(animated) {
458487 animationsEnabled = (animated === undefined) || animated;
459488 windowState |= WindowStateStorage.WindowStateMinimized; // add the minimized bit
460489 }
461490 function restoreFromMaximized(animated) {
462491 animationsEnabled = (animated === undefined) || animated;
463− windowState = WindowStateStorage.WindowStateNormal;
492+ windowState = WindowStateStorage.WindowStateRestored;
464493 }
465− function restore(animated) {
494+ function restore(animated,state) {
466495 animationsEnabled = (animated === undefined) || animated;
496+ windowState = state || WindowStateStorage.WindowStateRestored;
467497 windowState &= ~WindowStateStorage.WindowStateMinimized; // clear the minimized bit
468− if (maximized)
469− maximize();
470− else if (maximizedLeft)
471− maximizeLeft();
472− else if (maximizedRight)
473− maximizeRight();
474− else if (maximizedHorizontally)
475− maximizeHorizontally();
476− else if (maximizedVertically)
477− maximizeVertically();
478−
479498 focus = true;
480499 }
481500
@@ -492,9 +511,14 @@ AbstractStage {
492511 duration: UbuntuAnimation.SnapDuration
493512 }
494513
514+ // unlike requestedX/Y, this is the last known grab position before being pushed against edges/corners
515+ // when restoring, the window should return to these, not to the place where it was dropped near the edge
516+ property real restoredX
517+ property real restoredY
518+
495519 states: [
496520 State {
497− name: "fullscreen"; when: decoratedWindow.fullscreen && !appDelegate.minimized
521+ name: "fullscreen"; when: appDelegate.fullscreen && !appDelegate.minimized
498522 PropertyChanges {
499523 target: appDelegate;
500524 x: rotation == 0 ? 0 : (parent.width - width) / 2 + (shellOrientationAngle == 90 ? -PanelState.panelHeight : PanelState.panelHeight)
@@ -513,61 +537,94 @@ AbstractStage {
513537 }
514538 },
515539 State {
516− name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
540+ name: "restored";
541+ when: appDelegate.windowState == WindowStateStorage.WindowStateRestored
542+ extend: "normal"
517543 PropertyChanges {
518544 target: appDelegate;
519− x: root.leftMargin;
520− y: 0;
521− visuallyMinimized: false;
522− visuallyMaximized: true
545+ requestedX: restoredX;
546+ requestedY: restoredY;
523547 }
548+ },
549+ State {
550+ name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
524551 PropertyChanges {
525− target: decoratedWindow
552+ target: appDelegate;
553+ requestedX: root.leftMargin;
554+ requestedY: 0;
526555 requestedWidth: appContainer.width - root.leftMargin;
527556 requestedHeight: appContainer.height;
557+ visuallyMinimized: false;
558+ visuallyMaximized: true
528559 }
529560 },
530561 State {
531562 name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
532563 PropertyChanges {
533564 target: appDelegate
534− x: root.leftMargin
535− y: PanelState.panelHeight
536− }
537− PropertyChanges {
538− target: decoratedWindow
565+ requestedX: root.leftMargin
566+ requestedY: PanelState.panelHeight
539567 requestedWidth: (appContainer.width - root.leftMargin)/2
540568 requestedHeight: appContainer.height - PanelState.panelHeight
541569 }
542570 },
543571 State {
544572 name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
573+ extend: "maximizedLeft"
545574 PropertyChanges {
546575 target: appDelegate;
547− x: (appContainer.width + root.leftMargin)/2
548− y: PanelState.panelHeight
576+ requestedX: (appContainer.width + root.leftMargin)/2
549577 }
578+ },
579+ State {
580+ name: "maximizedTopLeft"; when: appDelegate.maximizedTopLeft && !appDelegate.minimized
550581 PropertyChanges {
551− target: decoratedWindow
582+ target: appDelegate
583+ requestedX: root.leftMargin
584+ requestedY: PanelState.panelHeight
552585 requestedWidth: (appContainer.width - root.leftMargin)/2
553− requestedHeight: appContainer.height - PanelState.panelHeight
586+ requestedHeight: (appContainer.height - PanelState.panelHeight)/2
587+ }
588+ },
589+ State {
590+ name: "maximizedTopRight"; when: appDelegate.maximizedTopRight && !appDelegate.minimized
591+ extend: "maximizedTopLeft"
592+ PropertyChanges {
593+ target: appDelegate
594+ requestedX: (appContainer.width + root.leftMargin)/2
595+ }
596+ },
597+ State {
598+ name: "maximizedBottomLeft"; when: appDelegate.maximizedBottomLeft && !appDelegate.minimized
599+ PropertyChanges {
600+ target: appDelegate
601+ requestedX: root.leftMargin
602+ requestedY: (appContainer.height + PanelState.panelHeight)/2
603+ requestedWidth: (appContainer.width - root.leftMargin)/2
604+ requestedHeight: appContainer.height/2
605+ }
606+ },
607+ State {
608+ name: "maximizedBottomRight"; when: appDelegate.maximizedBottomRight && !appDelegate.minimized
609+ extend: "maximizedBottomLeft"
610+ PropertyChanges {
611+ target: appDelegate
612+ requestedX: (appContainer.width + root.leftMargin)/2
554613 }
555614 },
556615 State {
557616 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
558− PropertyChanges { target: appDelegate; x: root.leftMargin }
559− PropertyChanges { target: decoratedWindow; requestedWidth: appContainer.width - root.leftMargin }
617+ PropertyChanges { target: appDelegate; requestedX: root.leftMargin; requestedY: requestedY; requestedWidth: appContainer.width - root.leftMargin }
560618 },
561619 State {
562620 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
563− PropertyChanges { target: appDelegate; y: PanelState.panelHeight }
564− PropertyChanges { target: decoratedWindow; requestedHeight: appContainer.height - PanelState.panelHeight }
621+ PropertyChanges { target: appDelegate; requestedX: requestedX; requestedY: PanelState.panelHeight; requestedHeight: appContainer.height - PanelState.panelHeight }
565622 },
566623 State {
567624 name: "minimized"; when: appDelegate.minimized
568625 PropertyChanges {
569626 target: appDelegate;
570− x: -appDelegate.width / 2;
627+ requestedX: -appDelegate.width / 2;
571628 scale: units.gu(5) / appDelegate.width;
572629 opacity: 0;
573630 visuallyMinimized: true;
@@ -577,21 +634,17 @@ AbstractStage {
577634 ]
578635 transitions: [
579636 Transition {
580− to: "normal"
637+ to: "normal,restored"
581638 enabled: appDelegate.animationsEnabled
582639 PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
583− UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,requestedWidth,requestedHeight,scale"; duration: UbuntuAnimation.FastDuration }
584− UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
640+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,opacity,scale,requestedWidth,requestedHeight" }
585641 },
586642 Transition {
587643 to: "minimized"
588644 enabled: appDelegate.animationsEnabled
589645 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
590646 SequentialAnimation {
591− ParallelAnimation {
592− UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,scale"; duration: UbuntuAnimation.FastDuration }
593− UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
594− }
647+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,opacity,scale,requestedWidth,requestedHeight" }
595648 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
596649 ScriptAction {
597650 script: {
@@ -608,11 +661,9 @@ AbstractStage {
608661 enabled: appDelegate.animationsEnabled
609662 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
610663 SequentialAnimation {
611− ParallelAnimation {
612− UbuntuNumberAnimation { target: appDelegate; properties: "x,y,opacity,scale"; duration: UbuntuAnimation.FastDuration }
613− UbuntuNumberAnimation { target: decoratedWindow; properties: "requestedWidth,requestedHeight"; duration: UbuntuAnimation.FastDuration }
614− }
664+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,opacity,scale,requestedWidth,requestedHeight" }
615665 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
666+ ScriptAction { script: { fakeRectangle.stop(); } }
616667 }
617668 }
618669 ]
@@ -678,27 +729,38 @@ AbstractStage {
678729 surface: model.surface
679730 active: appDelegate.focus
680731 focus: true
681− maximizeButtonShown: (maximumWidth == 0 || maximumWidth >= appContainer.width) &&
682− (maximumHeight == 0 || maximumHeight >= appContainer.height)
732+ maximizeButtonShown: appDelegate.canBeMaximized
683733 overlayShown: touchControls.overlayShown
734+ stageWidth: appContainer.width
735+ stageHeight: appContainer.height
684736
685737 requestedWidth: appDelegate.requestedWidth
686738 requestedHeight: appDelegate.requestedHeight
687739
688740 onCloseClicked: { appDelegate.close(); }
689− onMaximizeClicked: appDelegate.maximized || appDelegate.maximizedLeft || appDelegate.maximizedRight
690− || appDelegate.maximizedHorizontally || appDelegate.maximizedVertically
691− ? appDelegate.restoreFromMaximized() : appDelegate.maximize()
741+ onMaximizeClicked: appDelegate.anyMaximized ? appDelegate.restoreFromMaximized() : appDelegate.maximize();
692742 onMaximizeHorizontallyClicked: appDelegate.maximizedHorizontally ? appDelegate.restoreFromMaximized() : appDelegate.maximizeHorizontally()
693743 onMaximizeVerticallyClicked: appDelegate.maximizedVertically ? appDelegate.restoreFromMaximized() : appDelegate.maximizeVertically()
694744 onMinimizeClicked: appDelegate.minimize()
695745 onDecorationPressed: { appDelegate.focus = true; }
746+ onDecorationReleased: fakeRectangle.commit();
696747 }
697748
698749 WindowControlsOverlay {
699750 id: touchControls
700− anchors.fill: appDelegate
701751 target: appDelegate
752+ stageWidth: appContainer.width
753+ stageHeight: appContainer.height
754+
755+ onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
756+ onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
757+ onFakeMaximizeRightAnimationRequested: if (!appDelegate.maximizedRight) fakeRectangle.maximizeRight(amount, true)
758+ onFakeMaximizeTopLeftAnimationRequested: if (!appDelegate.maximizedTopLeft) fakeRectangle.maximizeTopLeft(amount, true);
759+ onFakeMaximizeTopRightAnimationRequested: if (!appDelegate.maximizedTopRight) fakeRectangle.maximizeTopRight(amount, true);
760+ onFakeMaximizeBottomLeftAnimationRequested: if (!appDelegate.maximizedBottomLeft) fakeRectangle.maximizeBottomLeft(amount, true);
761+ onFakeMaximizeBottomRightAnimationRequested: if (!appDelegate.maximizedBottomRight) fakeRectangle.maximizeBottomRight(amount, true);
762+ onStopFakeAnimation: fakeRectangle.stop();
763+ onDragReleased: fakeRectangle.commit();
702764 }
703765
704766 WindowedFullscreenPolicy {
@@ -710,6 +772,14 @@ AbstractStage {
710772 }
711773 }
712774
775+ FakeMaximizeDelegate {
776+ id: fakeRectangle
777+ target: priv.focusedAppDelegate
778+ leftMargin: root.leftMargin
779+ appContainerWidth: appContainer.width
780+ appContainerHeight: appContainer.height
781+ }
782+
713783 EdgeBarrier {
714784 id: edgeBarrier
715785