@@ -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
@@ -44,10 +44,10 @@ FocusScope {
4444 property int shellOrientationAngle
4545 property bool spreadEnabled: true // If false, animations and right edge will be disabled
4646 property bool suspended
47− property int leftMargin: 0
4847 property bool oskEnabled: false
4948 property rect inputMethodRect
5049 property real rightEdgePushProgress: 0
50+ property Item availableDesktopArea
5151 property PanelState panelState
5252
5353 readonly property var temporarySelectedWorkspace: state == "spread" ? screensAndWorkspaces.lastClickedWorkspace : null
@@ -124,6 +124,12 @@ FocusScope {
124124 }
125125 }
126126
127+ // For MirAL window management
128+ WindowMargins {
129+ normal: Qt.rect(0, root.mode === "windowed" ? priv.windowDecorationHeight : 0, 0, 0)
130+ dialog: normal
131+ }
132+
127133 property Item itemConfiningMouseCursor: !spreadShown && priv.focusedAppDelegate && priv.focusedAppDelegate.window.confinesMousePointer ?
128134 priv.focusedAppDelegate.clientAreaItem : null;
129135
@@ -228,6 +234,18 @@ FocusScope {
228234 active: priv.focusedAppDelegate !== null
229235 }
230236
237+ GlobalShortcut {
238+ shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_T
239+ onTriggered: {
240+ // try in this order: snap pkg, new deb name, old deb name
241+ var candidates = ["ubuntu-terminal-app_ubuntu-terminal-app", "ubuntu-terminal-app", "com.ubuntu.terminal"];
242+ for (var i = 0; i < candidates.length; i++) {
243+ if (priv.startApp(candidates[i]))
244+ break;
245+ }
246+ }
247+ }
248+
231249 GlobalShortcut {
232250 id: showWorkspaceSwitcherShortcutLeft
233251 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
@@ -251,6 +269,14 @@ FocusScope {
251269 id: priv
252270 objectName: "DesktopStagePrivate"
253271
272+ function startApp(appId) {
273+ if (root.applicationManager.findApplication(appId)) {
274+ return root.applicationManager.requestFocusApplication(appId);
275+ } else {
276+ return root.applicationManager.startApplication(appId) !== null;
277+ }
278+ }
279+
254280 property var focusedAppDelegate: null
255281 property var foregroundMaximizedAppDelegate: null // for stuff like drop shadow and focusing maximized app by clicking panel
256282
@@ -370,6 +396,8 @@ FocusScope {
370396 }
371397
372398 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
399+
400+ readonly property real windowDecorationHeight: units.gu(3)
373401 }
374402
375403 Component.onCompleted: priv.updateMainAndSideStageIndexes()
@@ -610,7 +638,7 @@ FocusScope {
610638 id: spreadItem
611639 objectName: "spreadItem"
612640 anchors { left: parent.left; bottom: parent.bottom; right: parent.right; top: screensAndWorkspaces.bottom }
613− leftMargin: root.leftMargin
641+ leftMargin: root.availableDesktopArea.x
614642 model: root.topLevelSurfaceList
615643 spreadFlickable: floatingFlickable
616644 z: 10
@@ -813,13 +841,6 @@ FocusScope {
813841 z: 1000
814842 }
815843
816− Item {
817− id: boundariesForWindowPlacement
818− anchors.fill: parent
819− anchors.topMargin: panelState.panelHeight
820− visible: false
821− }
822−
823844 Repeater {
824845 id: appRepeater
825846 model: topLevelSurfaceList
@@ -920,7 +941,7 @@ FocusScope {
920941 target: appDelegate
921942 property: "y"
922943 value: appDelegate.requestedY -
923− Math.min(appDelegate.requestedY - panelState.panelHeight,
944+ Math.min(appDelegate.requestedY - root.availableDesktopArea.y,
924945 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
925946 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
926947 && root.inputMethodRect.height > 0
@@ -938,8 +959,8 @@ FocusScope {
938959 angleDiff = (360 + angleDiff) % 360;
939960 if (angleDiff === 90 || angleDiff === 270) {
940961 var aux = decoratedWindow.requestedHeight;
941− decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.decorationHeight;
942− decoratedWindow.requestedWidth = aux - decoratedWindow.decorationHeight;
962+ decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.actualDecorationHeight;
963+ decoratedWindow.requestedWidth = aux - decoratedWindow.actualDecorationHeight;
943964 }
944965 }
945966 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
@@ -1039,12 +1060,13 @@ FocusScope {
10391060 priv.updateMainAndSideStageIndexes();
10401061 }
10411062 appDelegate.focus = true;
1063+ priv.focusedAppDelegate = appDelegate;
10421064 }
10431065
10441066 function updateQmlFocusFromMirSurfaceFocus() {
10451067 if (model.window.focused) {
10461068 claimFocus();
1047− priv.focusedAppDelegate = appDelegate;
1069+ decoratedWindow.focus = true;
10481070 }
10491071 }
10501072
@@ -1053,8 +1075,8 @@ FocusScope {
10531075 target: appDelegate
10541076 screenWidth: appContainer.width
10551077 screenHeight: appContainer.height
1056− leftMargin: root.leftMargin
1057− minimumY: boundariesForWindowPlacement.y
1078+ leftMargin: root.availableDesktopArea.x
1079+ minimumY: root.availableDesktopArea.y
10581080 }
10591081
10601082 Connections {
@@ -1306,7 +1328,7 @@ FocusScope {
13061328
13071329 StagedRightEdgeMaths {
13081330 id: stagedRightEdgeMaths
1309− sceneWidth: appContainer.width - root.leftMargin
1331+ sceneWidth: root.availableDesktopArea.width
13101332 sceneHeight: appContainer.height
13111333 isMainStageApp: priv.mainStageDelegate == appDelegate
13121334 isSideStageApp: priv.sideStageDelegate == appDelegate
@@ -1317,7 +1339,7 @@ FocusScope {
13171339 progress: 0
13181340 targetHeight: spreadItem.stackHeight
13191341 targetX: spreadMaths.targetX
1320− startY: appDelegate.fullscreen ? 0 : panelState.panelHeight
1342+ startY: appDelegate.fullscreen ? 0 : root.availableDesktopArea.y
13211343 targetY: spreadMaths.targetY
13221344 targetAngle: spreadMaths.targetAngle
13231345 targetScale: spreadMaths.targetScale
@@ -1432,14 +1454,14 @@ FocusScope {
14321454 PropertyChanges {
14331455 target: appDelegate
14341456 x: stageMaths.itemX
1435− y: appDelegate.fullscreen ? 0 : panelState.panelHeight
1457+ y: root.availableDesktopArea.y
14361458 visuallyMaximized: true
14371459 visible: appDelegate.x < root.width
14381460 }
14391461 PropertyChanges {
14401462 target: appDelegate
14411463 requestedWidth: appContainer.width
1442− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1464+ requestedHeight: root.availableDesktopArea.height
14431465 restoreEntryValues: false
14441466 }
14451467 PropertyChanges {
@@ -1468,7 +1490,7 @@ FocusScope {
14681490 PropertyChanges {
14691491 target: appDelegate
14701492 x: stageMaths.itemX
1471− y: appDelegate.fullscreen ? 0 : panelState.panelHeight
1493+ y: root.availableDesktopArea.y
14721494 z: stageMaths.itemZ
14731495 visuallyMaximized: true
14741496 visible: appDelegate.x < root.width
@@ -1476,7 +1498,7 @@ FocusScope {
14761498 PropertyChanges {
14771499 target: appDelegate
14781500 requestedWidth: stageMaths.itemWidth
1479− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1501+ requestedHeight: root.availableDesktopArea.height
14801502 restoreEntryValues: false
14811503 }
14821504 PropertyChanges {
@@ -1496,15 +1518,15 @@ FocusScope {
14961518 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
14971519 PropertyChanges {
14981520 target: appDelegate;
1499− requestedX: root.leftMargin;
1521+ requestedX: root.availableDesktopArea.x;
15001522 requestedY: 0;
15011523 visuallyMinimized: false;
15021524 visuallyMaximized: true
15031525 }
15041526 PropertyChanges {
15051527 target: appDelegate
1506− requestedWidth: appContainer.width - root.leftMargin
1507− requestedHeight: appContainer.height
1528+ requestedWidth: root.availableDesktopArea.width;
1529+ requestedHeight: appContainer.height;
15081530 restoreEntryValues: false
15091531 }
15101532 PropertyChanges { target: touchControls; enabled: true }
@@ -1547,6 +1569,7 @@ FocusScope {
15471569 when: appDelegate.windowState == WindowStateStorage.WindowStateRestored
15481570 extend: "normal"
15491571 PropertyChanges {
1572+ restoreEntryValues: false
15501573 target: appDelegate;
15511574 windowedX: restoredX;
15521575 windowedY: restoredY;
@@ -1557,10 +1580,10 @@ FocusScope {
15571580 extend: "normal"
15581581 PropertyChanges {
15591582 target: appDelegate
1560− windowedX: root.leftMargin
1561− windowedY: panelState.panelHeight
1562− windowedWidth: (appContainer.width - root.leftMargin)/2
1563− windowedHeight: appContainer.height - panelState.panelHeight
1583+ windowedX: root.availableDesktopArea.x
1584+ windowedY: root.availableDesktopArea.y
1585+ windowedWidth: root.availableDesktopArea.width / 2
1586+ windowedHeight: root.availableDesktopArea.height
15641587 }
15651588 },
15661589 State {
@@ -1568,7 +1591,7 @@ FocusScope {
15681591 extend: "maximizedLeft"
15691592 PropertyChanges {
15701593 target: appDelegate;
1571− windowedX: (appContainer.width + root.leftMargin)/2
1594+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
15721595 }
15731596 },
15741597 State {
@@ -1576,10 +1599,10 @@ FocusScope {
15761599 extend: "normal"
15771600 PropertyChanges {
15781601 target: appDelegate
1579− windowedX: root.leftMargin
1580− windowedY: panelState.panelHeight
1581− windowedWidth: (appContainer.width - root.leftMargin)/2
1582− windowedHeight: (appContainer.height - panelState.panelHeight)/2
1602+ windowedX: root.availableDesktopArea.x
1603+ windowedY: root.availableDesktopArea.y
1604+ windowedWidth: root.availableDesktopArea.width / 2
1605+ windowedHeight: root.availableDesktopArea.height / 2
15831606 }
15841607 },
15851608 State {
@@ -1587,7 +1610,7 @@ FocusScope {
15871610 extend: "maximizedTopLeft"
15881611 PropertyChanges {
15891612 target: appDelegate
1590− windowedX: (appContainer.width + root.leftMargin)/2
1613+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
15911614 }
15921615 },
15931616 State {
@@ -1595,10 +1618,10 @@ FocusScope {
15951618 extend: "normal"
15961619 PropertyChanges {
15971620 target: appDelegate
1598− windowedX: root.leftMargin
1599− windowedY: (appContainer.height + panelState.panelHeight)/2
1600− windowedWidth: (appContainer.width - root.leftMargin)/2
1601− windowedHeight: appContainer.height/2
1621+ windowedX: root.availableDesktopArea.x
1622+ windowedY: root.availableDesktopArea.y + (root.availableDesktopArea.height / 2)
1623+ windowedWidth: root.availableDesktopArea.width / 2
1624+ windowedHeight: root.availableDesktopArea.height / 2
16021625 }
16031626 },
16041627 State {
@@ -1606,20 +1629,26 @@ FocusScope {
16061629 extend: "maximizedBottomLeft"
16071630 PropertyChanges {
16081631 target: appDelegate
1609− windowedX: (appContainer.width + root.leftMargin)/2
1632+ windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
16101633 }
16111634 },
16121635 State {
16131636 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
16141637 extend: "normal"
1615− PropertyChanges { target: appDelegate; windowedX: root.leftMargin; windowedY: windowedY;
1616− windowedWidth: appContainer.width - root.leftMargin; windowedHeight: windowedHeight }
1638+ PropertyChanges {
1639+ target: appDelegate
1640+ windowedX: root.availableDesktopArea.x; windowedY: windowedY
1641+ windowedWidth: root.availableDesktopArea.width; windowedHeight: windowedHeight
1642+ }
16171643 },
16181644 State {
16191645 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
16201646 extend: "normal"
1621− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: panelState.panelHeight;
1622− windowedWidth: windowedWidth; windowedHeight: appContainer.height - panelState.panelHeight }
1647+ PropertyChanges {
1648+ target: appDelegate
1649+ windowedX: windowedX; windowedY: root.availableDesktopArea.y
1650+ windowedWidth: windowedWidth; windowedHeight: root.availableDesktopArea.height
1651+ }
16231652 },
16241653 State {
16251654 name: "minimized"; when: appDelegate.minimized
@@ -1752,7 +1781,7 @@ FocusScope {
17521781 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
17531782
17541783 target: appDelegate
1755− boundsItem: boundariesForWindowPlacement
1784+ boundsItem: root.availableDesktopArea
17561785 minWidth: units.gu(10)
17571786 minHeight: units.gu(10)
17581787 borderThickness: units.gu(2)
@@ -1776,12 +1805,13 @@ FocusScope {
17761805 focus: true
17771806 interactive: root.interactive
17781807 showDecoration: 1
1808+ decorationHeight: priv.windowDecorationHeight
17791809 maximizeButtonShown: appDelegate.canBeMaximized
17801810 overlayShown: touchControls.overlayShown
17811811 width: implicitWidth
17821812 height: implicitHeight
17831813 highlightSize: windowInfoItem.iconMargin / 2
1784− boundsItem: boundariesForWindowPlacement
1814+ boundsItem: root.availableDesktopArea
17851815 panelState: root.panelState
17861816 altDragEnabled: root.mode == "windowed"
17871817
@@ -1840,7 +1870,7 @@ FocusScope {
18401870 resizeArea: resizeArea
18411871 enabled: false
18421872 visible: enabled
1843− boundsItem: boundariesForWindowPlacement
1873+ boundsItem: root.availableDesktopArea
18441874
18451875 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
18461876 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
@@ -1966,9 +1996,18 @@ FocusScope {
19661996 displacementX: appDelegate.clientAreaItem.x
19671997 displacementY: appDelegate.clientAreaItem.y
19681998
1969− boundsItem: boundariesForWindowPlacement
1999+ boundsItem: root.availableDesktopArea
2000+ decorationHeight: priv.windowDecorationHeight
19702001
19712002 z: childWindowRepeater.count - model.index
2003+
2004+ onFocusChanged: {
2005+ if (focus) {
2006+ // some child surface in this tree got focus.
2007+ // Ensure we also have it at the top-level hierarchy
2008+ appDelegate.claimFocus();
2009+ }
2010+ }
19722011 }
19732012 }
19742013 }
@@ -1979,7 +2018,7 @@ FocusScope {
19792018 FakeMaximizeDelegate {
19802019 id: fakeRectangle
19812020 target: priv.focusedAppDelegate
1982− leftMargin: root.leftMargin
2021+ leftMargin: root.availableDesktopArea.x
19832022 appContainerWidth: appContainer.width
19842023 appContainerHeight: appContainer.height
19852024 panelState: root.panelState