@@ -0,0 +1,1881 @@
1+/*
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import Unity.Application 0.1
20+import "../Components/PanelState"
21+import "../Components"
22+import Utils 0.1
23+import Ubuntu.Gestures 0.1
24+import GlobalShortcut 1.0
25+import GSettings 1.0
26+import "Spread"
27+import "Spread/MathUtils.js" as MathUtils
28+
29+FocusScope {
30+ id: root
31+ anchors.fill: parent
32+
33+ property QtObject applicationManager
34+ property QtObject topLevelSurfaceList
35+ property bool altTabPressed
36+ property url background
37+ property int dragAreaWidth
38+ property bool interactive
39+ property bool keepDashRunning: true
40+ property real nativeHeight
41+ property real nativeWidth
42+ property QtObject orientations
43+ property int shellOrientation
44+ property int shellOrientationAngle
45+ property bool spreadEnabled: true // If false, animations and right edge will be disabled
46+ property bool suspended
47+ property int leftMargin: 0
48+ property bool oskEnabled: false
49+ property rect inputMethodRect
50+
51+ // Configuration
52+ property string mode: "staged"
53+ property real leftEdgeDragProgress: 0
54+
55+ // Used by the tutorial code
56+ readonly property bool spreadShown: state == "spread"
57+ readonly property real rightEdgeDragProgress: rightEdgeDragArea.progress // How far left the stage has been dragged
58+
59+ // used by the snap windows (edge maximize) feature
60+ readonly property alias previewRectangle: fakeRectangle
61+
62+ readonly property var mainApp: priv.focusedAppDelegate ? priv.focusedAppDelegate.application : null
63+
64+ // application windows never rotate independently
65+ property int mainAppWindowOrientationAngle: shellOrientationAngle
66+
67+ property bool orientationChangesEnabled: priv.focusedAppDelegate && priv.focusedAppDelegate.orientationChangesEnabled
68+
69+ property int supportedOrientations: {
70+ if (mainApp) {
71+ switch (mode) {
72+ case "staged":
73+ return mainApp.supportedOrientations;
74+ case "stagedWithSideStage":
75+ var orientations = mainApp.supportedOrientations;
76+ orientations |= Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation;
77+ if (priv.sideStageItemId) {
78+ // If we have a sidestage app, support Portrait orientation
79+ // so that it will switch the sidestage app to mainstage on rotate to portrait
80+ orientations |= Qt.PortraitOrientation|Qt.InvertedPortraitOrientation;
81+ }
82+ return orientations;
83+ }
84+ }
85+
86+ return Qt.PortraitOrientation |
87+ Qt.LandscapeOrientation |
88+ Qt.InvertedPortraitOrientation |
89+ Qt.InvertedLandscapeOrientation;
90+ }
91+
92+
93+ onAltTabPressedChanged: priv.goneToSpread = altTabPressed
94+
95+ property Item itemConfiningMouseCursor: !spreadShown && priv.focusedAppDelegate && priv.focusedAppDelegate.surface &&
96+ priv.focusedAppDelegate.surface.confinesMousePointer ?
97+ priv.focusedAppDelegate.clientAreaItem : null;
98+
99+ signal itemSnapshotRequested(Item item)
100+
101+ // functions to be called from outside
102+ function updateFocusedAppOrientation() { /* TODO */ }
103+ function updateFocusedAppOrientationAnimated() { /* TODO */}
104+ function pushRightEdge(amount) {
105+ edgeBarrier.push(amount);
106+ }
107+
108+ onSpreadEnabledChanged: {
109+ if (!spreadEnabled && root.state == "spread") {
110+ priv.goneToSpread = false;
111+ }
112+ }
113+
114+ GSettings {
115+ id: lifecycleExceptions
116+ schema.id: "com.canonical.qtmir"
117+ }
118+
119+ function isExemptFromLifecycle(appId) {
120+ var shortAppId = appId.split('_')[0];
121+ for (var i = 0; i < lifecycleExceptions.lifecycleExemptAppids.length; i++) {
122+ if (shortAppId === lifecycleExceptions.lifecycleExemptAppids[i]) {
123+ return true;
124+ }
125+ }
126+ return false;
127+ }
128+
129+ GlobalShortcut {
130+ id: closeFocusedShortcut
131+ shortcut: Qt.AltModifier|Qt.Key_F4
132+ onTriggered: {
133+ if (priv.focusedAppDelegate && !priv.focusedAppDelegate.isDash) {
134+ priv.focusedAppDelegate.close();
135+ }
136+ }
137+ }
138+
139+ GlobalShortcut {
140+ id: showSpreadShortcut
141+ shortcut: Qt.MetaModifier|Qt.Key_W
142+ onTriggered: priv.goneToSpread = true
143+ }
144+
145+ GlobalShortcut {
146+ id: minimizeAllShortcut
147+ shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_D
148+ onTriggered: priv.minimizeAllWindows()
149+ active: root.state == "windowed"
150+ }
151+
152+ GlobalShortcut {
153+ id: maximizeWindowShortcut
154+ shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
155+ onTriggered: priv.focusedAppDelegate.maximize()
156+ active: root.state == "windowed" && priv.focusedAppDelegate && priv.focusedAppDelegate.canBeMaximized
157+ }
158+
159+ GlobalShortcut {
160+ id: maximizeWindowLeftShortcut
161+ shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Left
162+ onTriggered: priv.focusedAppDelegate.maximizeLeft()
163+ active: root.state == "windowed" && priv.focusedAppDelegate && priv.focusedAppDelegate.canBeMaximizedLeftRight
164+ }
165+
166+ GlobalShortcut {
167+ id: maximizeWindowRightShortcut
168+ shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Right
169+ onTriggered: priv.focusedAppDelegate.maximizeRight()
170+ active: root.state == "windowed" && priv.focusedAppDelegate && priv.focusedAppDelegate.canBeMaximizedLeftRight
171+ }
172+
173+ GlobalShortcut {
174+ id: minimizeRestoreShortcut
175+ shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
176+ onTriggered: priv.focusedAppDelegate.anyMaximized
177+ ? priv.focusedAppDelegate.restoreFromMaximized() : priv.focusedAppDelegate.minimize()
178+ active: root.state == "windowed" && priv.focusedAppDelegate
179+ }
180+
181+ GlobalShortcut {
182+ shortcut: Qt.AltModifier|Qt.Key_Print
183+ onTriggered: root.itemSnapshotRequested(priv.focusedAppDelegate)
184+ active: priv.focusedAppDelegate !== null
185+ }
186+
187+ QtObject {
188+ id: priv
189+ objectName: "DesktopStagePrivate"
190+
191+ property var focusedAppDelegate: null
192+ property var foregroundMaximizedAppDelegate: null // for stuff like drop shadow and focusing maximized app by clicking panel
193+
194+ property bool goneToSpread: false
195+ property int closingIndex: -1
196+ property int animationDuration: UbuntuAnimation.FastDuration
197+
198+ function updateForegroundMaximizedApp() {
199+ var found = false;
200+ for (var i = 0; i < appRepeater.count && !found; i++) {
201+ var item = appRepeater.itemAt(i);
202+ if (item && item.visuallyMaximized) {
203+ foregroundMaximizedAppDelegate = item;
204+ found = true;
205+ }
206+ }
207+ if (!found) {
208+ foregroundMaximizedAppDelegate = null;
209+ }
210+ }
211+
212+ function minimizeAllWindows() {
213+ for (var i = 0; i < appRepeater.count; i++) {
214+ var appDelegate = appRepeater.itemAt(i);
215+ if (appDelegate && !appDelegate.minimized) {
216+ appDelegate.minimize();
217+ }
218+ }
219+ }
220+
221+ function focusNext() {
222+ for (var i = 0; i < appRepeater.count; i++) {
223+ var appDelegate = appRepeater.itemAt(i);
224+ if (appDelegate && !appDelegate.minimized) {
225+ appDelegate.focus = true;
226+ return;
227+ }
228+ }
229+ }
230+
231+ readonly property bool sideStageEnabled: root.mode === "stagedWithSideStage" &&
232+ (root.shellOrientation == Qt.LandscapeOrientation ||
233+ root.shellOrientation == Qt.InvertedLandscapeOrientation)
234+
235+ property var mainStageDelegate: null
236+ property var sideStageDelegate: null
237+ property int mainStageItemId: 0
238+ property int sideStageItemId: 0
239+ property string mainStageAppId: ""
240+ property string sideStageAppId: ""
241+
242+ onSideStageDelegateChanged: {
243+ if (!sideStageDelegate) {
244+ sideStage.hide();
245+ }
246+ }
247+
248+ function updateMainAndSideStageIndexes() {
249+ if (root.mode != "stagedWithSideStage") {
250+ priv.sideStageDelegate = null;
251+ priv.sideStageItemId = 0;
252+ priv.sideStageAppId = "";
253+ priv.mainStageDelegate = appRepeater.itemAt(0);
254+ priv.mainStageAppId = topLevelSurfaceList.idAt(0);
255+ priv.mainStageAppId = topLevelSurfaceList.applicationAt(0) ? topLevelSurfaceList.applicationAt(0).appId : ""
256+ return;
257+ }
258+
259+ var choseMainStage = false;
260+ var choseSideStage = false;
261+
262+ if (!root.topLevelSurfaceList)
263+ return;
264+
265+ for (var i = 0; i < appRepeater.count && (!choseMainStage || !choseSideStage); ++i) {
266+ var appDelegate = appRepeater.itemAt(i);
267+ if (!appDelegate) {
268+ // This might happen during startup phase... If the delegate appears and claims focus
269+ // things are updated and appRepeater.itemAt(x) still returns null while appRepeater.count >= x
270+ // Lets just skip it, on startup it will be generated at a later point too...
271+ continue;
272+ }
273+ if (sideStage.shown && appDelegate.stage == ApplicationInfoInterface.SideStage
274+ && !choseSideStage) {
275+ priv.sideStageDelegate = appDelegate
276+ priv.sideStageItemId = root.topLevelSurfaceList.idAt(i);
277+ priv.sideStageAppId = root.topLevelSurfaceList.applicationAt(i).appId;
278+ choseSideStage = true;
279+ } else if (!choseMainStage && appDelegate.stage == ApplicationInfoInterface.MainStage) {
280+ priv.mainStageDelegate = appDelegate;
281+ priv.mainStageItemId = root.topLevelSurfaceList.idAt(i);
282+ priv.mainStageAppId = root.topLevelSurfaceList.applicationAt(i).appId;
283+ choseMainStage = true;
284+ }
285+ }
286+ if (!choseMainStage && priv.mainStageDelegate) {
287+ priv.mainStageDelegate = null;
288+ priv.mainStageItemId = 0;
289+ priv.mainStageAppId = "";
290+ }
291+ if (!choseSideStage && priv.sideStageDelegate) {
292+ priv.sideStageDelegate = null;
293+ priv.sideStageItemId = 0;
294+ priv.sideStageAppId = "";
295+ }
296+ }
297+
298+ property int nextInStack: {
299+ var mainStageIndex = priv.mainStageDelegate ? priv.mainStageDelegate.itemIndex : -1;
300+ var sideStageIndex = priv.sideStageDelegate ? priv.sideStageDelegate.itemIndex : -1;
301+ if (sideStageIndex == -1) {
302+ return topLevelSurfaceList.count > 1 ? 1 : -1;
303+ }
304+ if (mainStageIndex == 0 || sideStageIndex == 0) {
305+ if (mainStageIndex == 1 || sideStageIndex == 1) {
306+ return topLevelSurfaceList.count > 2 ? 2 : -1;
307+ }
308+ return 1;
309+ }
310+ return -1;
311+ }
312+
313+ readonly property real virtualKeyboardHeight: root.inputMethodRect.height
314+ }
315+
316+ Component.onCompleted: priv.updateMainAndSideStageIndexes();
317+
318+ Connections {
319+ target: PanelState
320+ onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
321+ onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.minimize(); } }
322+ onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.restoreFromMaximized(); } }
323+ }
324+
325+ Binding {
326+ target: PanelState
327+ property: "buttonsVisible"
328+ value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized // FIXME for Locally integrated menus
329+ }
330+
331+ Binding {
332+ target: PanelState
333+ property: "title"
334+ value: {
335+ if (priv.focusedAppDelegate !== null) {
336+ if (priv.focusedAppDelegate.maximized)
337+ return priv.focusedAppDelegate.title
338+ else
339+ return priv.focusedAppDelegate.appName
340+ }
341+ return ""
342+ }
343+ when: priv.focusedAppDelegate
344+ }
345+
346+ Binding {
347+ target: PanelState
348+ property: "dropShadow"
349+ value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
350+ }
351+
352+ Binding {
353+ target: PanelState
354+ property: "closeButtonShown"
355+ value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
356+ }
357+
358+ Component.onDestruction: {
359+ PanelState.title = "";
360+ PanelState.buttonsVisible = false;
361+ PanelState.dropShadow = false;
362+ }
363+
364+ Instantiator {
365+ model: root.applicationManager
366+ delegate: QtObject {
367+ property var stateBinding: Binding {
368+ readonly property bool isDash: model.application ? model.application.appId == "unity8-dash" : false
369+ target: model.application
370+ property: "requestedState"
371+
372+ // TODO: figure out some lifecycle policy, like suspending minimized apps
373+ // or something if running windowed.
374+ // TODO: If the device has a dozen suspended apps because it was running
375+ // in staged mode, when it switches to Windowed mode it will suddenly
376+ // resume all those apps at once. We might want to avoid that.
377+ value: root.mode === "windowed"
378+ || (isDash && root.keepDashRunning)
379+ || (!root.suspended && model.application && priv.focusedAppDelegate &&
380+ (priv.focusedAppDelegate.appId === model.application.appId ||
381+ priv.mainStageAppId === model.application.appId ||
382+ priv.sideStageAppId === model.application.appId))
383+ ? ApplicationInfoInterface.RequestedRunning
384+ : ApplicationInfoInterface.RequestedSuspended
385+ }
386+
387+ property var lifecycleBinding: Binding {
388+ target: model.application
389+ property: "exemptFromLifecycle"
390+ value: model.application
391+ ? (!model.application.isTouchApp || isExemptFromLifecycle(model.application.appId))
392+ : false
393+ }
394+ }
395+ }
396+
397+ Binding {
398+ target: MirFocusController
399+ property: "focusedSurface"
400+ value: priv.focusedAppDelegate ? priv.focusedAppDelegate.focusedSurface : null
401+ when: !appRepeater.startingUp && root.parent
402+ }
403+
404+ states: [
405+ State {
406+ name: "spread"; when: priv.goneToSpread
407+ PropertyChanges { target: floatingFlickable; enabled: true }
408+ PropertyChanges { target: spreadItem; focus: true }
409+ PropertyChanges { target: hoverMouseArea; enabled: true }
410+ PropertyChanges { target: rightEdgeDragArea; enabled: false }
411+ PropertyChanges { target: cancelSpreadMouseArea; enabled: true }
412+ },
413+ State {
414+ name: "stagedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "staged"
415+ },
416+ State {
417+ name: "sideStagedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "stagedWithSideStage"
418+ PropertyChanges {
419+ target: sideStage
420+ opacity: priv.sideStageDelegate.x === sideStage.x ? 1 : 0
421+ visible: true
422+ }
423+ },
424+ State {
425+ name: "windowedRightEdge"; when: (rightEdgeDragArea.dragging || edgeBarrier.progress > 0) && root.mode == "windowed"
426+ },
427+ State {
428+ name: "staged"; when: root.mode === "staged"
429+ },
430+ State {
431+ name: "stagedWithSideStage"; when: root.mode === "stagedWithSideStage"
432+ PropertyChanges { target: triGestureArea; enabled: true }
433+ PropertyChanges { target: sideStage; visible: true }
434+ },
435+ State {
436+ name: "windowed"; when: root.mode === "windowed"
437+ }
438+ ]
439+ transitions: [
440+ Transition {
441+ from: "stagedRightEdge,sideStagedRightEdge,windowedRightEdge"; to: "spread"
442+ PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
443+ },
444+ Transition {
445+ to: "spread"
446+ PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
447+ PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
448+ },
449+ Transition {
450+ from: "spread"
451+ SequentialAnimation {
452+ ScriptAction {
453+ script: {
454+ var item = appRepeater.itemAt(Math.max(0, spreadItem.highlightedIndex));
455+ if (item.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
456+ sideStage.show();
457+ }
458+ item.playFocusAnimation();
459+ }
460+ }
461+ PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
462+ }
463+ },
464+ Transition {
465+ to: "stagedRightEdge"
466+ PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
467+ },
468+ Transition {
469+ to: "stagedWithSideStage"
470+ ScriptAction { script: priv.updateMainAndSideStageIndexes(); }
471+ }
472+
473+ ]
474+
475+ MouseArea {
476+ id: cancelSpreadMouseArea
477+ anchors.fill: parent
478+ enabled: false
479+ onClicked: priv.goneToSpread = false
480+ }
481+
482+ FocusScope {
483+ id: appContainer
484+ objectName: "appContainer"
485+ anchors.fill: parent
486+ focus: true
487+
488+ Wallpaper {
489+ id: wallpaper
490+ anchors.fill: parent
491+ source: root.background
492+ // Make sure it's the lowest item. Due to the left edge drag we sometimes need
493+ // to put the dash at -1 and we don't want it behind the Wallpaper
494+ z: -2
495+ }
496+
497+ Spread {
498+ id: spreadItem
499+ objectName: "spreadItem"
500+ anchors.fill: appContainer
501+ leftMargin: root.leftMargin
502+ model: root.topLevelSurfaceList
503+ spreadFlickable: floatingFlickable
504+ z: 10
505+
506+ onLeaveSpread: {
507+ priv.goneToSpread = false;
508+ }
509+ }
510+
511+ Connections {
512+ target: root.topLevelSurfaceList
513+ onListChanged: priv.updateMainAndSideStageIndexes()
514+ }
515+
516+
517+ DropArea {
518+ objectName: "MainStageDropArea"
519+ anchors {
520+ left: parent.left
521+ top: parent.top
522+ bottom: parent.bottom
523+ }
524+ width: appContainer.width - sideStage.width
525+ enabled: sideStage.enabled
526+
527+ onDropped: {
528+ drop.source.appDelegate.saveStage(ApplicationInfoInterface.MainStage);
529+ drop.source.appDelegate.focus = true;
530+ }
531+ keys: "SideStage"
532+ }
533+
534+ SideStage {
535+ id: sideStage
536+ objectName: "sideStage"
537+ shown: false
538+ height: appContainer.height
539+ x: appContainer.width - width
540+ visible: false
541+ Behavior on opacity { UbuntuNumberAnimation {} }
542+ z: {
543+ if (!priv.mainStageItemId) return 0;
544+
545+ if (priv.sideStageItemId && priv.nextInStack > 0) {
546+
547+ // Due the order in which bindings are evaluated, this might be triggered while shuffling
548+ // the list and index doesn't yet match with itemIndex (even though itemIndex: index)
549+ // Let's walk the list and compare itemIndex to make sure we have the correct one.
550+ var nextDelegateInStack = -1;
551+ for (var i = 0; i < appRepeater.count; i++) {
552+ if (appRepeater.itemAt(i).itemIndex == priv.nextInStack) {
553+ nextDelegateInStack = appRepeater.itemAt(i);
554+ break;
555+ }
556+ }
557+
558+ if (nextDelegateInStack.stage === ApplicationInfoInterface.MainStage) {
559+ // if the next app in stack is a main stage app, put the sidestage on top of it.
560+ return 2;
561+ }
562+ return 1;
563+ }
564+
565+ return 1;
566+ }
567+
568+ onShownChanged: {
569+ if (!shown && priv.mainStageDelegate) {
570+ priv.mainStageDelegate.claimFocus();
571+ }
572+ }
573+
574+ DropArea {
575+ id: sideStageDropArea
576+ objectName: "SideStageDropArea"
577+ anchors.fill: parent
578+
579+ property bool dropAllowed: true
580+
581+ onEntered: {
582+ dropAllowed = drag.keys != "Disabled";
583+ }
584+ onExited: {
585+ dropAllowed = true;
586+ }
587+ onDropped: {
588+ if (drop.keys == "MainStage") {
589+ drop.source.appDelegate.saveStage(ApplicationInfoInterface.SideStage);
590+ drop.source.appDelegate.focus = true;
591+ }
592+ }
593+ drag {
594+ onSourceChanged: {
595+ if (!sideStageDropArea.drag.source) {
596+ dropAllowed = true;
597+ }
598+ }
599+ }
600+ }
601+ }
602+
603+ TopLevelSurfaceRepeater {
604+ id: appRepeater
605+ model: topLevelSurfaceList
606+ objectName: "appRepeater"
607+
608+ delegate: FocusScope {
609+ id: appDelegate
610+ objectName: "appDelegate_" + model.id
611+ property int itemIndex: index // We need this from outside the repeater
612+ // z might be overriden in some cases by effects, but we need z ordering
613+ // to calculate occlusion detection
614+ property int normalZ: topLevelSurfaceList.count - index
615+ onNormalZChanged: {
616+ if (visuallyMaximized) {
617+ priv.updateForegroundMaximizedApp();
618+ }
619+ }
620+ z: normalZ
621+
622+ // Normally we want x/y where we request it to be. Width/height of our delegate will
623+ // match what the actual surface size is.
624+ // Don't write to those, they will be set by states
625+ x: requestedX
626+ y: requestedY
627+ width: decoratedWindow.implicitWidth
628+ height: decoratedWindow.implicitHeight
629+
630+ // requestedX/Y/width/height is what we ask the actual surface to be.
631+ // Do not write to those, they will be set by states
632+ property real requestedX: windowedX
633+ property real requestedY: windowedY
634+ property real requestedWidth: windowedWidth
635+ property real requestedHeight: windowedHeight
636+
637+ // In those are for windowed mode. Those values basically store the window's properties
638+ // when having a floating window. If you want to move/resize a window in normal mode, this is what you want to write to.
639+ property real windowedX
640+ property real windowedY
641+ property real windowedWidth
642+ property real windowedHeight
643+
644+ // unlike windowedX/Y, this is the last known grab position before being pushed against edges/corners
645+ // when restoring, the window should return to these, not to the place where it was dropped near the edge
646+ property real restoredX
647+ property real restoredY
648+
649+ Binding {
650+ target: appDelegate
651+ property: "y"
652+ value: appDelegate.requestedY -
653+ Math.min(appDelegate.requestedY - PanelState.panelHeight,
654+ Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
655+ when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
656+ && root.inputMethodRect.height > 0
657+
658+ }
659+
660+ Behavior on x { id: xBehavior; enabled: priv.closingIndex >= 0; UbuntuNumberAnimation { onRunningChanged: if (!running) priv.closingIndex = -1} }
661+
662+ Connections {
663+ target: root
664+ onShellOrientationAngleChanged: {
665+ // at this point decoratedWindow.surfaceOrientationAngle is the old shellOrientationAngle
666+ if (application && application.rotatesWindowContents) {
667+ if (root.state == "windowed") {
668+ var angleDiff = decoratedWindow.surfaceOrientationAngle - shellOrientationAngle;
669+ angleDiff = (360 + angleDiff) % 360;
670+ if (angleDiff === 90 || angleDiff === 270) {
671+ var aux = decoratedWindow.requestedHeight;
672+ decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.decorationHeight;
673+ decoratedWindow.requestedWidth = aux - decoratedWindow.decorationHeight;
674+ }
675+ }
676+ decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
677+ } else {
678+ decoratedWindow.surfaceOrientationAngle = 0;
679+ }
680+ }
681+ }
682+ Connections {
683+ target: priv
684+ onSideStageEnabledChanged: refreshStage()
685+ }
686+
687+ readonly property alias application: decoratedWindow.application
688+ readonly property alias minimumWidth: decoratedWindow.minimumWidth
689+ readonly property alias minimumHeight: decoratedWindow.minimumHeight
690+ readonly property alias maximumWidth: decoratedWindow.maximumWidth
691+ readonly property alias maximumHeight: decoratedWindow.maximumHeight
692+ readonly property alias widthIncrement: decoratedWindow.widthIncrement
693+ readonly property alias heightIncrement: decoratedWindow.heightIncrement
694+
695+ readonly property bool maximized: windowState === WindowStateStorage.WindowStateMaximized
696+ readonly property bool maximizedLeft: windowState === WindowStateStorage.WindowStateMaximizedLeft
697+ readonly property bool maximizedRight: windowState === WindowStateStorage.WindowStateMaximizedRight
698+ readonly property bool maximizedHorizontally: windowState === WindowStateStorage.WindowStateMaximizedHorizontally
699+ readonly property bool maximizedVertically: windowState === WindowStateStorage.WindowStateMaximizedVertically
700+ readonly property bool maximizedTopLeft: windowState === WindowStateStorage.WindowStateMaximizedTopLeft
701+ readonly property bool maximizedTopRight: windowState === WindowStateStorage.WindowStateMaximizedTopRight
702+ readonly property bool maximizedBottomLeft: windowState === WindowStateStorage.WindowStateMaximizedBottomLeft
703+ readonly property bool maximizedBottomRight: windowState === WindowStateStorage.WindowStateMaximizedBottomRight
704+ readonly property bool anyMaximized: maximized || maximizedLeft || maximizedRight || maximizedHorizontally || maximizedVertically ||
705+ maximizedTopLeft || maximizedTopRight || maximizedBottomLeft || maximizedBottomRight
706+
707+ readonly property bool minimized: windowState & WindowStateStorage.WindowStateMinimized
708+ readonly property bool fullscreen: surface ? surface.state === Mir.FullscreenState : application.fullscreen
709+
710+ readonly property bool canBeMaximized: canBeMaximizedHorizontally && canBeMaximizedVertically
711+ readonly property bool canBeMaximizedLeftRight: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
712+ (maximumHeight == 0 || maximumHeight >= appContainer.height)
713+ readonly property bool canBeCornerMaximized: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
714+ (maximumHeight == 0 || maximumHeight >= appContainer.height/2)
715+ readonly property bool canBeMaximizedHorizontally: maximumWidth == 0 || maximumWidth >= appContainer.width
716+ readonly property bool canBeMaximizedVertically: maximumHeight == 0 || maximumHeight >= appContainer.height
717+ readonly property alias orientationChangesEnabled: decoratedWindow.orientationChangesEnabled
718+
719+ property int windowState: WindowStateStorage.WindowStateNormal
720+ property bool animationsEnabled: true
721+ property alias title: decoratedWindow.title
722+ readonly property string appName: model.application ? model.application.name : ""
723+ property bool visuallyMaximized: false
724+ property bool visuallyMinimized: false
725+
726+ property int stage: ApplicationInfoInterface.MainStage
727+ function saveStage(newStage) {
728+ appDelegate.stage = newStage;
729+ WindowStateStorage.saveStage(appId, newStage);
730+ priv.updateMainAndSideStageIndexes()
731+ }
732+
733+ readonly property var surface: model.surface
734+ readonly property alias resizeArea: resizeArea
735+ readonly property alias focusedSurface: decoratedWindow.focusedSurface
736+ readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
737+
738+ readonly property string appId: model.application.appId
739+ readonly property bool isDash: appId == "unity8-dash"
740+ readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
741+
742+ function claimFocus() {
743+ if (root.state == "spread") {
744+ spreadItem.highlightedIndex = index
745+ priv.goneToSpread = false;
746+ }
747+ if (root.mode == "stagedWithSideStage") {
748+ if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
749+ sideStage.show();
750+ }
751+ priv.updateMainAndSideStageIndexes();
752+ }
753+
754+ if (root.mode == "windowed") {
755+ appDelegate.restore(true /* animated */, appDelegate.windowState);
756+ } else {
757+ appDelegate.focus = true;
758+ }
759+ }
760+ Connections {
761+ target: model.surface
762+ onFocusRequested: {
763+ claimFocus();
764+ }
765+ }
766+ Connections {
767+ target: model.application
768+ onFocusRequested: {
769+ if (!model.surface) {
770+ // when an app has no surfaces, we assume there's only one entry representing it:
771+ // this delegate.
772+ claimFocus();
773+ } else {
774+ // if the application has surfaces, focus request should be at surface-level.
775+ }
776+ }
777+ }
778+
779+ onFocusChanged: {
780+ if (appRepeater.startingUp)
781+ return;
782+
783+ if (focus) {
784+ topLevelSurfaceList.raiseId(model.id);
785+ priv.focusedAppDelegate = appDelegate;
786+ } else if (!focus && priv.focusedAppDelegate === appDelegate && root.state != "spread") {
787+ priv.focusedAppDelegate = null;
788+ // FIXME: No idea why the Binding{} doens't update when focusedAppDelegate turns null
789+ MirFocusController.focusedSurface = null;
790+ }
791+ }
792+ Component.onCompleted: {
793+ if (application && application.rotatesWindowContents) {
794+ decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
795+ } else {
796+ decoratedWindow.surfaceOrientationAngle = 0;
797+ }
798+
799+ // First, cascade the newly created window, relative to the currently/old focused window.
800+ windowedX = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedX + units.gu(3) : (normalZ - 1) * units.gu(3)
801+ windowedY = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedY + units.gu(3) : normalZ * units.gu(3)
802+ // Now load any saved state. This needs to happen *after* the cascading!
803+ resizeArea.loadWindowState();
804+
805+ // NB: We're differentiating if this delegate was created in response to a new entry in the model
806+ // or if the Repeater is just populating itself with delegates to match the model it received.
807+ if (!appRepeater.startingUp) {
808+ // a top level window is always the focused one when it first appears, unfocusing
809+ // any preexisting one
810+ if (root.state == "spread") {
811+ spreadItem.highlightedIndex = index;
812+ }
813+ claimFocus();
814+ }
815+
816+ refreshStage();
817+ _constructing = false;
818+ }
819+ Component.onDestruction: {
820+ if (!root.parent) {
821+ // This stage is about to be destroyed. Don't mess up with the model at this point
822+ return;
823+ }
824+
825+ if (visuallyMaximized) {
826+ priv.updateForegroundMaximizedApp();
827+ }
828+
829+ if (focus) {
830+ // focus some other window
831+ for (var i = 0; i < appRepeater.count; i++) {
832+ var appDelegate = appRepeater.itemAt(i);
833+ if (appDelegate && !appDelegate.minimized && i != index) {
834+ appDelegate.focus = true;
835+ return;
836+ }
837+ }
838+ }
839+ }
840+
841+ onVisuallyMaximizedChanged: priv.updateForegroundMaximizedApp()
842+
843+ property bool _constructing: true;
844+ onStageChanged: {
845+ if (!_constructing) {
846+ priv.updateMainAndSideStageIndexes();
847+ }
848+ }
849+
850+ visible: (
851+ !visuallyMinimized
852+ && !greeter.fullyShown
853+ && (priv.foregroundMaximizedAppDelegate === null || priv.foregroundMaximizedAppDelegate.normalZ <= z)
854+ )
855+ || appDelegate.fullscreen
856+ || focusAnimation.running || rightEdgeFocusAnimation.running || hidingAnimation.running
857+
858+ function close() {
859+ model.surface.close();
860+ }
861+
862+ function maximize(animated) {
863+ animationsEnabled = (animated === undefined) || animated;
864+ windowState = WindowStateStorage.WindowStateMaximized;
865+ }
866+ function maximizeLeft(animated) {
867+ animationsEnabled = (animated === undefined) || animated;
868+ windowState = WindowStateStorage.WindowStateMaximizedLeft;
869+ }
870+ function maximizeRight(animated) {
871+ animationsEnabled = (animated === undefined) || animated;
872+ windowState = WindowStateStorage.WindowStateMaximizedRight;
873+ }
874+ function maximizeHorizontally(animated) {
875+ animationsEnabled = (animated === undefined) || animated;
876+ windowState = WindowStateStorage.WindowStateMaximizedHorizontally;
877+ }
878+ function maximizeVertically(animated) {
879+ animationsEnabled = (animated === undefined) || animated;
880+ windowState = WindowStateStorage.WindowStateMaximizedVertically;
881+ }
882+ function maximizeTopLeft(animated) {
883+ animationsEnabled = (animated === undefined) || animated;
884+ windowState = WindowStateStorage.WindowStateMaximizedTopLeft;
885+ }
886+ function maximizeTopRight(animated) {
887+ animationsEnabled = (animated === undefined) || animated;
888+ windowState = WindowStateStorage.WindowStateMaximizedTopRight;
889+ }
890+ function maximizeBottomLeft(animated) {
891+ animationsEnabled = (animated === undefined) || animated;
892+ windowState = WindowStateStorage.WindowStateMaximizedBottomLeft;
893+ }
894+ function maximizeBottomRight(animated) {
895+ animationsEnabled = (animated === undefined) || animated;
896+ windowState = WindowStateStorage.WindowStateMaximizedBottomRight;
897+ }
898+ function minimize(animated) {
899+ animationsEnabled = (animated === undefined) || animated;
900+ windowState |= WindowStateStorage.WindowStateMinimized; // add the minimized bit
901+ }
902+ function restoreFromMaximized(animated) {
903+ animationsEnabled = (animated === undefined) || animated;
904+ windowState = WindowStateStorage.WindowStateRestored;
905+ }
906+ function restore(animated,state) {
907+ animationsEnabled = (animated === undefined) || animated;
908+ windowState = state || WindowStateStorage.WindowStateRestored;
909+ windowState &= ~WindowStateStorage.WindowStateMinimized; // clear the minimized bit
910+ focus = true;
911+ }
912+
913+ function playFocusAnimation() {
914+ if (state == "stagedRightEdge") {
915+ // TODO: Can we drop this if and find something that always works?
916+ if (root.mode == "staged") {
917+ rightEdgeFocusAnimation.targetX = 0
918+ rightEdgeFocusAnimation.start()
919+ } else if (root.mode == "stagedWithSideStage") {
920+ rightEdgeFocusAnimation.targetX = appDelegate.stage == ApplicationInfoInterface.SideStage ? sideStage.x : 0
921+ rightEdgeFocusAnimation.start()
922+ }
923+ } else if (state == "windowedRightEdge" || state == "windowed") {
924+ claimFocus();
925+ } else {
926+ focusAnimation.start()
927+ }
928+ }
929+ function playHidingAnimation() {
930+ if (state != "windowedRightEdge") {
931+ hidingAnimation.start()
932+ }
933+ }
934+
935+ function refreshStage() {
936+ var newStage = ApplicationInfoInterface.MainStage;
937+ if (priv.sideStageEnabled) { // we're in lanscape rotation.
938+ if (!isDash && application && application.supportedOrientations & (Qt.PortraitOrientation|Qt.InvertedPortraitOrientation)) {
939+ var defaultStage = ApplicationInfoInterface.SideStage; // if application supports portrait, it defaults to sidestage.
940+ if (application.supportedOrientations & (Qt.LandscapeOrientation|Qt.InvertedLandscapeOrientation)) {
941+ // if it supports lanscape, it defaults to mainstage.
942+ defaultStage = ApplicationInfoInterface.MainStage;
943+ }
944+ newStage = WindowStateStorage.getStage(application.appId, defaultStage);
945+ }
946+ }
947+
948+ stage = newStage;
949+ if (focus && stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
950+ sideStage.show();
951+ }
952+ }
953+
954+ UbuntuNumberAnimation {
955+ id: focusAnimation
956+ target: appDelegate
957+ property: "scale"
958+ from: 0.98
959+ to: 1
960+ duration: UbuntuAnimation.SnapDuration
961+ onStarted: {
962+ topLevelSurfaceList.raiseId(model.id);
963+ }
964+ onStopped: {
965+ appDelegate.claimFocus();
966+ }
967+ }
968+ ParallelAnimation {
969+ id: rightEdgeFocusAnimation
970+ property int targetX: 0
971+ UbuntuNumberAnimation { target: appDelegate; properties: "x"; to: rightEdgeFocusAnimation.targetX; duration: priv.animationDuration }
972+ UbuntuNumberAnimation { target: decoratedWindow; properties: "angle"; to: 0; duration: priv.animationDuration }
973+ UbuntuNumberAnimation { target: decoratedWindow; properties: "itemScale"; to: 1; duration: priv.animationDuration }
974+ onStopped: {
975+ appDelegate.focus = true
976+ }
977+ }
978+ ParallelAnimation {
979+ id: hidingAnimation
980+ UbuntuNumberAnimation { target: appDelegate; property: "opacity"; to: 0; duration: priv.animationDuration }
981+ onStopped: appDelegate.opacity = 1
982+ }
983+
984+ SpreadMaths {
985+ id: spreadMaths
986+ spread: spreadItem
987+ itemIndex: index
988+ flickable: floatingFlickable
989+ }
990+ StageMaths {
991+ id: stageMaths
992+ sceneWidth: root.width
993+ stage: appDelegate.stage
994+ thisDelegate: appDelegate
995+ mainStageDelegate: priv.mainStageDelegate
996+ sideStageDelegate: priv.sideStageDelegate
997+ sideStageWidth: sideStage.panelWidth
998+ sideStageX: sideStage.x
999+ itemIndex: appDelegate.itemIndex
1000+ nextInStack: priv.nextInStack
1001+ leftEdgeDragProgress: root.leftEdgeDragProgress
1002+ }
1003+
1004+ StagedRightEdgeMaths {
1005+ id: stagedRightEdgeMaths
1006+ sceneWidth: appContainer.width - root.leftMargin
1007+ sceneHeight: appContainer.height
1008+ isMainStageApp: priv.mainStageDelegate == appDelegate
1009+ isSideStageApp: priv.sideStageDelegate == appDelegate
1010+ sideStageWidth: sideStage.width
1011+ sideStageOpen: sideStage.shown
1012+ itemIndex: index
1013+ nextInStack: priv.nextInStack
1014+ progress: 0
1015+ targetHeight: spreadItem.stackHeight
1016+ targetX: spreadMaths.targetX
1017+ startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1018+ targetY: spreadMaths.targetY
1019+ targetAngle: spreadMaths.targetAngle
1020+ targetScale: spreadMaths.targetScale
1021+ shuffledZ: stageMaths.itemZ
1022+ breakPoint: spreadItem.rightEdgeBreakPoint
1023+ }
1024+
1025+ WindowedRightEdgeMaths {
1026+ id: windowedRightEdgeMaths
1027+ itemIndex: index
1028+ startWidth: appDelegate.requestedWidth
1029+ startHeight: appDelegate.requestedHeight
1030+ targetHeight: spreadItem.stackHeight
1031+ targetX: spreadMaths.targetX
1032+ targetY: spreadMaths.targetY
1033+ normalZ: appDelegate.normalZ
1034+ targetAngle: spreadMaths.targetAngle
1035+ targetScale: spreadMaths.targetScale
1036+ breakPoint: spreadItem.rightEdgeBreakPoint
1037+ }
1038+
1039+ states: [
1040+ State {
1041+ name: "spread"; when: root.state == "spread"
1042+ PropertyChanges {
1043+ target: decoratedWindow;
1044+ showDecoration: false;
1045+ angle: spreadMaths.targetAngle
1046+ itemScale: spreadMaths.targetScale
1047+ scaleToPreviewSize: spreadItem.stackHeight
1048+ scaleToPreviewProgress: 1
1049+ hasDecoration: root.mode === "windowed"
1050+ shadowOpacity: spreadMaths.shadowOpacity
1051+ showHighlight: spreadItem.highlightedIndex === index
1052+ darkening: spreadItem.highlightedIndex >= 0
1053+ anchors.topMargin: dragArea.distance
1054+ }
1055+ PropertyChanges {
1056+ target: appDelegate
1057+ x: spreadMaths.targetX
1058+ y: spreadMaths.targetY
1059+ z: index
1060+ height: spreadItem.spreadItemHeight
1061+ requestedWidth: decoratedWindow.oldRequestedWidth
1062+ requestedHeight: decoratedWindow.oldRequestedHeight
1063+ visible: spreadMaths.itemVisible
1064+ }
1065+ PropertyChanges { target: dragArea; enabled: true }
1066+ PropertyChanges { target: windowInfoItem; opacity: spreadMaths.tileInfoOpacity; visible: spreadMaths.itemVisible }
1067+ },
1068+ State {
1069+ name: "stagedRightEdge"
1070+ when: (root.mode == "staged" || root.mode == "stagedWithSideStage") && (root.state == "sideStagedRightEdge" || root.state == "stagedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running)
1071+ PropertyChanges {
1072+ target: stagedRightEdgeMaths
1073+ progress: Math.max(edgeBarrier.progress, rightEdgeDragArea.draggedProgress)
1074+ }
1075+ PropertyChanges {
1076+ target: appDelegate
1077+ x: stagedRightEdgeMaths.animatedX
1078+ y: stagedRightEdgeMaths.animatedY
1079+ z: stagedRightEdgeMaths.animatedZ
1080+ height: stagedRightEdgeMaths.animatedHeight
1081+ requestedWidth: decoratedWindow.oldRequestedWidth
1082+ requestedHeight: decoratedWindow.oldRequestedHeight
1083+ visible: appDelegate.x < root.width
1084+ }
1085+ PropertyChanges {
1086+ target: decoratedWindow
1087+ hasDecoration: false
1088+ angle: stagedRightEdgeMaths.animatedAngle
1089+ itemScale: stagedRightEdgeMaths.animatedScale
1090+ scaleToPreviewSize: spreadItem.stackHeight
1091+ scaleToPreviewProgress: stagedRightEdgeMaths.scaleToPreviewProgress
1092+ shadowOpacity: .3
1093+ }
1094+ },
1095+ State {
1096+ name: "windowedRightEdge"
1097+ when: root.mode == "windowed" && (root.state == "windowedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running || edgeBarrier.progress > 0)
1098+ PropertyChanges {
1099+ target: windowedRightEdgeMaths
1100+ progress: Math.max(rightEdgeDragArea.progress, edgeBarrier.progress)
1101+ }
1102+ PropertyChanges {
1103+ target: appDelegate
1104+ x: windowedRightEdgeMaths.animatedX
1105+ y: windowedRightEdgeMaths.animatedY
1106+ z: windowedRightEdgeMaths.animatedZ
1107+ height: stagedRightEdgeMaths.animatedHeight
1108+ requestedWidth: decoratedWindow.oldRequestedWidth
1109+ requestedHeight: decoratedWindow.oldRequestedHeight
1110+ }
1111+ PropertyChanges {
1112+ target: decoratedWindow
1113+ showDecoration: windowedRightEdgeMaths.decorationHeight
1114+ angle: windowedRightEdgeMaths.animatedAngle
1115+ itemScale: windowedRightEdgeMaths.animatedScale
1116+ scaleToPreviewSize: spreadItem.stackHeight
1117+ scaleToPreviewProgress: windowedRightEdgeMaths.scaleToPreviewProgress
1118+ shadowOpacity: .3
1119+ }
1120+ PropertyChanges {
1121+ target: opacityEffect;
1122+ opacityValue: windowedRightEdgeMaths.opacityMask
1123+ sourceItem: windowedRightEdgeMaths.opacityMask < 1 ? decoratedWindow : null
1124+ }
1125+ },
1126+ State {
1127+ name: "staged"; when: root.state == "staged"
1128+ PropertyChanges {
1129+ target: appDelegate
1130+ x: stageMaths.itemX
1131+ y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1132+ requestedWidth: appContainer.width
1133+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1134+ visuallyMaximized: true
1135+ visible: appDelegate.x < root.width
1136+ }
1137+ PropertyChanges {
1138+ target: decoratedWindow
1139+ hasDecoration: false
1140+ }
1141+ PropertyChanges {
1142+ target: resizeArea
1143+ enabled: false
1144+ }
1145+ PropertyChanges {
1146+ target: stageMaths
1147+ animateX: !focusAnimation.running && itemIndex !== spreadItem.highlightedIndex
1148+ }
1149+ },
1150+ State {
1151+ name: "stagedWithSideStage"; when: root.state == "stagedWithSideStage"
1152+ PropertyChanges {
1153+ target: stageMaths
1154+ itemIndex: index
1155+ }
1156+ PropertyChanges {
1157+ target: appDelegate
1158+ x: stageMaths.itemX
1159+ y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1160+ z: stageMaths.itemZ
1161+ requestedWidth: stageMaths.itemWidth
1162+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1163+ visuallyMaximized: true
1164+ visible: appDelegate.x < root.width
1165+ }
1166+ PropertyChanges {
1167+ target: decoratedWindow
1168+ hasDecoration: false
1169+ }
1170+ PropertyChanges {
1171+ target: resizeArea
1172+ enabled: false
1173+ }
1174+ },
1175+ State {
1176+ name: "maximized"; when: appDelegate.windowState == WindowStateStorage.WindowStateMaximized
1177+ PropertyChanges {
1178+ target: appDelegate;
1179+ requestedX: root.leftMargin;
1180+ requestedY: 0;
1181+ visuallyMinimized: false;
1182+ visuallyMaximized: true
1183+ requestedWidth: appContainer.width - root.leftMargin;
1184+ requestedHeight: appContainer.height;
1185+ }
1186+ PropertyChanges { target: touchControls; enabled: true }
1187+ },
1188+ State {
1189+ name: "fullscreen"; when: appDelegate.fullscreen && !appDelegate.minimized
1190+ PropertyChanges {
1191+ target: appDelegate;
1192+ requestedX: 0
1193+ requestedY: 0
1194+ requestedWidth: appContainer.width;
1195+ requestedHeight: appContainer.height;
1196+ }
1197+ PropertyChanges { target: decoratedWindow; hasDecoration: false }
1198+ },
1199+ State {
1200+ name: "normal";
1201+ when: appDelegate.windowState == WindowStateStorage.WindowStateNormal
1202+ PropertyChanges {
1203+ target: appDelegate
1204+ visuallyMinimized: false
1205+ visuallyMaximized: false
1206+ }
1207+ PropertyChanges { target: touchControls; enabled: true }
1208+ PropertyChanges { target: resizeArea; enabled: true }
1209+ PropertyChanges { target: decoratedWindow; shadowOpacity: .3}
1210+ },
1211+ State {
1212+ name: "restored";
1213+ when: appDelegate.windowState == WindowStateStorage.WindowStateRestored
1214+ extend: "normal"
1215+ PropertyChanges {
1216+ target: appDelegate;
1217+ windowedX: restoredX;
1218+ windowedY: restoredY;
1219+ }
1220+ },
1221+ State {
1222+ name: "semiMaximized"
1223+ PropertyChanges { target: touchControls; enabled: true }
1224+ PropertyChanges { target: resizeArea; enabled: true }
1225+ PropertyChanges { target: decoratedWindow; shadowOpacity: .3 }
1226+ },
1227+ State {
1228+ name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
1229+ extend: "semiMaximized"
1230+ PropertyChanges {
1231+ target: appDelegate
1232+ windowedX: root.leftMargin
1233+ windowedY: PanelState.panelHeight
1234+ windowedWidth: (appContainer.width - root.leftMargin)/2
1235+ windowedHeight: appContainer.height - PanelState.panelHeight
1236+ }
1237+ },
1238+ State {
1239+ name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
1240+ extend: "maximizedLeft"
1241+ PropertyChanges {
1242+ target: appDelegate;
1243+ windowedX: (appContainer.width + root.leftMargin)/2
1244+ }
1245+ },
1246+ State {
1247+ name: "maximizedTopLeft"; when: appDelegate.maximizedTopLeft && !appDelegate.minimized
1248+ extend: "semiMaximized"
1249+ PropertyChanges {
1250+ target: appDelegate
1251+ windowedX: root.leftMargin
1252+ windowedY: PanelState.panelHeight
1253+ windowedWidth: (appContainer.width - root.leftMargin)/2
1254+ windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1255+ }
1256+ },
1257+ State {
1258+ name: "maximizedTopRight"; when: appDelegate.maximizedTopRight && !appDelegate.minimized
1259+ extend: "maximizedTopLeft"
1260+ PropertyChanges {
1261+ target: appDelegate
1262+ windowedX: (appContainer.width + root.leftMargin)/2
1263+ }
1264+ },
1265+ State {
1266+ name: "maximizedBottomLeft"; when: appDelegate.maximizedBottomLeft && !appDelegate.minimized
1267+ extend: "semiMaximized"
1268+ PropertyChanges {
1269+ target: appDelegate
1270+ windowedX: root.leftMargin
1271+ windowedY: (appContainer.height + PanelState.panelHeight)/2
1272+ windowedWidth: (appContainer.width - root.leftMargin)/2
1273+ windowedHeight: appContainer.height/2
1274+ }
1275+ },
1276+ State {
1277+ name: "maximizedBottomRight"; when: appDelegate.maximizedBottomRight && !appDelegate.minimized
1278+ extend: "maximizedBottomLeft"
1279+ PropertyChanges {
1280+ target: appDelegate
1281+ windowedX: (appContainer.width + root.leftMargin)/2
1282+ }
1283+ },
1284+ State {
1285+ name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
1286+ extend: "semiMaximized"
1287+ PropertyChanges { target: appDelegate; requestedX: root.leftMargin; requestedY: windowedY;
1288+ requestedWidth: appContainer.width - root.leftMargin; requestedHeight: appDelegate.windowedHeight }
1289+ },
1290+ State {
1291+ name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
1292+ extend: "semiMaximized"
1293+ PropertyChanges { target: appDelegate; requestedX: windowedX; requestedY: PanelState.panelHeight;
1294+ requestedWidth: appDelegate.windowedWidth; requestedHeight: appContainer.height - PanelState.panelHeight }
1295+ },
1296+ State {
1297+ name: "minimized"; when: appDelegate.minimized
1298+ PropertyChanges {
1299+ target: appDelegate
1300+ requestedX: -appDelegate.width / 2
1301+ scale: units.gu(5) / appDelegate.width
1302+ opacity: 0;
1303+ visuallyMinimized: true
1304+ visuallyMaximized: false
1305+ }
1306+ }
1307+ ]
1308+ transitions: [
1309+ Transition {
1310+ from: "staged,stagedWithSideStage"; to: "normal"
1311+ enabled: appDelegate.animationsEnabled
1312+ PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
1313+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,opacity,requestedWidth,requestedHeight,scale"; duration: priv.animationDuration }
1314+ },
1315+ Transition {
1316+ from: "normal,maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight";
1317+ to: "staged,stagedWithSideStage"
1318+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,requestedWidth,requestedHeight"; duration: priv.animationDuration}
1319+ },
1320+ Transition {
1321+ from: "maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight,minimized";
1322+ to: "normal,restored"
1323+ enabled: appDelegate.animationsEnabled
1324+ PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
1325+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,windowedX,windowedY,requestedWidth,requestedHeight,windowedWidth,windowedHeight,scale";
1326+ duration: priv.animationDuration }
1327+ },
1328+ Transition {
1329+ to: "minimized"
1330+ enabled: appDelegate.animationsEnabled
1331+ PropertyAction { target: appDelegate; property: "visuallyMaximized" }
1332+ SequentialAnimation {
1333+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,opacity,scale,requestedWidth,requestedHeight" }
1334+ PropertyAction { target: appDelegate; property: "visuallyMinimized" }
1335+ ScriptAction {
1336+ script: {
1337+ if (appDelegate.minimized) {
1338+ appDelegate.focus = false;
1339+ priv.focusNext();
1340+ }
1341+ }
1342+ }
1343+ }
1344+ },
1345+ Transition {
1346+ to: "spread"
1347+ // DecoratedWindow wants the scaleToPreviewSize set before enabling scaleToPreview
1348+ PropertyAction { target: appDelegate; properties: "z,visible" }
1349+ PropertyAction { target: decoratedWindow; property: "scaleToPreviewSize" }
1350+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,height"; duration: priv.animationDuration }
1351+ UbuntuNumberAnimation { target: decoratedWindow; properties: "width,height,itemScale,angle,scaleToPreviewProgress"; duration: priv.animationDuration }
1352+ },
1353+ Transition {
1354+ from: "normal,staged"; to: "stagedWithSideStage"
1355+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y"; duration: priv.animationDuration }
1356+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedWidth,requestedHeight"; duration: priv.animationDuration }
1357+ },
1358+ Transition {
1359+ to: "windowedRightEdge"
1360+ ScriptAction {
1361+ script: {
1362+ windowedRightEdgeMaths.startX = appDelegate.requestedX
1363+ windowedRightEdgeMaths.startY = appDelegate.requestedY
1364+
1365+ if (index == 1) {
1366+ var thisRect = { x: appDelegate.windowedX, y: appDelegate.windowedY, width: appDelegate.requestedWidth, height: appDelegate.requestedHeight }
1367+ var otherDelegate = appRepeater.itemAt(0);
1368+ var otherRect = { x: otherDelegate.windowedX, y: otherDelegate.windowedY, width: otherDelegate.requestedWidth, height: otherDelegate.requestedHeight }
1369+ var intersectionRect = MathUtils.intersectionRect(thisRect, otherRect)
1370+ var mappedInterSectionRect = appDelegate.mapFromItem(root, intersectionRect.x, intersectionRect.y)
1371+ opacityEffect.maskX = mappedInterSectionRect.x
1372+ opacityEffect.maskY = mappedInterSectionRect.y
1373+ opacityEffect.maskWidth = intersectionRect.width
1374+ opacityEffect.maskHeight = intersectionRect.height
1375+ }
1376+ }
1377+ }
1378+ },
1379+ Transition {
1380+ from: "stagedRightEdge"; to: "staged"
1381+ enabled: rightEdgeDragArea.cancelled // only transition back to state if the gesture was cancelled, in the other cases we play the focusAnimations.
1382+ SequentialAnimation {
1383+ ParallelAnimation {
1384+ UbuntuNumberAnimation { target: appDelegate; properties: "x,y,height,width,scale"; duration: priv.animationDuration }
1385+ UbuntuNumberAnimation { target: decoratedWindow; properties: "width,height,itemScale,angle,scaleToPreviewProgress"; duration: priv.animationDuration }
1386+ }
1387+ // We need to release scaleToPreviewSize at last
1388+ PropertyAction { target: decoratedWindow; property: "scaleToPreviewSize" }
1389+ PropertyAction { target: appDelegate; property: "visible" }
1390+ }
1391+ },
1392+ Transition {
1393+ from: "normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTop,maximizedBottom,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
1394+ to: "normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTop,maximizedBottom,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
1395+ enabled: appDelegate.animationsEnabled
1396+ SequentialAnimation {
1397+ PropertyAction { target: appDelegate; property: "visuallyMinimized" }
1398+ UbuntuNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,windowedX,windowedY,opacity,scale,requestedWidth,requestedHeight,windowedWidth,windowedHeight";
1399+ duration: priv.animationDuration }
1400+ PropertyAction { target: appDelegate; property: "visuallyMaximized" }
1401+ ScriptAction { script: { fakeRectangle.stop(); } }
1402+ }
1403+ }
1404+ ]
1405+
1406+ Binding {
1407+ target: PanelState
1408+ property: "buttonsAlwaysVisible"
1409+ value: appDelegate && appDelegate.maximized && touchControls.overlayShown
1410+ }
1411+
1412+ WindowResizeArea {
1413+ id: resizeArea
1414+ objectName: "windowResizeArea"
1415+
1416+ // workaround so that it chooses the correct resize borders when you drag from a corner ResizeGrip
1417+ anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
1418+
1419+ target: appDelegate
1420+ minWidth: units.gu(10)
1421+ minHeight: units.gu(10)
1422+ borderThickness: units.gu(2)
1423+ windowId: model.application.appId // FIXME: Change this to point to windowId once we have such a thing
1424+ screenWidth: appContainer.width
1425+ screenHeight: appContainer.height
1426+ leftMargin: root.leftMargin
1427+ enabled: false
1428+ visible: enabled
1429+
1430+ onPressed: {
1431+ appDelegate.focus = true;
1432+ }
1433+
1434+ Component.onDestruction: {
1435+ saveWindowState();
1436+ }
1437+ }
1438+
1439+ DecoratedWindow {
1440+ id: decoratedWindow
1441+ objectName: "decoratedWindow"
1442+ anchors.left: appDelegate.left
1443+ anchors.top: appDelegate.top
1444+ application: model.application
1445+ surface: model.surface
1446+ active: appDelegate.focus
1447+ focus: true
1448+ interactive: root.interactive
1449+ showDecoration: 1
1450+ maximizeButtonShown: appDelegate.canBeMaximized
1451+ overlayShown: touchControls.overlayShown
1452+ width: implicitWidth
1453+ height: implicitHeight
1454+ highlightSize: windowInfoItem.iconMargin / 2
1455+ stageWidth: appContainer.width
1456+ stageHeight: appContainer.height
1457+
1458+ requestedWidth: appDelegate.requestedWidth
1459+ requestedHeight: appDelegate.requestedHeight
1460+
1461+ property int oldRequestedWidth: -1
1462+ property int oldRequestedHeight: -1
1463+
1464+ onRequestedWidthChanged: oldRequestedWidth = requestedWidth
1465+ onRequestedHeightChanged: oldRequestedHeight = requestedHeight
1466+
1467+ onCloseClicked: { appDelegate.close(); }
1468+ onMaximizeClicked: appDelegate.anyMaximized ? appDelegate.restoreFromMaximized() : appDelegate.maximize();
1469+ onMaximizeHorizontallyClicked: appDelegate.maximizedHorizontally ? appDelegate.restoreFromMaximized() : appDelegate.maximizeHorizontally()
1470+ onMaximizeVerticallyClicked: appDelegate.maximizedVertically ? appDelegate.restoreFromMaximized() : appDelegate.maximizeVertically()
1471+ onMinimizeClicked: appDelegate.minimize()
1472+ onDecorationPressed: { appDelegate.focus = true; }
1473+ onDecorationReleased: fakeRectangle.commit();
1474+
1475+ property real angle: 0
1476+ property real itemScale: 1
1477+ transform: [
1478+ Scale {
1479+ origin.x: 0
1480+ origin.y: decoratedWindow.implicitHeight / 2
1481+ xScale: decoratedWindow.itemScale
1482+ yScale: decoratedWindow.itemScale
1483+ },
1484+ Rotation {
1485+ origin { x: 0; y: (decoratedWindow.height / 2) }
1486+ axis { x: 0; y: 1; z: 0 }
1487+ angle: decoratedWindow.angle
1488+ }
1489+ ]
1490+ }
1491+
1492+ OpacityMask {
1493+ id: opacityEffect
1494+ anchors.fill: decoratedWindow
1495+ }
1496+
1497+ WindowControlsOverlay {
1498+ id: touchControls
1499+ target: appDelegate
1500+ enabled: false
1501+ visible: enabled
1502+ stageWidth: appContainer.width
1503+ stageHeight: appContainer.height
1504+
1505+ onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
1506+ onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
1507+ onFakeMaximizeRightAnimationRequested: if (!appDelegate.maximizedRight) fakeRectangle.maximizeRight(amount, true)
1508+ onFakeMaximizeTopLeftAnimationRequested: if (!appDelegate.maximizedTopLeft) fakeRectangle.maximizeTopLeft(amount, true);
1509+ onFakeMaximizeTopRightAnimationRequested: if (!appDelegate.maximizedTopRight) fakeRectangle.maximizeTopRight(amount, true);
1510+ onFakeMaximizeBottomLeftAnimationRequested: if (!appDelegate.maximizedBottomLeft) fakeRectangle.maximizeBottomLeft(amount, true);
1511+ onFakeMaximizeBottomRightAnimationRequested: if (!appDelegate.maximizedBottomRight) fakeRectangle.maximizeBottomRight(amount, true);
1512+ onStopFakeAnimation: fakeRectangle.stop();
1513+ onDragReleased: fakeRectangle.commit();
1514+ }
1515+
1516+ WindowedFullscreenPolicy {
1517+ id: windowedFullscreenPolicy
1518+ active: root.mode == "windowed"
1519+ surface: model.surface
1520+ }
1521+ StagedFullscreenPolicy {
1522+ id: stagedFullscreenPolicy
1523+ active: root.mode == "staged" || root.mode == "stagedWithSideStage"
1524+ surface: model.surface
1525+ }
1526+
1527+ SpreadDelegateInputArea {
1528+ id: dragArea
1529+ objectName: "dragArea"
1530+ anchors.fill: decoratedWindow
1531+ enabled: false
1532+ closeable: !appDelegate.isDash
1533+
1534+ onClicked: {
1535+ spreadItem.highlightedIndex = index;
1536+ if (distance == 0) {
1537+ priv.goneToSpread = false;
1538+ }
1539+ }
1540+ onClose: {
1541+ priv.closingIndex = index
1542+ if (model.surface) { // could be stopped by OOM
1543+ model.surface.close()
1544+ } else if (model.application) {
1545+ root.applicationManager.stopApplication(model.application.appId);
1546+ }
1547+ }
1548+ }
1549+
1550+ WindowInfoItem {
1551+ id: windowInfoItem
1552+ objectName: "windowInfoItem"
1553+ anchors { left: parent.left; top: decoratedWindow.bottom; topMargin: units.gu(1) }
1554+ title: model.application.name
1555+ iconSource: model.application.icon
1556+ height: spreadItem.appInfoHeight
1557+ opacity: 0
1558+ z: 1
1559+ visible: opacity > 0
1560+ maxWidth: {
1561+ var nextApp = appRepeater.itemAt(index + 1);
1562+ if (nextApp) {
1563+ return nextApp.x - appDelegate.x - units.gu(1)
1564+ }
1565+ return appDelegate.width;
1566+ }
1567+
1568+ onClicked: {
1569+ spreadItem.highlightedIndex = index;
1570+ priv.goneToSpread = false;
1571+ }
1572+ }
1573+
1574+ Image {
1575+ id: closeImage
1576+ anchors { left: parent.left; top: parent.top; leftMargin: -height / 2; topMargin: -height / 2 + spreadMaths.closeIconOffset }
1577+ source: "graphics/window-close.svg"
1578+ readonly property var mousePos: hoverMouseArea.mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1579+ visible: !appDelegate.isDash && dragArea.distance == 0
1580+ && index == spreadItem.highlightedIndex
1581+ && mousePos.y < (decoratedWindow.height / 3)
1582+ && mousePos.y > -units.gu(4)
1583+ && mousePos.x > -units.gu(4)
1584+ && mousePos.x < (decoratedWindow.width * 2 / 3)
1585+ height: units.gu(2)
1586+ width: height
1587+ sourceSize.width: width
1588+ sourceSize.height: height
1589+
1590+ MouseArea {
1591+ id: closeMouseArea
1592+ objectName: "closeMouseArea"
1593+ anchors.fill: closeImage
1594+ anchors.margins: -units.gu(2)
1595+ onClicked: {
1596+ priv.closingIndex = index;
1597+ appDelegate.close();
1598+ }
1599+ }
1600+ }
1601+ }
1602+ }
1603+ }
1604+
1605+ FakeMaximizeDelegate {
1606+ id: fakeRectangle
1607+ target: priv.focusedAppDelegate
1608+ leftMargin: root.leftMargin
1609+ appContainerWidth: appContainer.width
1610+ appContainerHeight: appContainer.height
1611+ }
1612+
1613+ EdgeBarrier {
1614+ id: edgeBarrier
1615+
1616+ // NB: it does its own positioning according to the specified edge
1617+ edge: Qt.RightEdge
1618+
1619+ onPassed: priv.goneToSpread = true;
1620+
1621+ material: Component {
1622+ Item {
1623+ Rectangle {
1624+ width: parent.height
1625+ height: parent.width
1626+ rotation: 90
1627+ anchors.centerIn: parent
1628+ gradient: Gradient {
1629+ GradientStop { position: 0.0; color: Qt.rgba(0.16,0.16,0.16,0.5)}
1630+ GradientStop { position: 1.0; color: Qt.rgba(0.16,0.16,0.16,0)}
1631+ }
1632+ }
1633+ }
1634+ }
1635+ }
1636+
1637+ MouseArea {
1638+ id: hoverMouseArea
1639+ objectName: "hoverMouseArea"
1640+ anchors.fill: appContainer
1641+ propagateComposedEvents: true
1642+ hoverEnabled: true
1643+ enabled: false
1644+ visible: enabled
1645+
1646+ property int scrollAreaWidth: width / 3
1647+ property bool progressiveScrollingEnabled: false
1648+
1649+ onMouseXChanged: {
1650+ mouse.accepted = false
1651+
1652+ if (hoverMouseArea.pressed) {
1653+ return;
1654+ }
1655+
1656+ // Find the hovered item and mark it active
1657+ var mapped = mapToItem(appContainer, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1658+ var itemUnder = appContainer.childAt(mapped.x, mapped.y)
1659+ if (itemUnder) {
1660+ mapped = mapToItem(itemUnder, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1661+ var delegateChild = itemUnder.childAt(mapped.x, mapped.y)
1662+ if (delegateChild && (delegateChild.objectName === "dragArea" || delegateChild.objectName === "windowInfoItem")) {
1663+ spreadItem.highlightedIndex = appRepeater.indexOf(itemUnder)
1664+ }
1665+ }
1666+
1667+ if (floatingFlickable.contentWidth > floatingFlickable.width) {
1668+ var margins = floatingFlickable.width * 0.05;
1669+
1670+ if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
1671+ progressiveScrollingEnabled = true
1672+ }
1673+
1674+ // do we need to scroll?
1675+ if (mouseX < scrollAreaWidth + margins) {
1676+ var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
1677+ var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
1678+ floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
1679+ }
1680+ if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
1681+ var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
1682+ var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
1683+ floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
1684+ }
1685+ }
1686+ }
1687+
1688+ onPressed: mouse.accepted = false
1689+ }
1690+
1691+ FloatingFlickable {
1692+ id: floatingFlickable
1693+ objectName: "spreadFlickable"
1694+ anchors.fill: appContainer
1695+ enabled: false
1696+ contentWidth: spreadItem.spreadTotalWidth
1697+
1698+ function snap(toIndex) {
1699+ var delegate = appRepeater.itemAt(toIndex)
1700+ var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
1701+ if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
1702+ var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
1703+ snapAnimation.to = floatingFlickable.contentX - offset;
1704+ snapAnimation.start();
1705+ } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
1706+ var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
1707+ snapAnimation.to = floatingFlickable.contentX - offset;
1708+ snapAnimation.start();
1709+ }
1710+ }
1711+ UbuntuNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
1712+ }
1713+
1714+ PropertyAnimation {
1715+ id: shortRightEdgeSwipeAnimation
1716+ property: "x"
1717+ to: 0
1718+ duration: priv.animationDuration
1719+ }
1720+
1721+ SwipeArea {
1722+ id: rightEdgeDragArea
1723+ objectName: "rightEdgeDragArea"
1724+ direction: Direction.Leftwards
1725+ anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
1726+ width: root.dragAreaWidth
1727+
1728+ property var gesturePoints: []
1729+ property bool cancelled: false
1730+
1731+ property real progress: dragging ? -touchPosition.x / root.width : 0
1732+ onProgressChanged: {
1733+ if (dragging) {
1734+ draggedProgress = progress;
1735+ }
1736+ }
1737+
1738+ property real draggedProgress: 0
1739+
1740+ onTouchPositionChanged: {
1741+ gesturePoints.push(touchPosition.x);
1742+ if (gesturePoints.length > 10) {
1743+ gesturePoints.splice(0, gesturePoints.length - 10)
1744+ }
1745+ }
1746+
1747+ onDraggingChanged: {
1748+ if (dragging) {
1749+ // A potential edge-drag gesture has started. Start recording it
1750+ gesturePoints = [];
1751+ cancelled = false;
1752+ draggedProgress = 0;
1753+ } else {
1754+ // Ok. The user released. Did he drag far enough to go to full spread?
1755+ if (gesturePoints[gesturePoints.length - 1] < -spreadItem.rightEdgeBreakPoint * spreadItem.width ) {
1756+
1757+ // He dragged far enough, but if the last movement was a flick to the right again, he wants to cancel the spread again.
1758+ var oneWayFlickToRight = true;
1759+ var smallestX = gesturePoints[0]-1;
1760+ for (var i = 0; i < gesturePoints.length; i++) {
1761+ if (gesturePoints[i] <= smallestX) {
1762+ oneWayFlickToRight = false;
1763+ break;
1764+ }
1765+ smallestX = gesturePoints[i];
1766+ }
1767+
1768+ if (!oneWayFlickToRight) {
1769+ // Ok, the user made it, let's go to spread!
1770+ priv.goneToSpread = true;
1771+ } else {
1772+ cancelled = true;
1773+ }
1774+ } else {
1775+ // Ok, the user didn't drag far enough to cross the breakPoint
1776+ // Find out if it was a one-way movement to the left, in which case we just switch directly to next app.
1777+ var oneWayFlick = true;
1778+ var smallestX = rightEdgeDragArea.width;
1779+ for (var i = 0; i < gesturePoints.length; i++) {
1780+ if (gesturePoints[i] >= smallestX) {
1781+ oneWayFlick = false;
1782+ break;
1783+ }
1784+ smallestX = gesturePoints[i];
1785+ }
1786+
1787+ if (appRepeater.count > 1 &&
1788+ (oneWayFlick && rightEdgeDragArea.distance > units.gu(2) || rightEdgeDragArea.distance > spreadItem.rightEdgeBreakPoint * spreadItem.width)) {
1789+ var nextStage = appRepeater.itemAt(priv.nextInStack).stage
1790+ for (var i = 0; i < appRepeater.count; i++) {
1791+ if (i != priv.nextInStack && appRepeater.itemAt(i).stage == nextStage) {
1792+ appRepeater.itemAt(i).playHidingAnimation()
1793+ break;
1794+ }
1795+ }
1796+ appRepeater.itemAt(priv.nextInStack).playFocusAnimation()
1797+ if (appRepeater.itemAt(priv.nextInStack).stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
1798+ sideStage.show();
1799+ }
1800+
1801+ } else {
1802+ cancelled = true;
1803+ }
1804+
1805+ gesturePoints = [];
1806+ }
1807+ }
1808+ }
1809+ }
1810+
1811+ TabletSideStageTouchGesture {
1812+ id: triGestureArea
1813+ objectName: "triGestureArea"
1814+ anchors.fill: parent
1815+ enabled: false
1816+ property Item appDelegate
1817+
1818+ dragComponent: dragComponent
1819+ dragComponentProperties: { "appDelegate": appDelegate }
1820+
1821+ onPressed: {
1822+ function matchDelegate(obj) { return String(obj.objectName).indexOf("appDelegate") >= 0; }
1823+
1824+ var delegateAtCenter = Functions.itemAt(appContainer, x, y, matchDelegate);
1825+ if (!delegateAtCenter) return;
1826+
1827+ appDelegate = delegateAtCenter;
1828+ }
1829+
1830+ onClicked: {
1831+ if (sideStage.shown) {
1832+ sideStage.hide();
1833+ } else {
1834+ sideStage.show();
1835+ priv.updateMainAndSideStageIndexes()
1836+ }
1837+ }
1838+
1839+ onDragStarted: {
1840+ // If we're dragging to the sidestage.
1841+ if (!sideStage.shown) {
1842+ sideStage.show();
1843+ }
1844+ }
1845+
1846+ Component {
1847+ id: dragComponent
1848+ SurfaceContainer {
1849+ property Item appDelegate
1850+
1851+ surface: appDelegate ? appDelegate.surface : null
1852+
1853+ consumesInput: false
1854+ interactive: false
1855+ focus: false
1856+ requestedWidth: appDelegate.requestedWidth
1857+ requestedHeight: appDelegate.requestedHeight
1858+
1859+ width: units.gu(40)
1860+ height: units.gu(40)
1861+
1862+ Drag.hotSpot.x: width/2
1863+ Drag.hotSpot.y: height/2
1864+ // only accept opposite stage.
1865+ Drag.keys: {
1866+ if (!surface) return "Disabled";
1867+ if (appDelegate.isDash) return "Disabled";
1868+
1869+ if (appDelegate.stage === ApplicationInfo.MainStage) {
1870+ if (appDelegate.application.supportedOrientations
1871+ & (Qt.PortraitOrientation|Qt.InvertedPortraitOrientation)) {
1872+ return "MainStage";
1873+ }
1874+ return "Disabled";
1875+ }
1876+ return "SideStage";
1877+ }
1878+ }
1879+ }
1880+ }
1881+}