@@ -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();
@@ -568,7 +597,7 @@ FocusScope {
568597 id: spreadItem
569598 objectName: "spreadItem"
570599 anchors.fill: appContainer
571− leftMargin: root.leftMargin
600+ leftMargin: root.availableDesktopArea.x
572601 model: root.topLevelSurfaceList
573602 spreadFlickable: floatingFlickable
574603 z: 10
@@ -676,13 +705,6 @@ FocusScope {
676705 }
677706 }
678707
679− Item {
680− id: boundariesForWindowPlacement
681− anchors.fill: parent
682− anchors.topMargin: PanelState.panelHeight
683− visible: false
684− }
685−
686708 Repeater {
687709 id: appRepeater
688710 model: topLevelSurfaceList
@@ -780,7 +802,7 @@ FocusScope {
780802 target: appDelegate
781803 property: "y"
782804 value: appDelegate.requestedY -
783− Math.min(appDelegate.requestedY - PanelState.panelHeight,
805+ Math.min(appDelegate.requestedY - root.availableDesktopArea.y,
784806 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
785807 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
786808 && root.inputMethodRect.height > 0
@@ -798,8 +820,8 @@ FocusScope {
798820 angleDiff = (360 + angleDiff) % 360;
799821 if (angleDiff === 90 || angleDiff === 270) {
800822 var aux = decoratedWindow.requestedHeight;
801− decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.decorationHeight;
802− decoratedWindow.requestedWidth = aux - decoratedWindow.decorationHeight;
823+ decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.actualDecorationHeight;
824+ decoratedWindow.requestedWidth = aux - decoratedWindow.actualDecorationHeight;
803825 }
804826 }
805827 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -900,12 +922,13 @@ FocusScope {
900922 priv.updateMainAndSideStageIndexes();
901923 }
902924 appDelegate.focus = true;
925+ priv.focusedAppDelegate = appDelegate;
903926 }
904927
905928 function updateQmlFocusFromMirSurfaceFocus() {
906929 if (model.window.focused) {
907930 claimFocus();
908− priv.focusedAppDelegate = appDelegate;
931+ decoratedWindow.focus = true;
909932 }
910933 }
911934
@@ -914,8 +937,8 @@ FocusScope {
914937 target: appDelegate
915938 screenWidth: appContainer.width
916939 screenHeight: appContainer.height
917− leftMargin: root.leftMargin
918− minimumY: boundariesForWindowPlacement.y
940+ leftMargin: root.availableDesktopArea.x
941+ minimumY: root.availableDesktopArea.y
919942 }
920943
921944 Connections {
@@ -1167,7 +1190,7 @@ FocusScope {
11671190
11681191 StagedRightEdgeMaths {
11691192 id: stagedRightEdgeMaths
1170− sceneWidth: appContainer.width - root.leftMargin
1193+ sceneWidth: root.availableDesktopArea.width
11711194 sceneHeight: appContainer.height
11721195 isMainStageApp: priv.mainStageDelegate == appDelegate
11731196 isSideStageApp: priv.sideStageDelegate == appDelegate
@@ -1178,7 +1201,7 @@ FocusScope {
11781201 progress: 0
11791202 targetHeight: spreadItem.stackHeight
11801203 targetX: spreadMaths.targetX
1181− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1204+ startY: appDelegate.fullscreen ? 0 : root.availableDesktopArea.y
11821205 targetY: spreadMaths.targetY
11831206 targetAngle: spreadMaths.targetAngle
11841207 targetScale: spreadMaths.targetScale
@@ -1299,9 +1322,9 @@ FocusScope {
12991322 PropertyChanges {
13001323 target: appDelegate
13011324 x: stageMaths.itemX
1302− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1325+ y: root.availableDesktopArea.y
13031326 requestedWidth: appContainer.width
1304− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1327+ requestedHeight: root.availableDesktopArea.height
13051328 visuallyMaximized: true
13061329 visible: appDelegate.x < root.width
13071330 }
@@ -1331,10 +1354,10 @@ FocusScope {
13311354 PropertyChanges {
13321355 target: appDelegate
13331356 x: stageMaths.itemX
1334− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1357+ y: root.availableDesktopArea.y
13351358 z: stageMaths.itemZ
13361359 requestedWidth: stageMaths.itemWidth
1337− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1360+ requestedHeight: root.availableDesktopArea.height
13381361 visuallyMaximized: true
13391362 visible: appDelegate.x < root.width
13401363 }
@@ -1355,11 +1378,11 @@ FocusScope {
13551378 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
13561379 PropertyChanges {
13571380 target: appDelegate;
1358− requestedX: root.leftMargin;
1381+ requestedX: root.availableDesktopArea.x;
13591382 requestedY: 0;
13601383 visuallyMinimized: false;
13611384 visuallyMaximized: true
1362− requestedWidth: appContainer.width - root.leftMargin;
1385+ requestedWidth: root.availableDesktopArea.width;
13631386 requestedHeight: appContainer.height;
13641387 }
13651388 PropertyChanges { target: touchControls; enabled: true }
@@ -1392,6 +1415,7 @@ FocusScope {
13921415 when: appDelegate.windowState == WindowStateStorage.WindowStateRestored
13931416 extend: "normal"
13941417 PropertyChanges {
1418+ restoreEntryValues: false
13951419 target: appDelegate;
13961420 windowedX: restoredX;
13971421 windowedY: restoredY;
@@ -1402,10 +1426,10 @@ FocusScope {
14021426 extend: "normal"
14031427 PropertyChanges {
14041428 target: appDelegate
1405− windowedX: root.leftMargin
1406− windowedY: PanelState.panelHeight
1407− windowedWidth: (appContainer.width - root.leftMargin)/2
1408− windowedHeight: appContainer.height - PanelState.panelHeight
1429+ windowedX: root.availableDesktopArea.x
1430+ windowedY: root.availableDesktopArea.y
1431+ windowedWidth: root.availableDesktopArea.width / 2
1432+ windowedHeight: root.availableDesktopArea.height
14091433 }
14101434 },
14111435 State {
@@ -1413,7 +1437,7 @@ FocusScope {
14131437 extend: "maximizedLeft"
14141438 PropertyChanges {
14151439 target: appDelegate;
1416− windowedX: (appContainer.width + root.leftMargin)/2
1440+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14171441 }
14181442 },
14191443 State {
@@ -1421,10 +1445,10 @@ FocusScope {
14211445 extend: "normal"
14221446 PropertyChanges {
14231447 target: appDelegate
1424− windowedX: root.leftMargin
1425− windowedY: PanelState.panelHeight
1426− windowedWidth: (appContainer.width - root.leftMargin)/2
1427− windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1448+ windowedX: root.availableDesktopArea.x
1449+ windowedY: root.availableDesktopArea.y
1450+ windowedWidth: root.availableDesktopArea.width / 2
1451+ windowedHeight: root.availableDesktopArea.height / 2
14281452 }
14291453 },
14301454 State {
@@ -1432,7 +1456,7 @@ FocusScope {
14321456 extend: "maximizedTopLeft"
14331457 PropertyChanges {
14341458 target: appDelegate
1435− windowedX: (appContainer.width + root.leftMargin)/2
1459+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14361460 }
14371461 },
14381462 State {
@@ -1440,10 +1464,10 @@ FocusScope {
14401464 extend: "normal"
14411465 PropertyChanges {
14421466 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
1467+ windowedX: root.availableDesktopArea.x
1468+ windowedY: root.availableDesktopArea.y + (root.availableDesktopArea.height / 2)
1469+ windowedWidth: root.availableDesktopArea.width / 2
1470+ windowedHeight: root.availableDesktopArea.height / 2
14471471 }
14481472 },
14491473 State {
@@ -1451,20 +1475,26 @@ FocusScope {
14511475 extend: "maximizedBottomLeft"
14521476 PropertyChanges {
14531477 target: appDelegate
1454− windowedX: (appContainer.width + root.leftMargin)/2
1478+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
14551479 }
14561480 },
14571481 State {
14581482 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
14591483 extend: "normal"
1460− PropertyChanges { target: appDelegate; windowedX: root.leftMargin; windowedY: windowedY;
1461− windowedWidth: appContainer.width - root.leftMargin; windowedHeight: windowedHeight }
1484+ PropertyChanges {
1485+ target: appDelegate
1486+ windowedX: root.availableDesktopArea.x; windowedY: windowedY
1487+ windowedWidth: root.availableDesktopArea.width; windowedHeight: windowedHeight
1488+ }
14621489 },
14631490 State {
14641491 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
14651492 extend: "normal"
1466− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1467− windowedWidth: windowedWidth; windowedHeight: appContainer.height - PanelState.panelHeight }
1493+ PropertyChanges {
1494+ target: appDelegate
1495+ windowedX: windowedX; windowedY: root.availableDesktopArea.y
1496+ windowedWidth: windowedWidth; windowedHeight: root.availableDesktopArea.height
1497+ }
14681498 },
14691499 State {
14701500 name: "minimized"; when: appDelegate.minimized
@@ -1592,7 +1622,7 @@ FocusScope {
15921622 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
15931623
15941624 target: appDelegate
1595− boundsItem: boundariesForWindowPlacement
1625+ boundsItem: root.availableDesktopArea
15961626 minWidth: units.gu(10)
15971627 minHeight: units.gu(10)
15981628 borderThickness: units.gu(2)
@@ -1615,13 +1645,14 @@ FocusScope {
16151645 focus: true
16161646 interactive: root.interactive
16171647 showDecoration: 1
1648+ decorationHeight: priv.windowDecorationHeight
16181649 maximizeButtonShown: appDelegate.canBeMaximized
16191650 overlayShown: touchControls.overlayShown
16201651 width: implicitWidth
16211652 height: implicitHeight
16221653 highlightSize: windowInfoItem.iconMargin / 2
1623− boundsItem: boundariesForWindowPlacement
16241654 altDragEnabled: root.mode == "windowed"
1655+ boundsItem: root.availableDesktopArea
16251656
16261657 requestedWidth: appDelegate.requestedWidth
16271658 requestedHeight: appDelegate.requestedHeight
@@ -1684,7 +1715,7 @@ FocusScope {
16841715 resizeArea: resizeArea
16851716 enabled: false
16861717 visible: enabled
1687− boundsItem: boundariesForWindowPlacement
1718+ boundsItem: root.availableDesktopArea
16881719
16891720 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
16901721 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
@@ -1805,9 +1836,18 @@ FocusScope {
18051836 displacementX: appDelegate.clientAreaItem.x
18061837 displacementY: appDelegate.clientAreaItem.y
18071838
1808− boundsItem: boundariesForWindowPlacement
1839+ boundsItem: root.availableDesktopArea
1840+ decorationHeight: priv.windowDecorationHeight
18091841
18101842 z: childWindowRepeater.count - model.index
1843+
1844+ onFocusChanged: {
1845+ if (focus) {
1846+ // some child surface in this tree got focus.
1847+ // Ensure we also have it at the top-level hierarchy
1848+ appDelegate.claimFocus();
1849+ }
1850+ }
18111851 }
18121852 }
18131853 }
@@ -1818,7 +1858,7 @@ FocusScope {
18181858 FakeMaximizeDelegate {
18191859 id: fakeRectangle
18201860 target: priv.focusedAppDelegate
1821− leftMargin: root.leftMargin
1861+ leftMargin: root.availableDesktopArea.x
18221862 appContainerWidth: appContainer.width
18231863 appContainerHeight: appContainer.height
18241864 }