@@ -46,6 +46,7 @@ FocusScope {
4646 property int leftMargin: 0
4747 property bool oskEnabled: false
4848 property rect inputMethodRect
49+ property real rightEdgePushProgress: 0
4950
5051 // Configuration
5152 property string mode: "staged"
@@ -100,7 +101,9 @@ FocusScope {
100101 } else {
101102 // No we didn't, do a quick alt-tab
102103 if (appRepeater.count > 1) {
103− appRepeater.itemAt(1).claimFocus();
104+ appRepeater.itemAt(1).activate();
105+ } else if (appRepeater.count > 0) {
106+ appRepeater.itemAt(0).activate(); // quick alt-tab to the only (minimized) window should still activate it
104107 }
105108 }
106109 }
@@ -125,11 +128,6 @@ FocusScope {
125128 // functions to be called from outside
126129 function updateFocusedAppOrientation() { /* TODO */ }
127130 function updateFocusedAppOrientationAnimated() { /* TODO */}
128− function pushRightEdge(amount) {
129− if (root.spreadEnabled) {
130− edgeBarrier.push(amount);
131− }
132− }
133131
134132 function closeSpread() {
135133 priv.goneToSpread = false;
@@ -141,6 +139,12 @@ FocusScope {
141139 }
142140 }
143141
142+ onRightEdgePushProgressChanged: {
143+ if (spreadEnabled && rightEdgePushProgress >= 1) {
144+ priv.goneToSpread = true
145+ }
146+ }
147+
144148 GSettings {
145149 id: lifecycleExceptions
146150 schema.id: "com.canonical.qtmir"
@@ -452,7 +456,7 @@ FocusScope {
452456 PropertyChanges { target: wallpaper; visible: false }
453457 },
454458 State {
455− name: "stagedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "staged"
459+ name: "stagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "staged"
456460 PropertyChanges {
457461 target: blurLayer;
458462 visible: true;
@@ -462,7 +466,7 @@ FocusScope {
462466 }
463467 },
464468 State {
465− name: "sideStagedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "stagedWithSideStage"
469+ name: "sideStagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "stagedWithSideStage"
466470 extend: "stagedRightEdge"
467471 PropertyChanges {
468472 target: sideStage
@@ -471,18 +475,18 @@ FocusScope {
471475 }
472476 },
473477 State {
474− name: "windowedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "windowed"
478+ name: "windowedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "windowed"
475479 PropertyChanges {
476480 target: blurLayer;
477481 visible: true
478482 blurRadius: 32
479483 brightness: .65
480− opacity: MathUtils.linearAnimation(spreadItem.rightEdgeBreakPoint, 1, 0, 1, Math.max(rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0, edgeBarrier.progress))
484+ opacity: MathUtils.linearAnimation(spreadItem.rightEdgeBreakPoint, 1, 0, 1, Math.max(rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0, rightEdgePushProgress))
481485 }
482486 },
483487 State {
484488 name: "staged"; when: root.mode === "staged"
485− PropertyChanges { target: wallpaper; visible: false }
489+ PropertyChanges { target: wallpaper; visible: !priv.focusedAppDelegate || priv.focusedAppDelegate.x !== 0 }
486490 },
487491 State {
488492 name: "stagedWithSideStage"; when: root.mode === "stagedWithSideStage"
@@ -502,7 +506,6 @@ FocusScope {
502506 Transition {
503507 to: "spread"
504508 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
505− PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
506509 },
507510 Transition {
508511 from: "spread"
@@ -517,6 +520,7 @@ FocusScope {
517520 }
518521 }
519522 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
523+ PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
520524 }
521525 },
522526 Transition {
@@ -665,6 +669,13 @@ FocusScope {
665669 }
666670 }
667671
672+ Item {
673+ id: boundariesForWindowPlacement
674+ anchors.fill: parent
675+ anchors.topMargin: PanelState.panelHeight
676+ visible: false
677+ }
678+
668679 Repeater {
669680 id: appRepeater
670681 model: topLevelSurfaceList
@@ -804,7 +815,7 @@ FocusScope {
804815 maximizedTopLeft || maximizedTopRight || maximizedBottomLeft || maximizedBottomRight
805816
806817 readonly property bool minimized: windowState & WindowStateStorage.WindowStateMinimized
807− readonly property bool fullscreen: window.state === Mir.FullscreenState
818+ readonly property bool fullscreen: windowState === WindowStateStorage.WindowStateFullscreen
808819
809820 readonly property bool canBeMaximized: canBeMaximizedHorizontally && canBeMaximizedVertically
810821 readonly property bool canBeMaximizedLeftRight: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
@@ -815,7 +826,10 @@ FocusScope {
815826 readonly property bool canBeMaximizedVertically: maximumHeight == 0 || maximumHeight >= appContainer.height
816827 readonly property alias orientationChangesEnabled: decoratedWindow.orientationChangesEnabled
817828
829+ // TODO drop our own windowType once Mir/Miral/Qtmir gets in sync with ours
818830 property int windowState: WindowStateStorage.WindowStateNormal
831+ property int prevWindowState: WindowStateStorage.WindowStateRestored
832+
819833 property bool animationsEnabled: true
820834 property alias title: decoratedWindow.title
821835 readonly property string appName: model.application ? model.application.name : ""
@@ -833,7 +847,6 @@ FocusScope {
833847 readonly property var surface: model.window.surface
834848 readonly property var window: model.window
835849
836− readonly property alias resizeArea: resizeArea
837850 readonly property alias focusedSurface: decoratedWindow.focusedSurface
838851 readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
839852
@@ -871,9 +884,6 @@ FocusScope {
871884 }
872885 priv.updateMainAndSideStageIndexes();
873886 }
874− if (root.mode == "windowed") {
875− appDelegate.restore(true /* animated */, appDelegate.windowState);
876− }
877887 appDelegate.focus = true;
878888 }
879889
@@ -890,7 +900,7 @@ FocusScope {
890900 screenWidth: appContainer.width
891901 screenHeight: appContainer.height
892902 leftMargin: root.leftMargin
893− minimumY: PanelState.panelHeight
903+ minimumY: boundariesForWindowPlacement.y
894904 }
895905
896906 Connections {
@@ -923,7 +933,14 @@ FocusScope {
923933 } else if (model.window.state === Mir.MaximizedBottomRightState) {
924934 appDelegate.maximizeBottomRight();
925935 } else if (model.window.state === Mir.RestoredState) {
926− appDelegate.restore();
936+ if (appDelegate.fullscreen && appDelegate.prevWindowState != WindowStateStorage.WindowStateRestored) {
937+ model.window.requestState(WindowStateStorage.toMirState(appDelegate.prevWindowState));
938+ } else {
939+ appDelegate.restore();
940+ }
941+ } else if (model.window.state === Mir.FullscreenState) {
942+ appDelegate.prevWindowState = appDelegate.windowState;
943+ appDelegate.windowState = WindowStateStorage.WindowStateFullscreen;
927944 }
928945 }
929946 }
@@ -1025,6 +1042,7 @@ FocusScope {
10251042 animationsEnabled = (animated === undefined) || animated;
10261043 windowState = state || WindowStateStorage.WindowStateRestored;
10271044 windowState &= ~WindowStateStorage.WindowStateMinimized; // clear the minimized bit
1045+ prevWindowState = windowState;
10281046 }
10291047
10301048 function playFocusAnimation() {
@@ -1187,7 +1205,7 @@ FocusScope {
11871205 when: (root.mode == "staged" || root.mode == "stagedWithSideStage") && (root.state == "sideStagedRightEdge" || root.state == "stagedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running)
11881206 PropertyChanges {
11891207 target: stagedRightEdgeMaths
1190− progress: Math.max(edgeBarrier.progress, rightEdgeDragArea.draggedProgress)
1208+ progress: Math.max(rightEdgePushProgress, rightEdgeDragArea.draggedProgress)
11911209 }
11921210 PropertyChanges {
11931211 target: appDelegate
@@ -1214,11 +1232,11 @@ FocusScope {
12141232 },
12151233 State {
12161234 name: "windowedRightEdge"
1217− when: root.mode == "windowed" && (root.state == "windowedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running || edgeBarrier.progress > 0)
1235+ when: root.mode == "windowed" && (root.state == "windowedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running || rightEdgePushProgress > 0)
12181236 PropertyChanges {
12191237 target: windowedRightEdgeMaths
12201238 swipeProgress: rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0
1221− pushProgress: edgeBarrier.progress
1239+ pushProgress: rightEdgePushProgress
12221240 }
12231241 PropertyChanges {
12241242 target: appDelegate
@@ -1412,11 +1430,12 @@ FocusScope {
14121430 name: "minimized"; when: appDelegate.minimized
14131431 PropertyChanges {
14141432 target: appDelegate
1415− requestedX: -appDelegate.width / 2
14161433 scale: units.gu(5) / appDelegate.width
14171434 opacity: 0;
14181435 visuallyMinimized: true
14191436 visuallyMaximized: false
1437+ x: -appDelegate.width / 2
1438+ y: root.height / 2
14201439 }
14211440 }
14221441 ]
@@ -1432,15 +1451,6 @@ FocusScope {
14321451 to: "staged,stagedWithSideStage"
14331452 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,requestedWidth,requestedHeight"; duration: priv.animationDuration}
14341453 },
1435− Transition {
1436− to: "minimized"
1437− enabled: appDelegate.animationsEnabled
1438− PropertyAction { target: appDelegate; property: "visuallyMaximized" }
1439− SequentialAnimation {
1440− UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,opacity,scale,requestedWidth,requestedHeight" }
1441− PropertyAction { target: appDelegate; property: "visuallyMinimized" }
1442− }
1443− },
14441454 Transition {
14451455 to: "spread"
14461456 // DecoratedWindow wants the scaleToPreviewSize set before enabling scaleToPreview
@@ -1489,6 +1499,31 @@ FocusScope {
14891499 PropertyAction { target: appDelegate; property: "visible" }
14901500 }
14911501 },
1502+ Transition {
1503+ from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
1504+ to: "minimized"
1505+ SequentialAnimation {
1506+ ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
1507+ ScriptAction { script: { fakeRectangle.stop(); } }
1508+ PropertyAction { target: appDelegate; property: "visuallyMaximized" }
1509+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,scale,opacity"; duration: priv.animationDuration }
1510+ PropertyAction { target: appDelegate; property: "visuallyMinimized" }
1511+ }
1512+ },
1513+ Transition {
1514+ from: "minimized"
1515+ to: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
1516+ SequentialAnimation {
1517+ ScriptAction { script: print("transitioning:", appDelegate.x, appDelegate.y, appDelegate.scale) }
1518+ PropertyAction { target: appDelegate; property: "visuallyMinimized,z" }
1519+ ParallelAnimation {
1520+ UbuntuNumberAnimation { target: appDelegate; properties: "x"; from: -appDelegate.width / 2; duration: priv.animationDuration }
1521+ UbuntuNumberAnimation { target: appDelegate; properties: "y,opacity"; duration: priv.animationDuration }
1522+ UbuntuNumberAnimation { target: appDelegate; properties: "scale"; from: 0; duration: priv.animationDuration }
1523+ }
1524+ PropertyAction { target: appDelegate; property: "visuallyMaximized" }
1525+ }
1526+ },
14921527 Transition {
14931528 id: windowedTransition
14941529 from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen,minimized"
@@ -1520,7 +1555,7 @@ FocusScope {
15201555 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
15211556
15221557 target: appDelegate
1523− minimumY: PanelState.panelHeight // disallow resizing up past Panel
1558+ boundsItem: boundariesForWindowPlacement
15241559 minWidth: units.gu(10)
15251560 minHeight: units.gu(10)
15261561 borderThickness: units.gu(2)
@@ -1539,7 +1574,7 @@ FocusScope {
15391574 anchors.top: appDelegate.top
15401575 application: model.application
15411576 surface: model.window.surface
1542− active: appDelegate.focus
1577+ active: model.window.focused
15431578 focus: true
15441579 interactive: root.interactive
15451580 showDecoration: 1
@@ -1548,8 +1583,7 @@ FocusScope {
15481583 width: implicitWidth
15491584 height: implicitHeight
15501585 highlightSize: windowInfoItem.iconMargin / 2
1551− stageWidth: appContainer.width
1552− stageHeight: appContainer.height
1586+ boundsItem: boundariesForWindowPlacement
15531587
15541588 requestedWidth: appDelegate.requestedWidth
15551589 requestedHeight: appDelegate.requestedHeight
@@ -1581,7 +1615,10 @@ FocusScope {
15811615 onDecorationReleased: fakeRectangle.commit();
15821616
15831617 property real angle: 0
1618+ Behavior on angle { enabled: priv.closingIndex >= 0; UbuntuNumberAnimation {} }
15841619 property real itemScale: 1
1620+ Behavior on itemScale { enabled: priv.closingIndex >= 0; UbuntuNumberAnimation {} }
1621+
15851622 transform: [
15861623 Scale {
15871624 origin.x: 0
@@ -1604,11 +1641,12 @@ FocusScope {
16041641
16051642 WindowControlsOverlay {
16061643 id: touchControls
1644+ anchors.fill: appDelegate
16071645 target: appDelegate
1646+ resizeArea: resizeArea
16081647 enabled: false
16091648 visible: enabled
1610− stageWidth: appContainer.width
1611− stageHeight: appContainer.height
1649+ boundsItem: boundariesForWindowPlacement
16121650
16131651 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
16141652 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
@@ -1642,7 +1680,6 @@ FocusScope {
16421680 onClicked: {
16431681 spreadItem.highlightedIndex = index;
16441682 if (distance == 0) {
1645− model.window.activate();
16461683 priv.goneToSpread = false;
16471684 }
16481685 }
@@ -1703,6 +1740,41 @@ FocusScope {
17031740 sourceSize.height: height
17041741 }
17051742 }
1743+
1744+ Item {
1745+ // Group all child windows in this item so that we can fade them out together when going to the spread
1746+ // (and fade them in back again when returning from it)
1747+ readonly property bool stageOnProperState: root.state === "windowed"
1748+ || root.state === "staged"
1749+ || root.state === "stagedWithSideStage"
1750+
1751+ // TODO: Is it worth the extra cost of layering to avoid the opacity artifacts of intersecting children?
1752+ // Btw, will involve more than uncommenting the line below as children won't necessarily fit this item's
1753+ // geometry. This is just a reference.
1754+ //layer.enabled: opacity !== 0.0 && opacity !== 1.0
1755+
1756+ opacity: stageOnProperState ? 1.0 : 0.0
1757+ visible: opacity !== 0.0 // make it transparent to input as well
1758+ Behavior on opacity { UbuntuNumberAnimation {} }
1759+
1760+ Repeater {
1761+ id: childWindowRepeater
1762+ model: appDelegate.surface ? appDelegate.surface.childSurfaceList : null
1763+
1764+ delegate: ChildWindowTree {
1765+ surface: model.surface
1766+
1767+ // Account for the displacement caused by window decoration in the top-level surface
1768+ // Ie, the top-level surface is not positioned at (0,0) of this ChildWindow's parent (appDelegate)
1769+ displacementX: appDelegate.clientAreaItem.x
1770+ displacementY: appDelegate.clientAreaItem.y
1771+
1772+ boundsItem: boundariesForWindowPlacement
1773+
1774+ z: childWindowRepeater.count - model.index
1775+ }
1776+ }
1777+ }
17061778 }
17071779 }
17081780 }
@@ -1715,30 +1787,6 @@ FocusScope {
17151787 appContainerHeight: appContainer.height
17161788 }
17171789
1718− EdgeBarrier {
1719− id: edgeBarrier
1720−
1721− // NB: it does its own positioning according to the specified edge
1722− edge: Qt.RightEdge
1723−
1724− onPassed: priv.goneToSpread = true;
1725−
1726− material: Component {
1727− Item {
1728− Rectangle {
1729− width: parent.height
1730− height: parent.width
1731− rotation: 90
1732− anchors.centerIn: parent
1733− gradient: Gradient {
1734− GradientStop { position: 0.0; color: Qt.rgba(0.16,0.16,0.16,0.5)}
1735− GradientStop { position: 1.0; color: Qt.rgba(0.16,0.16,0.16,0)}
1736− }
1737− }
1738− }
1739− }
1740− }
1741−
17421790 MouseArea {
17431791 id: hoverMouseArea
17441792 objectName: "hoverMouseArea"
@@ -1805,11 +1853,11 @@ FocusScope {
18051853 var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
18061854 if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
18071855 var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
1808− snapAnimation.to = floatingFlickable.contentX - offset;
1856+ snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
18091857 snapAnimation.start();
18101858 } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
18111859 var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
1812− snapAnimation.to = floatingFlickable.contentX - offset;
1860+ snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
18131861 snapAnimation.start();
18141862 }
18151863 }