@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014-2016 Canonical, Ltd.
2+ * Copyright (C) 2014-2017 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@ import GlobalShortcut 1.0
2525import GSettings 1.0
2626import "Spread"
2727import "Spread/MathUtils.js" as MathUtils
28+import WindowManager 1.0
2829
2930FocusScope {
3031 id: root
@@ -43,10 +44,10 @@ FocusScope {
4344 property int shellOrientationAngle
4445 property bool spreadEnabled: true // If false, animations and right edge will be disabled
4546 property bool suspended
46− property int leftMargin: 0
4747 property bool oskEnabled: false
4848 property rect inputMethodRect
4949 property real rightEdgePushProgress: 0
50+ property Item availableDesktopArea
5051
5152 // Configuration
5253 property string mode: "staged"
@@ -120,6 +121,12 @@ FocusScope {
120121 }
121122 }
122123
124+ // For MirAL window management
125+ WindowMargins {
126+ normal: Qt.rect(0, root.mode === "windowed" ? priv.windowDecorationHeight : 0, 0, 0)
127+ dialog: normal
128+ }
129+
123130 property Item itemConfiningMouseCursor: !spreadShown && priv.focusedAppDelegate && priv.focusedAppDelegate.window.confinesMousePointer ?
124131 priv.focusedAppDelegate.clientAreaItem : null;
125132
@@ -367,6 +374,8 @@ FocusScope {
367374 }
368375
369376 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
377+
378+ readonly property real windowDecorationHeight: units.gu(3)
370379 }
371380
372381 Component.onCompleted: priv.updateMainAndSideStageIndexes();
@@ -587,7 +596,7 @@ FocusScope {
587596 id: spreadItem
588597 objectName: "spreadItem"
589598 anchors.fill: appContainer
590− leftMargin: root.leftMargin
599+ leftMargin: root.availableDesktopArea.x
591600 model: root.topLevelSurfaceList
592601 spreadFlickable: floatingFlickable
593602 z: 10
@@ -695,13 +704,6 @@ FocusScope {
695704 }
696705 }
697706
698− Item {
699− id: boundariesForWindowPlacement
700− anchors.fill: parent
701− anchors.topMargin: PanelState.panelHeight
702− visible: false
703− }
704−
705707 Repeater {
706708 id: appRepeater
707709 model: topLevelSurfaceList
@@ -799,7 +801,7 @@ FocusScope {
799801 target: appDelegate
800802 property: "y"
801803 value: appDelegate.requestedY -
802− Math.min(appDelegate.requestedY - PanelState.panelHeight,
804+ Math.min(appDelegate.requestedY - root.availableDesktopArea.y,
803805 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
804806 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
805807 && root.inputMethodRect.height > 0
@@ -817,8 +819,8 @@ FocusScope {
817819 angleDiff = (360 + angleDiff) % 360;
818820 if (angleDiff === 90 || angleDiff === 270) {
819821 var aux = decoratedWindow.requestedHeight;
820− decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.decorationHeight;
821− decoratedWindow.requestedWidth = aux - decoratedWindow.decorationHeight;
822+ decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.actualDecorationHeight;
823+ decoratedWindow.requestedWidth = aux - decoratedWindow.actualDecorationHeight;
822824 }
823825 }
824826 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -934,8 +936,8 @@ FocusScope {
934936 target: appDelegate
935937 screenWidth: appContainer.width
936938 screenHeight: appContainer.height
937− leftMargin: root.leftMargin
938− minimumY: boundariesForWindowPlacement.y
939+ leftMargin: root.availableDesktopArea.x
940+ minimumY: root.availableDesktopArea.y
939941 }
940942
941943 Connections {
@@ -1187,7 +1189,7 @@ FocusScope {
11871189
11881190 StagedRightEdgeMaths {
11891191 id: stagedRightEdgeMaths
1190− sceneWidth: appContainer.width - root.leftMargin
1192+ sceneWidth: root.availableDesktopArea.width
11911193 sceneHeight: appContainer.height
11921194 isMainStageApp: priv.mainStageDelegate == appDelegate
11931195 isSideStageApp: priv.sideStageDelegate == appDelegate
@@ -1198,7 +1200,7 @@ FocusScope {
11981200 progress: 0
11991201 targetHeight: spreadItem.stackHeight
12001202 targetX: spreadMaths.targetX
1201− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1203+ startY: appDelegate.fullscreen ? 0 : root.availableDesktopArea.y
12021204 targetY: spreadMaths.targetY
12031205 targetAngle: spreadMaths.targetAngle
12041206 targetScale: spreadMaths.targetScale
@@ -1319,9 +1321,9 @@ FocusScope {
13191321 PropertyChanges {
13201322 target: appDelegate
13211323 x: stageMaths.itemX
1322− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1324+ y: root.availableDesktopArea.y
13231325 requestedWidth: appContainer.width
1324− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1326+ requestedHeight: root.availableDesktopArea.height
13251327 visuallyMaximized: true
13261328 visible: appDelegate.x < root.width
13271329 }
@@ -1351,10 +1353,10 @@ FocusScope {
13511353 PropertyChanges {
13521354 target: appDelegate
13531355 x: stageMaths.itemX
1354− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1356+ y: root.availableDesktopArea.y
13551357 z: stageMaths.itemZ
13561358 requestedWidth: stageMaths.itemWidth
1357− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1359+ requestedHeight: root.availableDesktopArea.height
13581360 visuallyMaximized: true
13591361 visible: appDelegate.x < root.width
13601362 }
@@ -1375,11 +1377,11 @@ FocusScope {
13751377 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
13761378 PropertyChanges {
13771379 target: appDelegate;
1378− requestedX: root.leftMargin;
1380+ requestedX: root.availableDesktopArea.x;
13791381 requestedY: 0;
13801382 visuallyMinimized: false;
13811383 visuallyMaximized: true
1382− requestedWidth: appContainer.width - root.leftMargin;
1384+ requestedWidth: root.availableDesktopArea.width;
13831385 requestedHeight: appContainer.height;
13841386 }
13851387 PropertyChanges { target: touchControls; enabled: true }
@@ -1423,10 +1425,10 @@ FocusScope {
14231425 extend: "normal"
14241426 PropertyChanges {
14251427 target: appDelegate
1426− windowedX: root.leftMargin
1427− windowedY: PanelState.panelHeight
1428− windowedWidth: (appContainer.width - root.leftMargin)/2
1429− windowedHeight: appContainer.height - PanelState.panelHeight
1428+ windowedX: root.availableDesktopArea.x
1429+ windowedY: root.availableDesktopArea.y
1430+ windowedWidth: root.availableDesktopArea.width / 2
1431+ windowedHeight: root.availableDesktopArea.height
14301432 }
14311433 },
14321434 State {
@@ -1434,7 +1436,7 @@ FocusScope {
14341436 extend: "maximizedLeft"
14351437 PropertyChanges {
14361438 target: appDelegate;
1437− windowedX: (appContainer.width + root.leftMargin)/2
1439+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14381440 }
14391441 },
14401442 State {
@@ -1442,10 +1444,10 @@ FocusScope {
14421444 extend: "normal"
14431445 PropertyChanges {
14441446 target: appDelegate
1445− windowedX: root.leftMargin
1446− windowedY: PanelState.panelHeight
1447− windowedWidth: (appContainer.width - root.leftMargin)/2
1448− windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1447+ windowedX: root.availableDesktopArea.x
1448+ windowedY: root.availableDesktopArea.y
1449+ windowedWidth: root.availableDesktopArea.width / 2
1450+ windowedHeight: root.availableDesktopArea.height / 2
14491451 }
14501452 },
14511453 State {
@@ -1453,7 +1455,7 @@ FocusScope {
14531455 extend: "maximizedTopLeft"
14541456 PropertyChanges {
14551457 target: appDelegate
1456− windowedX: (appContainer.width + root.leftMargin)/2
1458+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14571459 }
14581460 },
14591461 State {
@@ -1461,10 +1463,10 @@ FocusScope {
14611463 extend: "normal"
14621464 PropertyChanges {
14631465 target: appDelegate
1464− windowedX: root.leftMargin
1465− windowedY: (appContainer.height + PanelState.panelHeight)/2
1466− windowedWidth: (appContainer.width - root.leftMargin)/2
1467− windowedHeight: appContainer.height/2
1466+ windowedX: root.availableDesktopArea.x
1467+ windowedY: root.availableDesktopArea.y + (root.availableDesktopArea.height / 2)
1468+ windowedWidth: root.availableDesktopArea.width / 2
1469+ windowedHeight: root.availableDesktopArea.height / 2
14681470 }
14691471 },
14701472 State {
@@ -1472,20 +1474,26 @@ FocusScope {
14721474 extend: "maximizedBottomLeft"
14731475 PropertyChanges {
14741476 target: appDelegate
1475− windowedX: (appContainer.width + root.leftMargin)/2
1477+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14761478 }
14771479 },
14781480 State {
14791481 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
14801482 extend: "normal"
1481− PropertyChanges { target: appDelegate; windowedX: root.leftMargin; windowedY: windowedY;
1482− windowedWidth: appContainer.width - root.leftMargin; windowedHeight: windowedHeight }
1483+ PropertyChanges {
1484+ target: appDelegate
1485+ windowedX: root.availableDesktopArea.x; windowedY: windowedY
1486+ windowedWidth: root.availableDesktopArea.width; windowedHeight: windowedHeight
1487+ }
14831488 },
14841489 State {
14851490 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
14861491 extend: "normal"
1487− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1488− windowedWidth: windowedWidth; windowedHeight: appContainer.height - PanelState.panelHeight }
1492+ PropertyChanges {
1493+ target: appDelegate
1494+ windowedX: windowedX; windowedY: root.availableDesktopArea.y
1495+ windowedWidth: windowedWidth; windowedHeight: root.availableDesktopArea.height
1496+ }
14891497 },
14901498 State {
14911499 name: "minimized"; when: appDelegate.minimized
@@ -1613,7 +1621,7 @@ FocusScope {
16131621 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
16141622
16151623 target: appDelegate
1616− boundsItem: boundariesForWindowPlacement
1624+ boundsItem: root.availableDesktopArea
16171625 minWidth: units.gu(10)
16181626 minHeight: units.gu(10)
16191627 borderThickness: units.gu(2)
@@ -1636,13 +1644,14 @@ FocusScope {
16361644 focus: true
16371645 interactive: root.interactive
16381646 showDecoration: 1
1647+ decorationHeight: priv.windowDecorationHeight
16391648 maximizeButtonShown: appDelegate.canBeMaximized
16401649 overlayShown: touchControls.overlayShown
16411650 width: implicitWidth
16421651 height: implicitHeight
16431652 highlightSize: windowInfoItem.iconMargin / 2
1644− boundsItem: boundariesForWindowPlacement
16451653 altDragEnabled: root.mode == "windowed"
1654+ boundsItem: root.availableDesktopArea
16461655
16471656 requestedWidth: appDelegate.requestedWidth
16481657 requestedHeight: appDelegate.requestedHeight
@@ -1705,7 +1714,7 @@ FocusScope {
17051714 resizeArea: resizeArea
17061715 enabled: false
17071716 visible: enabled
1708− boundsItem: boundariesForWindowPlacement
1717+ boundsItem: root.availableDesktopArea
17091718
17101719 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
17111720 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
@@ -1826,7 +1835,8 @@ FocusScope {
18261835 displacementX: appDelegate.clientAreaItem.x
18271836 displacementY: appDelegate.clientAreaItem.y
18281837
1829− boundsItem: boundariesForWindowPlacement
1838+ boundsItem: root.availableDesktopArea
1839+ decorationHeight: priv.windowDecorationHeight
18301840
18311841 z: childWindowRepeater.count - model.index
18321842
@@ -1847,7 +1857,7 @@ FocusScope {
18471857 FakeMaximizeDelegate {
18481858 id: fakeRectangle
18491859 target: priv.focusedAppDelegate
1850− leftMargin: root.leftMargin
1860+ leftMargin: root.availableDesktopArea.x
18511861 appContainerWidth: appContainer.width
18521862 appContainerHeight: appContainer.height
18531863 }