@@ -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
@@ -224,10 +231,30 @@ FocusScope {
224231 active: priv.focusedAppDelegate !== null
225232 }
226233
234+ GlobalShortcut {
235+ shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_T
236+ onTriggered: {
237+ // try in this order: snap pkg, new deb name, old deb name
238+ var candidates = ["ubuntu-terminal-app_ubuntu-terminal-app", "ubuntu-terminal-app", "com.ubuntu.terminal"];
239+ for (var i = 0; i < candidates.length; i++) {
240+ if (priv.startApp(candidates[i]))
241+ break;
242+ }
243+ }
244+ }
245+
227246 QtObject {
228247 id: priv
229248 objectName: "DesktopStagePrivate"
230249
250+ function startApp(appId) {
251+ if (root.applicationManager.findApplication(appId)) {
252+ return root.applicationManager.requestFocusApplication(appId);
253+ } else {
254+ return root.applicationManager.startApplication(appId) !== null;
255+ }
256+ }
257+
231258 property var focusedAppDelegate: null
232259 property var foregroundMaximizedAppDelegate: null // for stuff like drop shadow and focusing maximized app by clicking panel
233260
@@ -347,6 +374,8 @@ FocusScope {
347374 }
348375
349376 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
377+
378+ readonly property real windowDecorationHeight: units.gu(3)
350379 }
351380
352381 Component.onCompleted: priv.updateMainAndSideStageIndexes();
@@ -567,7 +596,7 @@ FocusScope {
567596 id: spreadItem
568597 objectName: "spreadItem"
569598 anchors.fill: appContainer
570− leftMargin: root.leftMargin
599+ leftMargin: root.availableDesktopArea.x
571600 model: root.topLevelSurfaceList
572601 spreadFlickable: floatingFlickable
573602 z: 10
@@ -675,13 +704,6 @@ FocusScope {
675704 }
676705 }
677706
678− Item {
679− id: boundariesForWindowPlacement
680− anchors.fill: parent
681− anchors.topMargin: PanelState.panelHeight
682− visible: false
683− }
684−
685707 Repeater {
686708 id: appRepeater
687709 model: topLevelSurfaceList
@@ -779,7 +801,7 @@ FocusScope {
779801 target: appDelegate
780802 property: "y"
781803 value: appDelegate.requestedY -
782− Math.min(appDelegate.requestedY - PanelState.panelHeight,
804+ Math.min(appDelegate.requestedY - root.availableDesktopArea.y,
783805 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
784806 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
785807 && root.inputMethodRect.height > 0
@@ -797,8 +819,8 @@ FocusScope {
797819 angleDiff = (360 + angleDiff) % 360;
798820 if (angleDiff === 90 || angleDiff === 270) {
799821 var aux = decoratedWindow.requestedHeight;
800− decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.decorationHeight;
801− decoratedWindow.requestedWidth = aux - decoratedWindow.decorationHeight;
822+ decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.actualDecorationHeight;
823+ decoratedWindow.requestedWidth = aux - decoratedWindow.actualDecorationHeight;
802824 }
803825 }
804826 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -914,8 +936,8 @@ FocusScope {
914936 target: appDelegate
915937 screenWidth: appContainer.width
916938 screenHeight: appContainer.height
917− leftMargin: root.leftMargin
918− minimumY: boundariesForWindowPlacement.y
939+ leftMargin: root.availableDesktopArea.x
940+ minimumY: root.availableDesktopArea.y
919941 }
920942
921943 Connections {
@@ -1167,7 +1189,7 @@ FocusScope {
11671189
11681190 StagedRightEdgeMaths {
11691191 id: stagedRightEdgeMaths
1170− sceneWidth: appContainer.width - root.leftMargin
1192+ sceneWidth: root.availableDesktopArea.width
11711193 sceneHeight: appContainer.height
11721194 isMainStageApp: priv.mainStageDelegate == appDelegate
11731195 isSideStageApp: priv.sideStageDelegate == appDelegate
@@ -1178,7 +1200,7 @@ FocusScope {
11781200 progress: 0
11791201 targetHeight: spreadItem.stackHeight
11801202 targetX: spreadMaths.targetX
1181− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1203+ startY: appDelegate.fullscreen ? 0 : root.availableDesktopArea.y
11821204 targetY: spreadMaths.targetY
11831205 targetAngle: spreadMaths.targetAngle
11841206 targetScale: spreadMaths.targetScale
@@ -1299,9 +1321,9 @@ FocusScope {
12991321 PropertyChanges {
13001322 target: appDelegate
13011323 x: stageMaths.itemX
1302− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1324+ y: root.availableDesktopArea.y
13031325 requestedWidth: appContainer.width
1304− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1326+ requestedHeight: root.availableDesktopArea.height
13051327 visuallyMaximized: true
13061328 visible: appDelegate.x < root.width
13071329 }
@@ -1331,10 +1353,10 @@ FocusScope {
13311353 PropertyChanges {
13321354 target: appDelegate
13331355 x: stageMaths.itemX
1334− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1356+ y: root.availableDesktopArea.y
13351357 z: stageMaths.itemZ
13361358 requestedWidth: stageMaths.itemWidth
1337− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1359+ requestedHeight: root.availableDesktopArea.height
13381360 visuallyMaximized: true
13391361 visible: appDelegate.x < root.width
13401362 }
@@ -1355,11 +1377,11 @@ FocusScope {
13551377 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
13561378 PropertyChanges {
13571379 target: appDelegate;
1358− requestedX: root.leftMargin;
1380+ requestedX: root.availableDesktopArea.x;
13591381 requestedY: 0;
13601382 visuallyMinimized: false;
13611383 visuallyMaximized: true
1362− requestedWidth: appContainer.width - root.leftMargin;
1384+ requestedWidth: root.availableDesktopArea.width;
13631385 requestedHeight: appContainer.height;
13641386 }
13651387 PropertyChanges { target: touchControls; enabled: true }
@@ -1392,6 +1414,7 @@ FocusScope {
13921414 when: appDelegate.windowState == WindowStateStorage.WindowStateRestored
13931415 extend: "normal"
13941416 PropertyChanges {
1417+ restoreEntryValues: false
13951418 target: appDelegate;
13961419 windowedX: restoredX;
13971420 windowedY: restoredY;
@@ -1402,10 +1425,10 @@ FocusScope {
14021425 extend: "normal"
14031426 PropertyChanges {
14041427 target: appDelegate
1405− windowedX: root.leftMargin
1406− windowedY: PanelState.panelHeight
1407− windowedWidth: (appContainer.width - root.leftMargin)/2
1408− 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
14091432 }
14101433 },
14111434 State {
@@ -1413,7 +1436,7 @@ FocusScope {
14131436 extend: "maximizedLeft"
14141437 PropertyChanges {
14151438 target: appDelegate;
1416− windowedX: (appContainer.width + root.leftMargin)/2
1439+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14171440 }
14181441 },
14191442 State {
@@ -1421,10 +1444,10 @@ FocusScope {
14211444 extend: "normal"
14221445 PropertyChanges {
14231446 target: appDelegate
1424− windowedX: root.leftMargin
1425− windowedY: PanelState.panelHeight
1426− windowedWidth: (appContainer.width - root.leftMargin)/2
1427− 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
14281451 }
14291452 },
14301453 State {
@@ -1432,7 +1455,7 @@ FocusScope {
14321455 extend: "maximizedTopLeft"
14331456 PropertyChanges {
14341457 target: appDelegate
1435− windowedX: (appContainer.width + root.leftMargin)/2
1458+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14361459 }
14371460 },
14381461 State {
@@ -1440,10 +1463,10 @@ FocusScope {
14401463 extend: "normal"
14411464 PropertyChanges {
14421465 target: appDelegate
1443− windowedX: root.leftMargin
1444− windowedY: (appContainer.height + PanelState.panelHeight)/2
1445− windowedWidth: (appContainer.width - root.leftMargin)/2
1446− 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
14471470 }
14481471 },
14491472 State {
@@ -1451,20 +1474,26 @@ FocusScope {
14511474 extend: "maximizedBottomLeft"
14521475 PropertyChanges {
14531476 target: appDelegate
1454− windowedX: (appContainer.width + root.leftMargin)/2
1477+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14551478 }
14561479 },
14571480 State {
14581481 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
14591482 extend: "normal"
1460− PropertyChanges { target: appDelegate; windowedX: root.leftMargin; windowedY: windowedY;
1461− 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+ }
14621488 },
14631489 State {
14641490 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
14651491 extend: "normal"
1466− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1467− 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+ }
14681497 },
14691498 State {
14701499 name: "minimized"; when: appDelegate.minimized
@@ -1592,7 +1621,7 @@ FocusScope {
15921621 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
15931622
15941623 target: appDelegate
1595− boundsItem: boundariesForWindowPlacement
1624+ boundsItem: root.availableDesktopArea
15961625 minWidth: units.gu(10)
15971626 minHeight: units.gu(10)
15981627 borderThickness: units.gu(2)
@@ -1615,13 +1644,14 @@ FocusScope {
16151644 focus: true
16161645 interactive: root.interactive
16171646 showDecoration: 1
1647+ decorationHeight: priv.windowDecorationHeight
16181648 maximizeButtonShown: appDelegate.canBeMaximized
16191649 overlayShown: touchControls.overlayShown
16201650 width: implicitWidth
16211651 height: implicitHeight
16221652 highlightSize: windowInfoItem.iconMargin / 2
1623− boundsItem: boundariesForWindowPlacement
16241653 altDragEnabled: root.mode == "windowed"
1654+ boundsItem: root.availableDesktopArea
16251655
16261656 requestedWidth: appDelegate.requestedWidth
16271657 requestedHeight: appDelegate.requestedHeight
@@ -1684,7 +1714,7 @@ FocusScope {
16841714 resizeArea: resizeArea
16851715 enabled: false
16861716 visible: enabled
1687− boundsItem: boundariesForWindowPlacement
1717+ boundsItem: root.availableDesktopArea
16881718
16891719 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
16901720 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
@@ -1805,7 +1835,8 @@ FocusScope {
18051835 displacementX: appDelegate.clientAreaItem.x
18061836 displacementY: appDelegate.clientAreaItem.y
18071837
1808− boundsItem: boundariesForWindowPlacement
1838+ boundsItem: root.availableDesktopArea
1839+ decorationHeight: priv.windowDecorationHeight
18091840
18101841 z: childWindowRepeater.count - model.index
18111842
@@ -1826,7 +1857,7 @@ FocusScope {
18261857 FakeMaximizeDelegate {
18271858 id: fakeRectangle
18281859 target: priv.focusedAppDelegate
1829− leftMargin: root.leftMargin
1860+ leftMargin: root.availableDesktopArea.x
18301861 appContainerWidth: appContainer.width
18311862 appContainerHeight: appContainer.height
18321863 }