Lomiri
Loading...
Searching...
No Matches
Stage.qml
1/*
2 * Copyright (C) 2014-2017 Canonical Ltd.
3 * Copyright (C) 2021 UBports Foundation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.15
19import QtQml 2.15
20import QtQuick.Window 2.2
21import Lomiri.Components 1.3
22import QtMir.Application 0.1
23import "../Components/PanelState"
24import "../Components"
25import Utils 0.1
26import Lomiri.Gestures 0.1
27import GlobalShortcut 1.0
28import GSettings 1.0
29import "Spread"
30import "Spread/MathUtils.js" as MathUtils
31import ProcessControl 0.1
32import WindowManager 1.0
33
34FocusScope {
35 id: root
36 anchors.fill: parent
37
38 property QtObject applicationManager
39 property QtObject topLevelSurfaceList
40 property bool altTabPressed
41 property url background
42 property alias backgroundSourceSize: wallpaper.sourceSize
43 property int dragAreaWidth
44 property real nativeHeight
45 property real nativeWidth
46 property QtObject orientations
47 property int shellOrientation
48 property int shellOrientationAngle
49 property bool spreadEnabled: true // If false, animations and right edge will be disabled
50 property bool suspended
51 property bool oskEnabled: false
52 property rect inputMethodRect
53 property real rightEdgePushProgress: 0
54 property Item availableDesktopArea
55 property PanelState panelState
56
57 // Whether outside forces say that the Stage may have focus
58 property bool allowInteractivity
59
60 readonly property bool interactive: (state === "staged" || state === "stagedWithSideStage" || state === "windowed") && allowInteractivity
61
62 // Configuration
63 property string mode: "staged"
64
65 readonly property var temporarySelectedWorkspace: state == "spread" ? screensAndWorkspaces.activeWorkspace : null
66 property bool workspaceEnabled: (mode == "windowed" && settings.enableWorkspace) || settings.forceEnableWorkspace
67
68 // Used by the tutorial code
69 readonly property real rightEdgeDragProgress: rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0 // How far left the stage has been dragged
70
71 // used by the snap windows (edge maximize) feature
72 readonly property alias previewRectangle: fakeRectangle
73
74 readonly property bool spreadShown: state == "spread"
75 readonly property var mainApp: priv.focusedAppDelegate ? priv.focusedAppDelegate.application : null
76
77 // application windows never rotate independently
78 property int mainAppWindowOrientationAngle: shellOrientationAngle
79
80 property bool orientationChangesEnabled: !priv.focusedAppDelegate || priv.focusedAppDelegate.orientationChangesEnabled
81
82 property int supportedOrientations: {
83 if (mainApp) {
84 switch (mode) {
85 case "staged":
86 return mainApp.supportedOrientations;
87 case "stagedWithSideStage":
88 var orientations = mainApp.supportedOrientations;
89 orientations |= Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation;
90 if (priv.sideStageItemId) {
91 // If we have a sidestage app, support Portrait orientation
92 // so that it will switch the sidestage app to mainstage on rotate to portrait
93 orientations |= Qt.PortraitOrientation|Qt.InvertedPortraitOrientation;
94 }
95 return orientations;
96 }
97 }
98
99 return Qt.PortraitOrientation |
100 Qt.LandscapeOrientation |
101 Qt.InvertedPortraitOrientation |
102 Qt.InvertedLandscapeOrientation;
103 }
104
105 GSettings {
106 id: settings
107 schema.id: "com.lomiri.Shell"
108 }
109
110 property int launcherLeftMargin : 0
111
112 Binding {
113 target: topLevelSurfaceList
114 restoreMode: Binding.RestoreBinding
115 property: "rootFocus"
116 value: interactive
117 }
118
119 onInteractiveChanged: {
120 // Stage must have focus before activating windows, including null
121 if (interactive) {
122 focus = true;
123 }
124 }
125
126 onAltTabPressedChanged: {
127 root.focus = true;
128 if (altTabPressed) {
129 if (root.spreadEnabled) {
130 altTabDelayTimer.start();
131 }
132 } else {
133 // Alt Tab has been released, did we already go to spread?
134 if (priv.goneToSpread) {
135 priv.goneToSpread = false;
136 } else {
137 // No we didn't, do a quick alt-tab
138 if (appRepeater.count > 1) {
139 appRepeater.itemAt(1).activate();
140 } else if (appRepeater.count > 0) {
141 appRepeater.itemAt(0).activate(); // quick alt-tab to the only (minimized) window should still activate it
142 }
143 }
144 }
145 }
146
147 Timer {
148 id: altTabDelayTimer
149 interval: 140
150 repeat: false
151 onTriggered: {
152 if (root.altTabPressed) {
153 priv.goneToSpread = true;
154 }
155 }
156 }
157
158 // For MirAL window management
159 WindowMargins {
160 normal: Qt.rect(0, root.mode === "windowed" ? priv.windowDecorationHeight : 0, 0, 0)
161 dialog: normal
162 }
163
164 property Item itemConfiningMouseCursor: !spreadShown && priv.focusedAppDelegate && priv.focusedAppDelegate.window && priv.focusedAppDelegate.window.confinesMousePointer ?
165 priv.focusedAppDelegate.clientAreaItem : null;
166
167 signal itemSnapshotRequested(Item item)
168
169 // functions to be called from outside
170 function updateFocusedAppOrientation() { /* TODO */ }
171 function updateFocusedAppOrientationAnimated() { /* TODO */}
172
173 function closeSpread() {
174 spreadItem.highlightedIndex = -1;
175 priv.goneToSpread = false;
176 }
177
178 onSpreadEnabledChanged: {
179 if (!spreadEnabled && spreadShown) {
180 closeSpread();
181 }
182 }
183
184 onRightEdgePushProgressChanged: {
185 if (spreadEnabled && rightEdgePushProgress >= 1) {
186 priv.goneToSpread = true
187 }
188 }
189
190 GSettings {
191 id: lifecycleExceptions
192 schema.id: "com.canonical.qtmir"
193 }
194
195 function isExemptFromLifecycle(appId) {
196 var shortAppId = appId.split('_')[0];
197 for (var i = 0; i < lifecycleExceptions.lifecycleExemptAppids.length; i++) {
198 if (shortAppId === lifecycleExceptions.lifecycleExemptAppids[i]) {
199 return true;
200 }
201 }
202 return false;
203 }
204
205 GlobalShortcut {
206 id: closeFocusedShortcut
207 shortcut: Qt.AltModifier|Qt.Key_F4
208 onTriggered: {
209 if (priv.focusedAppDelegate) {
210 priv.focusedAppDelegate.close();
211 }
212 }
213 }
214
215 GlobalShortcut {
216 id: showSpreadShortcut
217 shortcut: Qt.MetaModifier|Qt.Key_W
218 active: root.spreadEnabled
219 onTriggered: priv.goneToSpread = true
220 }
221
222 GlobalShortcut {
223 id: toggleSideStageShortcut
224 shortcut: Qt.MetaModifier|Qt.Key_S
225 active: priv.sideStageEnabled
226 onTriggered: {
227 priv.toggleSideStage()
228 }
229 }
230
231 GlobalShortcut {
232 id: minimizeAllShortcut
233 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_D
234 onTriggered: priv.minimizeAllWindows()
235 active: root.state == "windowed"
236 }
237
238 GlobalShortcut {
239 id: maximizeWindowShortcut
240 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Up
241 onTriggered: priv.focusedAppDelegate.requestMaximize()
242 active: root.state == "windowed" && priv.focusedAppDelegate && priv.focusedAppDelegate.canBeMaximized
243 }
244
245 GlobalShortcut {
246 id: maximizeWindowLeftShortcut
247 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Left
248 onTriggered: {
249 switch (root.mode) {
250 case "stagedWithSideStage":
251 if ( priv.focusedAppDelegate
252 && priv.focusedAppDelegate.stage == ApplicationInfoInterface.SideStage
253 ) {
254 priv.focusedAppDelegate.saveStage(ApplicationInfoInterface.MainStage);
255 priv.focusedAppDelegate.focus = true;
256 }
257 break;
258 case "windowed":
259 if (priv.focusedAppDelegate) {
260 priv.focusedAppDelegate.requestMaximizeLeft();
261 }
262 break;
263 }
264 }
265 active: {
266 switch (root.state) {
267 case "stagedWithSideStage":
268 return priv.focusedAppDelegate
269 && priv.focusedAppDelegate.stage == ApplicationInfoInterface.SideStage
270 && priv.sideStageEnabled;
271 case "windowed":
272 return priv.focusedAppDelegate
273 && priv.focusedAppDelegate.canBeMaximizedLeftRight;
274 default:
275 return false;
276 }
277 }
278 }
279
280 GlobalShortcut {
281 id: maximizeWindowRightShortcut
282 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Right
283 onTriggered: {
284 switch (root.mode) {
285 case "stagedWithSideStage":
286 if ( priv.focusedAppDelegate
287 && priv.focusedAppDelegate.stage == ApplicationInfoInterface.MainStage
288 ) {
289 priv.focusedAppDelegate.saveStage(ApplicationInfoInterface.SideStage);
290 priv.focusedAppDelegate.focus = true;
291 sideStage.show();
292 priv.updateMainAndSideStageIndexes();
293 }
294 break;
295 case "windowed":
296 if (priv.focusedAppDelegate) {
297 priv.focusedAppDelegate.requestMaximizeRight();
298 }
299 break;
300 }
301 }
302 active: {
303 switch (root.state) {
304 case "stagedWithSideStage":
305 return priv.focusedAppDelegate
306 && priv.focusedAppDelegate.stage == ApplicationInfoInterface.MainStage
307 && priv.sideStageEnabled;
308 case "windowed":
309 return priv.focusedAppDelegate
310 && priv.focusedAppDelegate.canBeMaximizedLeftRight;
311 default:
312 return false;
313 }
314 }
315 }
316
317 GlobalShortcut {
318 id: minimizeRestoreShortcut
319 shortcut: Qt.MetaModifier|Qt.ControlModifier|Qt.Key_Down
320 onTriggered: {
321 if (priv.focusedAppDelegate.anyMaximized) {
322 priv.focusedAppDelegate.requestRestore();
323 } else {
324 priv.focusedAppDelegate.requestMinimize();
325 }
326 }
327 active: root.state == "windowed" && priv.focusedAppDelegate
328 }
329
330 GlobalShortcut {
331 shortcut: Qt.AltModifier|Qt.Key_Print
332 onTriggered: root.itemSnapshotRequested(priv.focusedAppDelegate)
333 active: priv.focusedAppDelegate !== null
334 }
335
336 GlobalShortcut {
337 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_T
338 onTriggered: {
339 // try in this order: snap pkg, new deb name, old deb name
340 var candidates = ["lomiri-terminal-app_lomiri-terminal-app", "lomiri-terminal-app", "com.lomiri.terminal_terminal"];
341 for (var i = 0; i < candidates.length; i++) {
342 if (priv.startApp(candidates[i]))
343 break;
344 }
345 }
346 }
347
348 GlobalShortcut {
349 id: showWorkspaceSwitcherShortcutLeft
350 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
351 active: !workspaceSwitcher.active && root.workspaceEnabled
352 onTriggered: {
353 root.focus = true;
354 workspaceSwitcher.showLeft()
355 }
356 }
357 GlobalShortcut {
358 id: showWorkspaceSwitcherShortcutRight
359 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Right
360 active: !workspaceSwitcher.active && root.workspaceEnabled
361 onTriggered: {
362 root.focus = true;
363 workspaceSwitcher.showRight()
364 }
365 }
366 GlobalShortcut {
367 id: showWorkspaceSwitcherShortcutUp
368 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Up
369 active: !workspaceSwitcher.active && root.workspaceEnabled
370 onTriggered: {
371 root.focus = true;
372 workspaceSwitcher.showUp()
373 }
374 }
375 GlobalShortcut {
376 id: showWorkspaceSwitcherShortcutDown
377 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Down
378 active: !workspaceSwitcher.active && root.workspaceEnabled
379 onTriggered: {
380 root.focus = true;
381 workspaceSwitcher.showDown()
382 }
383 }
384
385 GlobalShortcut {
386 id: moveAppShowWorkspaceSwitcherShortcutLeft
387 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.ShiftModifier|Qt.Key_Left
388 active: !workspaceSwitcher.active && root.workspaceEnabled && priv.focusedAppDelegate !== null
389 onTriggered: {
390 root.focus = true;
391 workspaceSwitcher.showLeftMoveApp(priv.focusedAppDelegate.surface)
392 }
393 }
394 GlobalShortcut {
395 id: moveAppShowWorkspaceSwitcherShortcutRight
396 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.ShiftModifier|Qt.Key_Right
397 active: !workspaceSwitcher.active && root.workspaceEnabled && priv.focusedAppDelegate !== null
398 onTriggered: {
399 root.focus = true;
400 workspaceSwitcher.showRightMoveApp(priv.focusedAppDelegate.surface)
401 }
402 }
403 GlobalShortcut {
404 id: moveAppShowWorkspaceSwitcherShortcutUp
405 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.ShiftModifier|Qt.Key_Up
406 active: !workspaceSwitcher.active && root.workspaceEnabled && priv.focusedAppDelegate !== null
407 onTriggered: {
408 root.focus = true;
409 workspaceSwitcher.showUpMoveApp(priv.focusedAppDelegate.surface)
410 }
411 }
412 GlobalShortcut {
413 id: moveAppShowWorkspaceSwitcherShortcutDown
414 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.ShiftModifier|Qt.Key_Down
415 active: !workspaceSwitcher.active && root.workspaceEnabled && priv.focusedAppDelegate !== null
416 onTriggered: {
417 root.focus = true;
418 workspaceSwitcher.showDownMoveApp(priv.focusedAppDelegate.surface)
419 }
420 }
421
422 QtObject {
423 id: priv
424 objectName: "DesktopStagePrivate"
425
426 function startApp(appId) {
427 if (root.applicationManager.findApplication(appId)) {
428 return root.applicationManager.requestFocusApplication(appId);
429 } else {
430 return root.applicationManager.startApplication(appId) !== null;
431 }
432 }
433
434 property var focusedAppDelegate: null
435 property var foregroundMaximizedAppDelegate: null // for stuff like drop shadow and focusing maximized app by clicking panel
436
437 property bool goneToSpread: false
438 property int closingIndex: -1
439 property int animationDuration: LomiriAnimation.FastDuration
440
441 function updateForegroundMaximizedApp() {
442 var found = false;
443 for (var i = 0; i < appRepeater.count && !found; i++) {
444 var item = appRepeater.itemAt(i);
445 if (item && item.visuallyMaximized) {
446 foregroundMaximizedAppDelegate = item;
447 found = true;
448 }
449 }
450 if (!found) {
451 foregroundMaximizedAppDelegate = null;
452 }
453 }
454
455 function minimizeAllWindows() {
456 for (var i = appRepeater.count - 1; i >= 0; i--) {
457 var appDelegate = appRepeater.itemAt(i);
458 if (appDelegate && !appDelegate.minimized) {
459 appDelegate.requestMinimize();
460 }
461 }
462 }
463
464 readonly property bool sideStageEnabled: root.mode === "stagedWithSideStage" &&
465 (root.shellOrientation == Qt.LandscapeOrientation ||
466 root.shellOrientation == Qt.InvertedLandscapeOrientation)
467 onSideStageEnabledChanged: {
468 for (var i = 0; i < appRepeater.count; i++) {
469 appRepeater.itemAt(i).refreshStage();
470 }
471 priv.updateMainAndSideStageIndexes();
472 }
473
474 property var mainStageDelegate: null
475 property var sideStageDelegate: null
476 property int mainStageItemId: 0
477 property int sideStageItemId: 0
478 property string mainStageAppId: ""
479 property string sideStageAppId: ""
480
481 onSideStageDelegateChanged: {
482 if (!sideStageDelegate) {
483 sideStage.hide();
484 }
485 }
486
487 function toggleSideStage() {
488 if (sideStage.shown) {
489 sideStage.hide();
490 } else {
491 sideStage.show();
492 updateMainAndSideStageIndexes()
493 }
494 }
495
496 function updateMainAndSideStageIndexes() {
497 if (root.mode != "stagedWithSideStage") {
498 priv.sideStageDelegate = null;
499 priv.sideStageItemId = 0;
500 priv.sideStageAppId = "";
501 priv.mainStageDelegate = appRepeater.itemAt(0);
502 priv.mainStageItemId = topLevelSurfaceList.idAt(0);
503 priv.mainStageAppId = topLevelSurfaceList.applicationAt(0) ? topLevelSurfaceList.applicationAt(0).appId : ""
504 return;
505 }
506
507 var choseMainStage = false;
508 var choseSideStage = false;
509
510 if (!root.topLevelSurfaceList)
511 return;
512
513 for (var i = 0; i < appRepeater.count && (!choseMainStage || !choseSideStage); ++i) {
514 var appDelegate = appRepeater.itemAt(i);
515 if (!appDelegate) {
516 // This might happen during startup phase... If the delegate appears and claims focus
517 // things are updated and appRepeater.itemAt(x) still returns null while appRepeater.count >= x
518 // Lets just skip it, on startup it will be generated at a later point too...
519 continue;
520 }
521 if (sideStage.shown && appDelegate.stage == ApplicationInfoInterface.SideStage
522 && !choseSideStage) {
523 priv.sideStageDelegate = appDelegate
524 priv.sideStageItemId = root.topLevelSurfaceList.idAt(i);
525 priv.sideStageAppId = root.topLevelSurfaceList.applicationAt(i).appId;
526 choseSideStage = true;
527 } else if (!choseMainStage && appDelegate.stage == ApplicationInfoInterface.MainStage) {
528 priv.mainStageDelegate = appDelegate;
529 priv.mainStageItemId = root.topLevelSurfaceList.idAt(i);
530 priv.mainStageAppId = root.topLevelSurfaceList.applicationAt(i).appId;
531 choseMainStage = true;
532 }
533 }
534 if (!choseMainStage && priv.mainStageDelegate) {
535 priv.mainStageDelegate = null;
536 priv.mainStageItemId = 0;
537 priv.mainStageAppId = "";
538 }
539 if (!choseSideStage && priv.sideStageDelegate) {
540 priv.sideStageDelegate = null;
541 priv.sideStageItemId = 0;
542 priv.sideStageAppId = "";
543 }
544 }
545
546 property int nextInStack: {
547 var mainStageIndex = priv.mainStageDelegate ? priv.mainStageDelegate.itemIndex : -1;
548 var sideStageIndex = priv.sideStageDelegate ? priv.sideStageDelegate.itemIndex : -1;
549 if (sideStageIndex == -1) {
550 return topLevelSurfaceList.count > 1 ? 1 : -1;
551 }
552 if (mainStageIndex == 0 || sideStageIndex == 0) {
553 if (mainStageIndex == 1 || sideStageIndex == 1) {
554 return topLevelSurfaceList.count > 2 ? 2 : -1;
555 }
556 return 1;
557 }
558 return -1;
559 }
560
561 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
562
563 readonly property real windowDecorationHeight: units.gu(3)
564 }
565
566 Component.onCompleted: priv.updateMainAndSideStageIndexes()
567
568 Connections {
569 target: panelState
570 function onCloseClicked() { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
571 function onMinimizeClicked() { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestMinimize(); } }
572 function onRestoreClicked() { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestRestore(); } }
573 }
574
575 Binding {
576 target: panelState
577 restoreMode: Binding.RestoreBinding
578 property: "decorationsVisible"
579 value: mode == "windowed" && priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized && !root.spreadShown
580 }
581
582 Binding {
583 target: panelState
584 restoreMode: Binding.RestoreBinding
585 property: "title"
586 value: {
587 if (priv.focusedAppDelegate !== null) {
588 if (priv.focusedAppDelegate.maximized)
589 return priv.focusedAppDelegate.title
590 else
591 return priv.focusedAppDelegate.appName
592 }
593 return ""
594 }
595 when: priv.focusedAppDelegate
596 }
597
598 Binding {
599 target: panelState
600 restoreMode: Binding.RestoreBinding
601 property: "focusedPersistentSurfaceId"
602 value: {
603 if (priv.focusedAppDelegate !== null) {
604 if (priv.focusedAppDelegate.surface) {
605 return priv.focusedAppDelegate.surface.persistentId;
606 }
607 }
608 return "";
609 }
610 when: priv.focusedAppDelegate
611 }
612
613 Binding {
614 target: panelState
615 restoreMode: Binding.RestoreBinding
616 property: "dropShadow"
617 value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
618 }
619
620 Binding {
621 target: panelState
622 restoreMode: Binding.RestoreBinding
623 property: "closeButtonShown"
624 value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized
625 }
626
627 Component.onDestruction: {
628 panelState.title = "";
629 panelState.decorationsVisible = false;
630 panelState.dropShadow = false;
631 }
632
633 Instantiator {
634 model: root.applicationManager
635 delegate: QtObject {
636 id: applicationDelegate
637 // TODO: figure out some lifecycle policy, like suspending minimized apps
638 // or something if running windowed.
639 // TODO: If the device has a dozen suspended apps because it was running
640 // in staged mode, when it switches to Windowed mode it will suddenly
641 // resume all those apps at once. We might want to avoid that.
642 property var requestedState: ApplicationInfoInterface.RequestedRunning
643 property bool temporaryAwaken: ProcessControl.awakenProcesses.indexOf(model.application.appId) >= 0
644
645 property var stateBinding: Binding {
646 target: model.application
647 property: "requestedState"
648 value: applicationDelegate.requestedState
649 restoreMode: Binding.RestoreBinding
650 }
651
652 property var lifecycleBinding: Binding {
653 target: model.application
654 property: "exemptFromLifecycle"
655 restoreMode: Binding.RestoreBinding
656 value: model.application
657 ? (!model.application.isTouchApp ||
658 isExemptFromLifecycle(model.application.appId) ||
659 applicationDelegate.temporaryAwaken)
660 : false
661
662 }
663
664 property var focusRequestedConnection: Connections {
665 target: model.application
666
667 function onFocusRequested() {
668 // Application emits focusRequested when it has no surface (i.e. their processes died).
669 // Find the topmost window for this application and activate it, after which the app
670 // will be requested to be running.
671
672 for (var i = 0; i < appRepeater.count; i++) {
673 var appDelegate = appRepeater.itemAt(i);
674 if (appDelegate.application.appId === model.application.appId) {
675 appDelegate.activate();
676 return;
677 }
678 }
679
680 console.warn("Application requested te be focused but no window for it. What should we do?");
681 }
682 }
683 }
684 }
685
686 states: [
687 State {
688 name: "spread"; when: priv.goneToSpread
689 PropertyChanges { target: floatingFlickable; enabled: true }
690 PropertyChanges { target: root; focus: true }
691 PropertyChanges { target: spreadItem; focus: true }
692 PropertyChanges { target: hoverMouseArea; enabled: true }
693 PropertyChanges { target: rightEdgeDragArea; enabled: false }
694 PropertyChanges { target: cancelSpreadMouseArea; enabled: true }
695 PropertyChanges { target: noAppsRunningHint; visible: (root.topLevelSurfaceList.count < 1) }
696 PropertyChanges { target: blurLayer; visible: true; blurRadius: 32; brightness: .50; opacity: 1 }
697 PropertyChanges { target: wallpaper; visible: false }
698 PropertyChanges { target: screensAndWorkspaces.showTimer; running: true }
699 },
700 State {
701 name: "stagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "staged"
702 PropertyChanges {
703 target: blurLayer;
704 visible: true;
705 blurRadius: 32
706 brightness: .65
707 opacity: 1
708 }
709 PropertyChanges { target: noAppsRunningHint; visible: (root.topLevelSurfaceList.count < 1) }
710 },
711 State {
712 name: "sideStagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "stagedWithSideStage"
713 extend: "stagedRightEdge"
714 PropertyChanges {
715 target: sideStage
716 opacity: priv.sideStageDelegate && priv.sideStageDelegate.x === sideStage.x ? 1 : 0
717 visible: true
718 }
719 },
720 State {
721 name: "windowedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "windowed"
722 PropertyChanges {
723 target: blurLayer;
724 visible: true
725 blurRadius: 32
726 brightness: .65
727 opacity: MathUtils.linearAnimation(spreadItem.rightEdgeBreakPoint, 1, 0, 1, Math.max(rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0, rightEdgePushProgress))
728 }
729 },
730 State {
731 name: "staged"; when: root.mode === "staged"
732 PropertyChanges { target: root; focus: true }
733 PropertyChanges { target: appContainer; focus: true }
734 },
735 State {
736 name: "stagedWithSideStage"; when: root.mode === "stagedWithSideStage"
737 PropertyChanges { target: triGestureArea; enabled: priv.sideStageEnabled }
738 PropertyChanges { target: sideStage; visible: true }
739 PropertyChanges { target: root; focus: true }
740 PropertyChanges { target: appContainer; focus: true }
741 },
742 State {
743 name: "windowed"; when: root.mode === "windowed"
744 PropertyChanges { target: root; focus: true }
745 PropertyChanges { target: appContainer; focus: true }
746 }
747 ]
748 transitions: [
749 Transition {
750 from: "stagedRightEdge,sideStagedRightEdge,windowedRightEdge"; to: "spread"
751 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
752 PropertyAction { target: screensAndWorkspaces; property: "activeWorkspace"; value: WMScreen.currentWorkspace }
753 PropertyAnimation { target: blurLayer; properties: "brightness,blurRadius"; duration: priv.animationDuration }
754 },
755 Transition {
756 to: "spread"
757 PropertyAction { target: screensAndWorkspaces; property: "activeWorkspace"; value: WMScreen.currentWorkspace }
758 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
759 PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
760 },
761 Transition {
762 from: "spread"
763 SequentialAnimation {
764 ScriptAction {
765 script: {
766 var item = appRepeater.itemAt(Math.max(0, spreadItem.highlightedIndex));
767 if (item) {
768 if (item.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
769 sideStage.show();
770 }
771 item.playFocusAnimation();
772 }
773 }
774 }
775 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
776 PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
777 }
778 },
779 Transition {
780 to: "stagedRightEdge,sideStagedRightEdge"
781 PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
782 },
783 Transition {
784 to: "stagedWithSideStage"
785 ScriptAction { script: priv.updateMainAndSideStageIndexes(); }
786 }
787
788 ]
789
790 MouseArea {
791 id: cancelSpreadMouseArea
792 anchors.fill: parent
793 enabled: false
794 onClicked: priv.goneToSpread = false
795 }
796
797 FocusScope {
798 id: appContainer
799 objectName: "appContainer"
800 anchors.fill: parent
801 focus: true
802
803 Wallpaper {
804 id: wallpaper
805 objectName: "stageBackground"
806 anchors.fill: parent
807 source: root.background
808 // Make sure it's the lowest item. Due to the left edge drag we sometimes need
809 // to put the dash at -1 and we don't want it behind the Wallpaper
810 z: -2
811 }
812
813 BlurLayer {
814 id: blurLayer
815 anchors.fill: parent
816 source: wallpaper
817 visible: false
818 }
819
820 ScreensAndWorkspaces {
821 id: screensAndWorkspaces
822 anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.launcherLeftMargin }
823 height: Math.max(units.gu(30), parent.height * .3)
824 background: root.background
825 visible: showAllowed
826 enabled: workspaceEnabled
827 mode: root.mode
828 availableDesktopArea: root.availableDesktopArea
829 onCloseSpread: priv.goneToSpread = false;
830 // Clicking a workspace should put it front and center
831 onActiveWorkspaceChanged: activeWorkspace.activate()
832 opacity: visible ? 1.0 : 0.0
833 Behavior on opacity {
834 NumberAnimation { duration: priv.animationDuration }
835 }
836
837 property bool showAllowed : false
838 property var showTimer: Timer {
839 running: false
840 repeat: false
841 interval: priv.animationDuration
842 onTriggered: {
843 if (!priv.goneToSpread)
844 return;
845 screensAndWorkspaces.showAllowed = root.workspaceEnabled;
846 }
847 }
848 Connections {
849 target: priv
850 onGoneToSpreadChanged: if (!priv.goneToSpread) screensAndWorkspaces.showAllowed = false
851 }
852 }
853
854 Spread {
855 id: spreadItem
856 objectName: "spreadItem"
857 anchors {
858 left: parent.left;
859 bottom: parent.bottom;
860 right: parent.right;
861 top: workspaceEnabled ? screensAndWorkspaces.bottom : parent.top;
862 }
863 leftMargin: root.availableDesktopArea.x
864 model: root.topLevelSurfaceList
865 spreadFlickable: floatingFlickable
866 z: root.topLevelSurfaceList.count
867
868 onLeaveSpread: {
869 priv.goneToSpread = false;
870 }
871
872 onCloseCurrentApp: {
873 appRepeater.itemAt(highlightedIndex).close();
874 }
875
876 FloatingFlickable {
877 id: floatingFlickable
878 objectName: "spreadFlickable"
879 anchors.fill: parent
880 enabled: false
881 contentWidth: spreadItem.spreadTotalWidth
882
883 function snap(toIndex) {
884 var delegate = appRepeater.itemAt(toIndex)
885 var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
886 if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
887 var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
888 snapAnimation.to = floatingFlickable.contentX - offset;
889 snapAnimation.start();
890 } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
891 var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
892 snapAnimation.to = floatingFlickable.contentX - offset;
893 snapAnimation.start();
894 }
895 }
896 LomiriNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
897 }
898
899 MouseArea {
900 id: hoverMouseArea
901 objectName: "hoverMouseArea"
902 anchors.fill: parent
903 propagateComposedEvents: true
904 hoverEnabled: true
905 enabled: false
906 visible: enabled
907 property bool wasTouchPress: false
908
909 property int scrollAreaWidth: width / 3
910 property bool progressiveScrollingEnabled: false
911
912 onMouseXChanged: {
913 mouse.accepted = false
914
915 if (hoverMouseArea.pressed || wasTouchPress) {
916 return;
917 }
918
919 // Find the hovered item and mark it active
920 for (var i = appRepeater.count - 1; i >= 0; i--) {
921 var appDelegate = appRepeater.itemAt(i);
922 var mapped = mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
923 var itemUnder = appDelegate.childAt(mapped.x, mapped.y);
924 if (itemUnder && (itemUnder.objectName === "dragArea" || itemUnder.objectName === "windowInfoItem" || itemUnder.objectName == "closeMouseArea")) {
925 spreadItem.highlightedIndex = i;
926 break;
927 }
928 }
929
930 if (floatingFlickable.contentWidth > floatingFlickable.width) {
931 var margins = floatingFlickable.width * 0.05;
932
933 if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
934 progressiveScrollingEnabled = true
935 }
936
937 // do we need to scroll?
938 if (mouseX < scrollAreaWidth + margins) {
939 var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
940 var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
941 floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
942 }
943 if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
944 var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
945 var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
946 floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
947 }
948 }
949 }
950
951 onPressed: {
952 mouse.accepted = false;
953 wasTouchPress = mouse.source === Qt.MouseEventSynthesizedByQt;
954 }
955
956 onExited: wasTouchPress = false;
957 }
958 }
959
960 Label {
961 id: noAppsRunningHint
962 visible: false
963 anchors.horizontalCenter: parent.horizontalCenter
964 anchors.verticalCenter: parent.verticalCenter
965 anchors.fill: parent
966 horizontalAlignment: Qt.AlignHCenter
967 verticalAlignment: Qt.AlignVCenter
968 anchors.leftMargin: root.launcherLeftMargin
969 wrapMode: Label.WordWrap
970 fontSize: "large"
971 text: i18n.tr("No running apps")
972 color: "#FFFFFF"
973 }
974
975 Connections {
976 target: root.topLevelSurfaceList
977 function onListChanged() { priv.updateMainAndSideStageIndexes() }
978 }
979
980
981 DropArea {
982 objectName: "MainStageDropArea"
983 anchors {
984 left: parent.left
985 top: parent.top
986 bottom: parent.bottom
987 }
988 width: appContainer.width - sideStage.width
989 enabled: priv.sideStageEnabled
990
991 onDropped: {
992 drop.source.appDelegate.saveStage(ApplicationInfoInterface.MainStage);
993 drop.source.appDelegate.activate();
994 }
995 keys: "SideStage"
996 }
997
998 SideStage {
999 id: sideStage
1000 objectName: "sideStage"
1001 shown: false
1002 height: appContainer.height
1003 x: appContainer.width - width
1004 visible: false
1005 showHint: !priv.sideStageDelegate
1006 Behavior on opacity { LomiriNumberAnimation {} }
1007 z: {
1008 if (!priv.mainStageItemId) return 0;
1009
1010 if (priv.sideStageItemId && priv.nextInStack > 0) {
1011
1012 // Due the order in which bindings are evaluated, this might be triggered while shuffling
1013 // the list and index doesn't yet match with itemIndex (even though itemIndex: index)
1014 // Let's walk the list and compare itemIndex to make sure we have the correct one.
1015 var nextDelegateInStack = -1;
1016 for (var i = 0; i < appRepeater.count; i++) {
1017 if (appRepeater.itemAt(i).itemIndex == priv.nextInStack) {
1018 nextDelegateInStack = appRepeater.itemAt(i);
1019 break;
1020 }
1021 }
1022
1023 if (nextDelegateInStack.stage === ApplicationInfoInterface.MainStage) {
1024 // if the next app in stack is a main stage app, put the sidestage on top of it.
1025 return 2;
1026 }
1027 return 1;
1028 }
1029
1030 return 1;
1031 }
1032
1033 onShownChanged: {
1034 if (!shown && priv.mainStageDelegate && !root.spreadShown) {
1035 priv.mainStageDelegate.activate();
1036 }
1037 }
1038
1039 DropArea {
1040 id: sideStageDropArea
1041 objectName: "SideStageDropArea"
1042 anchors.fill: parent
1043
1044 property bool dropAllowed: true
1045
1046 onEntered: {
1047 dropAllowed = drag.keys != "Disabled";
1048 }
1049 onExited: {
1050 dropAllowed = true;
1051 }
1052 onDropped: {
1053 if (drop.keys == "MainStage") {
1054 drop.source.appDelegate.saveStage(ApplicationInfoInterface.SideStage);
1055 drop.source.appDelegate.activate();
1056 }
1057 }
1058 drag {
1059 onSourceChanged: {
1060 if (!sideStageDropArea.drag.source) {
1061 dropAllowed = true;
1062 }
1063 }
1064 }
1065 }
1066 }
1067
1068 MirSurfaceItem {
1069 id: fakeDragItem
1070 property real previewScale: .5
1071 height: (screensAndWorkspaces.height - units.gu(8)) / 2
1072 // w : h = iw : ih
1073 width: implicitWidth * height / implicitHeight
1074 surfaceWidth: -1
1075 surfaceHeight: -1
1076 opacity: surface != null ? 1 : 0
1077 Behavior on opacity { LomiriNumberAnimation {} }
1078 visible: opacity > 0
1079 enabled: workspaceSwitcher
1080
1081 Drag.active: surface != null
1082 Drag.keys: ["application"]
1083
1084 z: 1000
1085 }
1086
1087 Repeater {
1088 id: appRepeater
1089 model: topLevelSurfaceList
1090 objectName: "appRepeater"
1091
1092 function indexOf(delegateItem) {
1093 for (var i = 0; i < count; i++) {
1094 if (itemAt(i) === delegateItem) {
1095 return i;
1096 }
1097 }
1098 return -1;
1099 }
1100
1101 delegate: FocusScope {
1102 id: appDelegate
1103 objectName: "appDelegate_" + model.window.id
1104 property int itemIndex: index // We need this from outside the repeater
1105 // z might be overriden in some cases by effects, but we need z ordering
1106 // to calculate occlusion detection
1107 property int normalZ: topLevelSurfaceList.count - index
1108 onNormalZChanged: {
1109 if (visuallyMaximized) {
1110 priv.updateForegroundMaximizedApp();
1111 }
1112 }
1113 z: normalZ
1114
1115 opacity: fakeDragItem.surface == model.window.surface && fakeDragItem.Drag.active ? 0 : 1
1116 Behavior on opacity { LomiriNumberAnimation {} }
1117
1118 // Set these as propertyes as they wont update otherwise
1119 property real screenOffsetX: Screen.virtualX
1120 property real screenOffsetY: Screen.virtualY
1121
1122 // Normally we want x/y where the surface thinks it is. Width/height of our delegate will
1123 // match what the actual surface size is.
1124 // Don't write to those, they will be set by states
1125 // --
1126 // Here we will also need to remove the screen offset from miral's results
1127 // as lomiri x,y will be relative to the current screen only
1128 // FIXME: when proper multiscreen lands
1129 x: model.window.position.x - clientAreaItem.x - screenOffsetX
1130 y: model.window.position.y - clientAreaItem.y - screenOffsetY
1131 width: decoratedWindow.implicitWidth
1132 height: decoratedWindow.implicitHeight
1133
1134 // requestedX/Y/width/height is what we ask the actual surface to be.
1135 // Do not write to those, they will be set by states
1136 property real requestedX: windowedX
1137 property real requestedY: windowedY
1138 property real requestedWidth: windowedWidth
1139 property real requestedHeight: windowedHeight
1140
1141 // For both windowed and staged need to tell miral what screen we are on,
1142 // so we need to add the screen offset to the position we tell miral
1143 // FIXME: when proper multiscreen lands
1144 Binding {
1145 target: model.window; property: "requestedPosition"
1146 // miral doesn't know about our window decorations. So we have to deduct them
1147 value: Qt.point(appDelegate.requestedX + appDelegate.clientAreaItem.x + screenOffsetX,
1148 appDelegate.requestedY + appDelegate.clientAreaItem.y + screenOffsetY)
1149 when: root.mode == "windowed"
1150 restoreMode: Binding.RestoreBinding
1151 }
1152 Binding {
1153 target: model.window; property: "requestedPosition"
1154 value: Qt.point(screenOffsetX, screenOffsetY)
1155 when: root.mode != "windowed"
1156 restoreMode: Binding.RestoreBinding
1157 }
1158
1159 // In those are for windowed mode. Those values basically store the window's properties
1160 // when having a floating window. If you want to move/resize a window in normal mode, this is what you want to write to.
1161 property real windowedX
1162 property real windowedY
1163 property real windowedWidth
1164 property real windowedHeight
1165
1166 // unlike windowedX/Y, this is the last known grab position before being pushed against edges/corners
1167 // when restoring, the window should return to these, not to the place where it was dropped near the edge
1168 property real restoredX
1169 property real restoredY
1170
1171 // Keeps track of the window geometry while in normal or restored state
1172 // Useful when returning from some maxmized state or when saving the geometry while maximized
1173 // FIXME: find a better solution
1174 property real normalX: 0
1175 property real normalY: 0
1176 property real normalWidth: 0
1177 property real normalHeight: 0
1178 function updateNormalGeometry() {
1179 if (appDelegate.state == "normal" || appDelegate.state == "restored") {
1180 normalX = appDelegate.requestedX;
1181 normalY = appDelegate.requestedY;
1182 normalWidth = appDelegate.width;
1183 normalHeight = appDelegate.height;
1184 }
1185 }
1186 function updateRestoredGeometry() {
1187 if (appDelegate.state == "normal" || appDelegate.state == "restored") {
1188 // save the x/y to restore to
1189 restoredX = appDelegate.x;
1190 restoredY = appDelegate.y;
1191 }
1192 }
1193
1194 Connections {
1195 target: appDelegate
1196 function onXChanged() { appDelegate.updateNormalGeometry(); }
1197 function onYChanged() { appDelegate.updateNormalGeometry(); }
1198 function onWidthChanged() { appDelegate.updateNormalGeometry(); }
1199 function onHeightChanged() { appDelegate.updateNormalGeometry(); }
1200 }
1201
1202 // True when the Stage is focusing this app and playing its own animation.
1203 // Stays true until the app is unfocused.
1204 // If it is, we don't want to play the slide in/out transition from StageMaths.
1205 // Setting it imperatively is not great, but any declarative solution hits
1206 // race conditions, causing two animations to play for one focus event.
1207 property bool inhibitSlideAnimation: false
1208
1209 Binding {
1210 target: appDelegate
1211 property: "y"
1212 value: appDelegate.requestedY -
1213 Math.min(appDelegate.requestedY - root.availableDesktopArea.y,
1214 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
1215 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
1216 && root.inputMethodRect.height > 0
1217 restoreMode: Binding.RestoreBinding
1218 }
1219
1220 Behavior on x { id: xBehavior; enabled: priv.closingIndex >= 0; LomiriNumberAnimation { onRunningChanged: if (!running) priv.closingIndex = -1} }
1221
1222 Connections {
1223 target: root
1224 function onShellOrientationAngleChanged() {
1225 // at this point decoratedWindow.surfaceOrientationAngle is the old shellOrientationAngle
1226 if (appDelegate.application && appDelegate.application.rotatesWindowContents) {
1227 if (root.state == "windowed") {
1228 var angleDiff = decoratedWindow.surfaceOrientationAngle - shellOrientationAngle;
1229 angleDiff = (360 + angleDiff) % 360;
1230 if (angleDiff === 90 || angleDiff === 270) {
1231 var aux = decoratedWindow.requestedHeight;
1232 decoratedWindow.requestedHeight = decoratedWindow.requestedWidth + decoratedWindow.actualDecorationHeight;
1233 decoratedWindow.requestedWidth = aux - decoratedWindow.actualDecorationHeight;
1234 }
1235 }
1236 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
1237 } else {
1238 decoratedWindow.surfaceOrientationAngle = 0;
1239 }
1240 }
1241 }
1242
1243 readonly property alias application: decoratedWindow.application
1244 readonly property alias minimumWidth: decoratedWindow.minimumWidth
1245 readonly property alias minimumHeight: decoratedWindow.minimumHeight
1246 readonly property alias maximumWidth: decoratedWindow.maximumWidth
1247 readonly property alias maximumHeight: decoratedWindow.maximumHeight
1248 readonly property alias widthIncrement: decoratedWindow.widthIncrement
1249 readonly property alias heightIncrement: decoratedWindow.heightIncrement
1250
1251 readonly property bool maximized: windowState === Mir.MaximizedState
1252 readonly property bool maximizedLeft: windowState === Mir.MaximizedLeftState
1253 readonly property bool maximizedRight: windowState === Mir.MaximizedRightState
1254 readonly property bool maximizedHorizontally: windowState === Mir.HorizMaximizedState
1255 readonly property bool maximizedVertically: windowState === Mir.VertMaximizedState
1256 readonly property bool maximizedTopLeft: windowState === Mir.MaximizedTopLeftState
1257 readonly property bool maximizedTopRight: windowState === Mir.MaximizedTopRightState
1258 readonly property bool maximizedBottomLeft: windowState === Mir.MaximizedBottomLeftState
1259 readonly property bool maximizedBottomRight: windowState === Mir.MaximizedBottomRightState
1260 readonly property bool anyMaximized: maximized || maximizedLeft || maximizedRight || maximizedHorizontally || maximizedVertically ||
1261 maximizedTopLeft || maximizedTopRight || maximizedBottomLeft || maximizedBottomRight
1262
1263 readonly property bool minimized: windowState === Mir.MinimizedState
1264 readonly property bool fullscreen: windowState === Mir.FullscreenState
1265
1266 readonly property bool canBeMaximized: canBeMaximizedHorizontally && canBeMaximizedVertically
1267 readonly property bool canBeMaximizedLeftRight: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
1268 (maximumHeight == 0 || maximumHeight >= appContainer.height)
1269 readonly property bool canBeCornerMaximized: (maximumWidth == 0 || maximumWidth >= appContainer.width/2) &&
1270 (maximumHeight == 0 || maximumHeight >= appContainer.height/2)
1271 readonly property bool canBeMaximizedHorizontally: maximumWidth == 0 || maximumWidth >= appContainer.width
1272 readonly property bool canBeMaximizedVertically: maximumHeight == 0 || maximumHeight >= appContainer.height
1273 readonly property alias orientationChangesEnabled: decoratedWindow.orientationChangesEnabled
1274
1275 property int windowState: model.window.state
1276 property int prevWindowState: Mir.RestoredState
1277
1278 property bool animationsEnabled: true
1279 property alias title: decoratedWindow.title
1280 readonly property string appName: model.application ? model.application.name : ""
1281 property bool visuallyMaximized: false
1282 property bool visuallyMinimized: false
1283 readonly property alias windowedTransitionRunning: windowedTransition.running
1284
1285 property int stage: ApplicationInfoInterface.MainStage
1286 function saveStage(newStage) {
1287 appDelegate.stage = newStage;
1288 WindowStateStorage.saveStage(appId, newStage);
1289 priv.updateMainAndSideStageIndexes()
1290 }
1291
1292 readonly property var surface: model.window.surface
1293 readonly property var window: model.window
1294
1295 readonly property alias focusedSurface: decoratedWindow.focusedSurface
1296 readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
1297
1298 readonly property string appId: model.application.appId
1299 readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
1300
1301 // It is Lomiri policy to close any window but the last one during OOM teardown
1302/*
1303 Connections {
1304 target: model.window.surface
1305 onLiveChanged: {
1306 if ((!surface.live && application && application.surfaceCount > 1) || !application)
1307 topLevelSurfaceList.removeAt(appRepeater.indexOf(appDelegate));
1308 }
1309 }
1310*/
1311
1312
1313 function activate() {
1314 if (model.window.focused) {
1315 updateQmlFocusFromMirSurfaceFocus();
1316 } else {
1317 if (surface.live) {
1318 // Activate the window since it has a surface (with a running app) backing it
1319 model.window.activate();
1320 } else {
1321 // Otherwise, cause a respawn of the app, and trigger it's refocusing as the last window
1322 topLevelSurfaceList.raiseId(model.window.id);
1323 }
1324 }
1325 }
1326 function requestMaximize() { model.window.requestState(Mir.MaximizedState); }
1327 function requestMaximizeVertically() { model.window.requestState(Mir.VertMaximizedState); }
1328 function requestMaximizeHorizontally() { model.window.requestState(Mir.HorizMaximizedState); }
1329 function requestMaximizeLeft() { model.window.requestState(Mir.MaximizedLeftState); }
1330 function requestMaximizeRight() { model.window.requestState(Mir.MaximizedRightState); }
1331 function requestMaximizeTopLeft() { model.window.requestState(Mir.MaximizedTopLeftState); }
1332 function requestMaximizeTopRight() { model.window.requestState(Mir.MaximizedTopRightState); }
1333 function requestMaximizeBottomLeft() { model.window.requestState(Mir.MaximizedBottomLeftState); }
1334 function requestMaximizeBottomRight() { model.window.requestState(Mir.MaximizedBottomRightState); }
1335 function requestMinimize() { model.window.requestState(Mir.MinimizedState); }
1336 function requestRestore() { model.window.requestState(Mir.RestoredState); }
1337
1338 function claimFocus() {
1339 if (root.state == "spread") {
1340 spreadItem.highlightedIndex = index
1341 // force pendingActivation so that when switching to staged mode, topLevelSurfaceList focus won't got to previous app ( case when apps are launched from outside )
1342 topLevelSurfaceList.pendingActivation();
1343 priv.goneToSpread = false;
1344 }
1345 if (root.mode == "stagedWithSideStage") {
1346 if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
1347 sideStage.show();
1348 }
1349 priv.updateMainAndSideStageIndexes();
1350 }
1351 appDelegate.focus = true;
1352
1353 // Don't set focusedAppDelegate (and signal mainAppChanged) unnecessarily
1354 // which can happen after getting interactive again.
1355 if (priv.focusedAppDelegate !== appDelegate)
1356 priv.focusedAppDelegate = appDelegate;
1357 }
1358
1359 function updateQmlFocusFromMirSurfaceFocus() {
1360 if (model.window.focused) {
1361 claimFocus();
1362 decoratedWindow.focus = true;
1363 }
1364 }
1365
1366 WindowStateSaver {
1367 id: windowStateSaver
1368 target: appDelegate
1369 screenWidth: appContainer.width
1370 screenHeight: appContainer.height
1371 leftMargin: root.availableDesktopArea.x
1372 minimumY: root.availableDesktopArea.y
1373 }
1374
1375 Connections {
1376 target: model.window
1377 property int lastWindowState: Mir.RestoredState
1378
1379 function onFocusedChanged() {
1380 updateQmlFocusFromMirSurfaceFocus();
1381 if (!model.window.focused) {
1382 inhibitSlideAnimation = false;
1383 }
1384 }
1385 function onFocusRequested() {
1386 appDelegate.activate();
1387 }
1388 function onStateChanged(value) {
1389 if (value == Mir.FullscreenState || value == Mir.MinimizedState) {
1390 if (lastWindowState == Mir.MinimizedState) {
1391 appDelegate.prevWindowState = Mir.RestoredState;
1392 } else {
1393 appDelegate.prevWindowState = lastWindowState;
1394 }
1395 } else if (value == Mir.RestoredState) {
1396 if ((lastWindowState == Mir.FullscreenState || lastWindowState == Mir.MinimizedState) &&
1397 appDelegate.prevWindowState != Mir.RestoredState) {
1398 model.window.requestState(appDelegate.prevWindowState);
1399 }
1400 return;
1401 }
1402
1403 lastWindowState = value;
1404 }
1405 }
1406
1407 readonly property bool windowReady: clientAreaItem.surfaceInitialized
1408 onWindowReadyChanged: {
1409 if (windowReady) {
1410 var loadedMirState = windowStateSaver.loadedState;
1411 var state = loadedMirState;
1412
1413 if (window.state == Mir.FullscreenState) {
1414 // If the app is fullscreen at startup, we should not use saved state
1415 // Example of why: if you open game that only requests fullscreen at
1416 // Statup, this will automaticly be set to "restored state" since
1417 // thats the default value of stateStorage, this will result in the app
1418 // having the "restored state" as it will not make a fullscreen
1419 // call after the app has started.
1420 console.log("Initial window state is fullscreen, not using saved state.");
1421 state = window.state;
1422 } else if (loadedMirState == Mir.FullscreenState) {
1423 // If saved state is fullscreen, we should use app initial state
1424 // Example of why: if you open browser with youtube video at fullscreen
1425 // and close this app, it will be fullscreen next time you open the app.
1426 console.log("Saved window state is fullscreen, using initial window state");
1427 state = window.state;
1428 }
1429
1430 // need to apply the shell chrome policy on top the saved window state
1431 var policy;
1432 if (root.mode == "windowed") {
1433 policy = windowedFullscreenPolicy;
1434 } else {
1435 policy = stagedFullscreenPolicy
1436 }
1437 window.requestState(policy.applyPolicy(state, surface.shellChrome));
1438 }
1439 }
1440
1441 Component.onCompleted: {
1442 if (application && application.rotatesWindowContents) {
1443 decoratedWindow.surfaceOrientationAngle = shellOrientationAngle;
1444 } else {
1445 decoratedWindow.surfaceOrientationAngle = 0;
1446 }
1447
1448 // First, cascade the newly created window, relative to the currently/old focused window.
1449 windowedX = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedX + units.gu(3) : (normalZ - 1) * units.gu(3)
1450 windowedY = priv.focusedAppDelegate ? priv.focusedAppDelegate.windowedY + units.gu(3) : normalZ * units.gu(3)
1451 // Now load any saved state. This needs to happen *after* the cascading!
1452 windowStateSaver.load(!model.window.constrained);
1453 if (!model.window.constrained) {
1454 // By this point windowStateSaver has loaded the state, and constrained it on screen. Set this to true
1455 model.window.constrained = true;
1456 }
1457
1458 if (!root.spreadShown) {
1459 updateQmlFocusFromMirSurfaceFocus();
1460 }
1461
1462 // Make apps maximized on phones & tablets
1463 if (root.mode == "staged" || root.mode == "stagedWithSideStage")
1464 appDelegate.maximize()
1465
1466 refreshStage();
1467 _constructing = false;
1468 }
1469 Component.onDestruction: {
1470 windowStateSaver.save();
1471
1472 if (!root.parent) {
1473 // This stage is about to be destroyed. Don't mess up with the model at this point
1474 return;
1475 }
1476
1477 if (visuallyMaximized) {
1478 priv.updateForegroundMaximizedApp();
1479 }
1480 }
1481
1482 onVisuallyMaximizedChanged: priv.updateForegroundMaximizedApp()
1483
1484 property bool _constructing: true;
1485 onStageChanged: {
1486 if (!_constructing) {
1487 priv.updateMainAndSideStageIndexes();
1488 }
1489 }
1490
1491 visible: (
1492 !visuallyMinimized
1493 && !greeter.fullyShown
1494 && (priv.foregroundMaximizedAppDelegate === null || priv.foregroundMaximizedAppDelegate.normalZ <= z)
1495 )
1496 || appDelegate.fullscreen
1497 || focusAnimation.running || rightEdgeFocusAnimation.running || hidingAnimation.running
1498
1499 function close() {
1500 model.window.close();
1501 }
1502
1503 function playFocusAnimation() {
1504 if (state == "stagedRightEdge") {
1505 // TODO: Can we drop this if and find something that always works?
1506 if (root.mode == "staged") {
1507 rightEdgeFocusAnimation.targetX = 0
1508 rightEdgeFocusAnimation.start()
1509 } else if (root.mode == "stagedWithSideStage") {
1510 rightEdgeFocusAnimation.targetX = appDelegate.stage == ApplicationInfoInterface.SideStage ? sideStage.x : 0
1511 rightEdgeFocusAnimation.start()
1512 }
1513 } else {
1514 focusAnimation.start()
1515 }
1516 }
1517 function playHidingAnimation() {
1518 if (state != "windowedRightEdge") {
1519 hidingAnimation.start()
1520 }
1521 }
1522
1523 function refreshStage() {
1524 var newStage = ApplicationInfoInterface.MainStage;
1525 if (priv.sideStageEnabled) { // we're in lanscape rotation.
1526 if (application && application.supportedOrientations & (Qt.PortraitOrientation|Qt.InvertedPortraitOrientation)) {
1527 var defaultStage = ApplicationInfoInterface.SideStage; // if application supports portrait, it defaults to sidestage.
1528 if (application.supportedOrientations & (Qt.LandscapeOrientation|Qt.InvertedLandscapeOrientation)) {
1529 // if it supports lanscape, it defaults to mainstage.
1530 defaultStage = ApplicationInfoInterface.MainStage;
1531 }
1532 newStage = WindowStateStorage.getStage(application.appId, defaultStage);
1533 }
1534 }
1535
1536 stage = newStage;
1537 if (focus && stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
1538 sideStage.show();
1539 }
1540 }
1541
1542 LomiriNumberAnimation {
1543 id: focusAnimation
1544 target: appDelegate
1545 property: "scale"
1546 from: 0.98
1547 to: 1
1548 duration: LomiriAnimation.SnapDuration
1549 onStarted: {
1550 topLevelSurfaceList.pendingActivation();
1551 topLevelSurfaceList.raiseId(model.window.id);
1552 }
1553 onStopped: {
1554 appDelegate.activate();
1555 }
1556 }
1557 ParallelAnimation {
1558 id: rightEdgeFocusAnimation
1559 property int targetX: 0
1560 LomiriNumberAnimation { target: appDelegate; properties: "x"; to: rightEdgeFocusAnimation.targetX; duration: priv.animationDuration }
1561 LomiriNumberAnimation { target: decoratedWindow; properties: "angle"; to: 0; duration: priv.animationDuration }
1562 LomiriNumberAnimation { target: decoratedWindow; properties: "itemScale"; to: 1; duration: priv.animationDuration }
1563 onStarted: {
1564 topLevelSurfaceList.pendingActivation();
1565 inhibitSlideAnimation = true;
1566 }
1567 onStopped: {
1568 appDelegate.activate();
1569 }
1570 }
1571 ParallelAnimation {
1572 id: hidingAnimation
1573 LomiriNumberAnimation { target: appDelegate; property: "opacity"; to: 0; duration: priv.animationDuration }
1574 onStopped: appDelegate.opacity = 1
1575 }
1576
1577 SpreadMaths {
1578 id: spreadMaths
1579 spread: spreadItem
1580 itemIndex: index
1581 flickable: floatingFlickable
1582 }
1583 StageMaths {
1584 id: stageMaths
1585 sceneWidth: root.width
1586 stage: appDelegate.stage
1587 thisDelegate: appDelegate
1588 mainStageDelegate: priv.mainStageDelegate
1589 sideStageDelegate: priv.sideStageDelegate
1590 sideStageWidth: sideStage.panelWidth
1591 sideStageHandleWidth: sideStage.handleWidth
1592 sideStageX: sideStage.x
1593 itemIndex: appDelegate.itemIndex
1594 nextInStack: priv.nextInStack
1595 animationDuration: priv.animationDuration
1596 }
1597
1598 StagedRightEdgeMaths {
1599 id: stagedRightEdgeMaths
1600 sceneWidth: root.availableDesktopArea.width
1601 sceneHeight: appContainer.height
1602 isMainStageApp: priv.mainStageDelegate == appDelegate
1603 isSideStageApp: priv.sideStageDelegate == appDelegate
1604 sideStageWidth: sideStage.width
1605 sideStageOpen: sideStage.shown
1606 itemIndex: index
1607 nextInStack: priv.nextInStack
1608 progress: 0
1609 targetHeight: spreadItem.stackHeight
1610 targetX: spreadMaths.targetX
1611 startY: appDelegate.fullscreen ? 0 : root.availableDesktopArea.y
1612 targetY: spreadMaths.targetY
1613 targetAngle: spreadMaths.targetAngle
1614 targetScale: spreadMaths.targetScale
1615 shuffledZ: stageMaths.itemZ
1616 breakPoint: spreadItem.rightEdgeBreakPoint
1617 }
1618
1619 WindowedRightEdgeMaths {
1620 id: windowedRightEdgeMaths
1621 itemIndex: index
1622 startWidth: appDelegate.requestedWidth
1623 startHeight: appDelegate.requestedHeight
1624 targetHeight: spreadItem.stackHeight
1625 targetX: spreadMaths.targetX
1626 targetY: spreadMaths.targetY
1627 normalZ: appDelegate.normalZ
1628 targetAngle: spreadMaths.targetAngle
1629 targetScale: spreadMaths.targetScale
1630 breakPoint: spreadItem.rightEdgeBreakPoint
1631 }
1632
1633 states: [
1634 State {
1635 name: "spread"; when: root.state == "spread"
1636 StateChangeScript { script: { decoratedWindow.cancelDrag(); } }
1637 PropertyChanges {
1638 target: decoratedWindow;
1639 showDecoration: false;
1640 angle: spreadMaths.targetAngle
1641 itemScale: spreadMaths.targetScale
1642 scaleToPreviewSize: spreadItem.stackHeight
1643 scaleToPreviewProgress: 1
1644 hasDecoration: root.mode === "windowed"
1645 shadowOpacity: spreadMaths.shadowOpacity
1646 showHighlight: spreadItem.highlightedIndex === index
1647 darkening: spreadItem.highlightedIndex >= 0
1648 anchors.topMargin: dragArea.distance
1649 }
1650 PropertyChanges {
1651 target: appDelegate
1652 x: spreadMaths.targetX
1653 y: spreadMaths.targetY
1654 z: index
1655 height: spreadItem.spreadItemHeight
1656 visible: spreadMaths.itemVisible
1657 }
1658 PropertyChanges { target: dragArea; enabled: true }
1659 PropertyChanges { target: windowInfoItem; opacity: spreadMaths.tileInfoOpacity; visible: spreadMaths.itemVisible }
1660 PropertyChanges { target: touchControls; enabled: false }
1661 },
1662 State {
1663 name: "stagedRightEdge"
1664 when: (root.mode == "staged" || root.mode == "stagedWithSideStage") && (root.state == "sideStagedRightEdge" || root.state == "stagedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running)
1665 PropertyChanges {
1666 target: stagedRightEdgeMaths
1667 progress: Math.max(rightEdgePushProgress, rightEdgeDragArea.draggedProgress)
1668 }
1669 PropertyChanges {
1670 target: appDelegate
1671 x: stagedRightEdgeMaths.animatedX
1672 y: stagedRightEdgeMaths.animatedY
1673 z: stagedRightEdgeMaths.animatedZ
1674 height: stagedRightEdgeMaths.animatedHeight
1675 visible: appDelegate.x < root.width
1676 }
1677 PropertyChanges {
1678 target: decoratedWindow
1679 hasDecoration: false
1680 angle: stagedRightEdgeMaths.animatedAngle
1681 itemScale: stagedRightEdgeMaths.animatedScale
1682 scaleToPreviewSize: spreadItem.stackHeight
1683 scaleToPreviewProgress: stagedRightEdgeMaths.scaleToPreviewProgress
1684 shadowOpacity: .3
1685 }
1686 // make sure it's visible but transparent so it fades in when we transition to spread
1687 PropertyChanges { target: windowInfoItem; opacity: 0; visible: true }
1688 },
1689 State {
1690 name: "windowedRightEdge"
1691 when: root.mode == "windowed" && (root.state == "windowedRightEdge" || rightEdgeFocusAnimation.running || hidingAnimation.running || rightEdgePushProgress > 0)
1692 PropertyChanges {
1693 target: windowedRightEdgeMaths
1694 swipeProgress: rightEdgeDragArea.dragging ? rightEdgeDragArea.progress : 0
1695 pushProgress: rightEdgePushProgress
1696 }
1697 PropertyChanges {
1698 target: appDelegate
1699 x: windowedRightEdgeMaths.animatedX
1700 y: windowedRightEdgeMaths.animatedY
1701 z: windowedRightEdgeMaths.animatedZ
1702 height: stagedRightEdgeMaths.animatedHeight
1703 }
1704 PropertyChanges {
1705 target: decoratedWindow
1706 showDecoration: windowedRightEdgeMaths.decorationHeight
1707 angle: windowedRightEdgeMaths.animatedAngle
1708 itemScale: windowedRightEdgeMaths.animatedScale
1709 scaleToPreviewSize: spreadItem.stackHeight
1710 scaleToPreviewProgress: windowedRightEdgeMaths.scaleToPreviewProgress
1711 shadowOpacity: .3
1712 }
1713 PropertyChanges {
1714 target: opacityEffect;
1715 opacityValue: windowedRightEdgeMaths.opacityMask
1716 sourceItem: windowedRightEdgeMaths.opacityMask < 1 ? decoratedWindow : null
1717 }
1718 },
1719 State {
1720 name: "staged"; when: root.state == "staged"
1721 PropertyChanges {
1722 target: appDelegate
1723 x: stageMaths.itemX
1724 y: root.availableDesktopArea.y
1725 visuallyMaximized: true
1726 visible: appDelegate.x < root.width
1727 }
1728 PropertyChanges {
1729 target: appDelegate
1730 requestedWidth: appContainer.width
1731 requestedHeight: root.availableDesktopArea.height
1732 restoreEntryValues: false
1733 }
1734 PropertyChanges {
1735 target: decoratedWindow
1736 hasDecoration: false
1737 }
1738 PropertyChanges {
1739 target: resizeArea
1740 enabled: false
1741 }
1742 PropertyChanges {
1743 target: stageMaths
1744 animateX: !focusAnimation.running && !rightEdgeFocusAnimation.running && itemIndex !== spreadItem.highlightedIndex && !inhibitSlideAnimation
1745 }
1746 PropertyChanges {
1747 target: appDelegate.window
1748 allowClientResize: false
1749 }
1750 },
1751 State {
1752 name: "stagedWithSideStage"; when: root.state == "stagedWithSideStage"
1753 PropertyChanges {
1754 target: stageMaths
1755 itemIndex: index
1756 }
1757 PropertyChanges {
1758 target: appDelegate
1759 x: stageMaths.itemX
1760 y: root.availableDesktopArea.y
1761 z: stageMaths.itemZ
1762 visuallyMaximized: true
1763 visible: appDelegate.x < root.width
1764 }
1765 PropertyChanges {
1766 target: appDelegate
1767 requestedWidth: stageMaths.itemWidth
1768 requestedHeight: root.availableDesktopArea.height
1769 restoreEntryValues: false
1770 }
1771 PropertyChanges {
1772 target: decoratedWindow
1773 hasDecoration: false
1774 }
1775 PropertyChanges {
1776 target: resizeArea
1777 enabled: false
1778 }
1779 PropertyChanges {
1780 target: appDelegate.window
1781 allowClientResize: false
1782 }
1783 },
1784 State {
1785 name: "maximized"; when: appDelegate.maximized && !appDelegate.minimized
1786 PropertyChanges {
1787 target: appDelegate;
1788 requestedX: root.availableDesktopArea.x;
1789 requestedY: 0;
1790 visuallyMinimized: false;
1791 visuallyMaximized: true
1792 }
1793 PropertyChanges {
1794 target: appDelegate
1795 requestedWidth: root.availableDesktopArea.width;
1796 requestedHeight: appContainer.height;
1797 restoreEntryValues: false
1798 }
1799 PropertyChanges { target: touchControls; enabled: true }
1800 PropertyChanges { target: decoratedWindow; windowControlButtonsVisible: false }
1801 },
1802 State {
1803 name: "fullscreen"; when: appDelegate.fullscreen && !appDelegate.minimized
1804 PropertyChanges {
1805 target: appDelegate;
1806 requestedX: 0
1807 requestedY: 0
1808 }
1809 PropertyChanges {
1810 target: appDelegate
1811 requestedWidth: appContainer.width
1812 requestedHeight: appContainer.height
1813 restoreEntryValues: false
1814 }
1815 PropertyChanges { target: decoratedWindow; hasDecoration: false }
1816 },
1817 // TODO: merge normal and restored together, there's no point in normal being a distinct state
1818 State {
1819 name: "normal";
1820 PropertyChanges {
1821 target: appDelegate
1822 visuallyMinimized: false
1823 }
1824 PropertyChanges { target: touchControls; enabled: true }
1825 PropertyChanges { target: resizeArea; enabled: true }
1826 PropertyChanges { target: decoratedWindow; shadowOpacity: .3; windowControlButtonsVisible: true}
1827 PropertyChanges {
1828 target: appDelegate
1829 requestedWidth: windowedWidth
1830 requestedHeight: windowedHeight
1831 restoreEntryValues: false
1832 }
1833 },
1834 State {
1835 name: "restored";
1836 when: appDelegate.windowState == Mir.RestoredState
1837 extend: "normal"
1838 PropertyChanges {
1839 restoreEntryValues: false
1840 target: appDelegate;
1841 windowedX: restoredX;
1842 windowedY: restoredY;
1843 }
1844 },
1845 State {
1846 name: "maximizedLeft"; when: appDelegate.maximizedLeft && !appDelegate.minimized
1847 extend: "normal"
1848 PropertyChanges {
1849 target: appDelegate
1850 windowedX: root.availableDesktopArea.x
1851 windowedY: root.availableDesktopArea.y
1852 windowedWidth: root.availableDesktopArea.width / 2
1853 windowedHeight: root.availableDesktopArea.height
1854 }
1855 },
1856 State {
1857 name: "maximizedRight"; when: appDelegate.maximizedRight && !appDelegate.minimized
1858 extend: "maximizedLeft"
1859 PropertyChanges {
1860 target: appDelegate;
1861 windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
1862 }
1863 },
1864 State {
1865 name: "maximizedTopLeft"; when: appDelegate.maximizedTopLeft && !appDelegate.minimized
1866 extend: "normal"
1867 PropertyChanges {
1868 target: appDelegate
1869 windowedX: root.availableDesktopArea.x
1870 windowedY: root.availableDesktopArea.y
1871 windowedWidth: root.availableDesktopArea.width / 2
1872 windowedHeight: root.availableDesktopArea.height / 2
1873 }
1874 },
1875 State {
1876 name: "maximizedTopRight"; when: appDelegate.maximizedTopRight && !appDelegate.minimized
1877 extend: "maximizedTopLeft"
1878 PropertyChanges {
1879 target: appDelegate
1880 windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
1881 }
1882 },
1883 State {
1884 name: "maximizedBottomLeft"; when: appDelegate.maximizedBottomLeft && !appDelegate.minimized
1885 extend: "normal"
1886 PropertyChanges {
1887 target: appDelegate
1888 windowedX: root.availableDesktopArea.x
1889 windowedY: root.availableDesktopArea.y + (root.availableDesktopArea.height / 2)
1890 windowedWidth: root.availableDesktopArea.width / 2
1891 windowedHeight: root.availableDesktopArea.height / 2
1892 }
1893 },
1894 State {
1895 name: "maximizedBottomRight"; when: appDelegate.maximizedBottomRight && !appDelegate.minimized
1896 extend: "maximizedBottomLeft"
1897 PropertyChanges {
1898 target: appDelegate
1899 windowedX: root.availableDesktopArea.x + (root.availableDesktopArea.width / 2)
1900 }
1901 },
1902 State {
1903 name: "maximizedHorizontally"; when: appDelegate.maximizedHorizontally && !appDelegate.minimized
1904 extend: "normal"
1905 PropertyChanges {
1906 target: appDelegate
1907 windowedX: root.availableDesktopArea.x; windowedY: windowedY
1908 windowedWidth: root.availableDesktopArea.width; windowedHeight: windowedHeight
1909 }
1910 },
1911 State {
1912 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
1913 extend: "normal"
1914 PropertyChanges {
1915 target: appDelegate
1916 windowedX: windowedX; windowedY: root.availableDesktopArea.y
1917 windowedWidth: windowedWidth; windowedHeight: root.availableDesktopArea.height
1918 }
1919 },
1920 State {
1921 name: "minimized"; when: appDelegate.minimized
1922 PropertyChanges {
1923 target: appDelegate
1924 scale: units.gu(5) / appDelegate.width
1925 opacity: 0;
1926 visuallyMinimized: true
1927 visuallyMaximized: false
1928 x: -appDelegate.width / 2
1929 y: root.height / 2
1930 }
1931 }
1932 ]
1933
1934 transitions: [
1935
1936 // These two animate applications into position from Staged to Desktop and back
1937 Transition {
1938 from: "staged,stagedWithSideStage"
1939 to: "normal,restored,maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight"
1940 enabled: appDelegate.animationsEnabled
1941 PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized" }
1942 LomiriNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,opacity,requestedWidth,requestedHeight,scale"; duration: priv.animationDuration }
1943 },
1944 Transition {
1945 from: "normal,restored,maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight"
1946 to: "staged,stagedWithSideStage"
1947 LomiriNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,requestedWidth,requestedHeight"; duration: priv.animationDuration}
1948 },
1949
1950 Transition {
1951 from: "normal,restored,maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight,staged,stagedWithSideStage,windowedRightEdge,stagedRightEdge";
1952 to: "spread"
1953 // DecoratedWindow wants the scaleToPreviewSize set before enabling scaleToPreview
1954 PropertyAction { target: appDelegate; properties: "z,visible" }
1955 PropertyAction { target: decoratedWindow; property: "scaleToPreviewSize" }
1956 LomiriNumberAnimation { target: appDelegate; properties: "x,y,height"; duration: priv.animationDuration }
1957 LomiriNumberAnimation { target: decoratedWindow; properties: "width,height,itemScale,angle,scaleToPreviewProgress"; duration: priv.animationDuration }
1958 LomiriNumberAnimation { target: windowInfoItem; properties: "opacity"; duration: priv.animationDuration }
1959 },
1960 Transition {
1961 from: "normal,staged"; to: "stagedWithSideStage"
1962 LomiriNumberAnimation { target: appDelegate; properties: "x,y,requestedWidth,requestedHeight"; duration: priv.animationDuration }
1963 },
1964 Transition {
1965 to: "windowedRightEdge"
1966 ScriptAction {
1967 script: {
1968 windowedRightEdgeMaths.startX = appDelegate.requestedX
1969 windowedRightEdgeMaths.startY = appDelegate.requestedY
1970
1971 if (index == 1) {
1972 var thisRect = { x: appDelegate.windowedX, y: appDelegate.windowedY, width: appDelegate.requestedWidth, height: appDelegate.requestedHeight }
1973 var otherDelegate = appRepeater.itemAt(0);
1974 var otherRect = { x: otherDelegate.windowedX, y: otherDelegate.windowedY, width: otherDelegate.requestedWidth, height: otherDelegate.requestedHeight }
1975 var intersectionRect = MathUtils.intersectionRect(thisRect, otherRect)
1976 var mappedInterSectionRect = appDelegate.mapFromItem(root, intersectionRect.x, intersectionRect.y)
1977 opacityEffect.maskX = mappedInterSectionRect.x
1978 opacityEffect.maskY = mappedInterSectionRect.y
1979 opacityEffect.maskWidth = intersectionRect.width
1980 opacityEffect.maskHeight = intersectionRect.height
1981 }
1982 }
1983 }
1984 },
1985 Transition {
1986 from: "stagedRightEdge"; to: "staged"
1987 enabled: rightEdgeDragArea.cancelled // only transition back to state if the gesture was cancelled, in the other cases we play the focusAnimations.
1988 SequentialAnimation {
1989 ParallelAnimation {
1990 LomiriNumberAnimation { target: appDelegate; properties: "x,y,height,width,scale"; duration: priv.animationDuration }
1991 LomiriNumberAnimation { target: decoratedWindow; properties: "width,height,itemScale,angle,scaleToPreviewProgress"; duration: priv.animationDuration }
1992 }
1993 // We need to release scaleToPreviewSize at last
1994 PropertyAction { target: decoratedWindow; property: "scaleToPreviewSize" }
1995 PropertyAction { target: appDelegate; property: "visible" }
1996 }
1997 },
1998 Transition {
1999 from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
2000 to: "minimized"
2001 SequentialAnimation {
2002 ScriptAction { script: { fakeRectangle.stop(); } }
2003 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
2004 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
2005 LomiriNumberAnimation { target: appDelegate; properties: "x,y,scale,opacity"; duration: priv.animationDuration }
2006 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
2007 }
2008 },
2009 Transition {
2010 from: "minimized"
2011 to: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
2012 SequentialAnimation {
2013 PropertyAction { target: appDelegate; property: "visuallyMinimized,z" }
2014 ParallelAnimation {
2015 LomiriNumberAnimation { target: appDelegate; properties: "x"; from: -appDelegate.width / 2; duration: priv.animationDuration }
2016 LomiriNumberAnimation { target: appDelegate; properties: "y,opacity"; duration: priv.animationDuration }
2017 LomiriNumberAnimation { target: appDelegate; properties: "scale"; from: 0; duration: priv.animationDuration }
2018 }
2019 PropertyAction { target: appDelegate; property: "visuallyMaximized" }
2020 }
2021 },
2022 Transition {
2023 id: windowedTransition
2024 from: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen,minimized"
2025 to: ",normal,restored,maximized,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedTopRight,maximizedBottomLeft,maximizedBottomRight,maximizedHorizontally,maximizedVertically,fullscreen"
2026 enabled: appDelegate.animationsEnabled
2027 SequentialAnimation {
2028 ScriptAction { script: {
2029 if (appDelegate.visuallyMaximized) visuallyMaximized = false; // maximized before -> going to restored
2030 }
2031 }
2032 PropertyAction { target: appDelegate; property: "visuallyMinimized" }
2033 LomiriNumberAnimation { target: appDelegate; properties: "requestedX,requestedY,windowedX,windowedY,opacity,scale,requestedWidth,requestedHeight,windowedWidth,windowedHeight";
2034 duration: priv.animationDuration }
2035 ScriptAction { script: {
2036 fakeRectangle.stop();
2037 appDelegate.visuallyMaximized = appDelegate.maximized; // reflect the target state
2038 }
2039 }
2040 }
2041 }
2042 ]
2043
2044 Binding {
2045 target: panelState
2046 property: "decorationsAlwaysVisible"
2047 value: appDelegate && appDelegate.maximized && touchControls.overlayShown
2048 restoreMode: Binding.RestoreBinding
2049 }
2050
2051 WindowResizeArea {
2052 id: resizeArea
2053 objectName: "windowResizeArea"
2054
2055 anchors.fill: appDelegate
2056
2057 // workaround so that it chooses the correct resize borders when you drag from a corner ResizeGrip
2058 anchors.margins: touchControls.overlayShown ? borderThickness/2 : -borderThickness
2059
2060 target: appDelegate
2061 boundsItem: root.availableDesktopArea
2062 minWidth: units.gu(10)
2063 minHeight: units.gu(10)
2064 borderThickness: units.gu(2)
2065 enabled: false
2066 visible: enabled
2067 readyToAssesBounds: !appDelegate._constructing
2068
2069 onPressed: {
2070 appDelegate.activate();
2071 }
2072 }
2073
2074 DecoratedWindow {
2075 id: decoratedWindow
2076 objectName: "decoratedWindow"
2077 anchors.left: appDelegate.left
2078 anchors.top: appDelegate.top
2079 application: model.application
2080 surface: model.window.surface
2081 active: model.window.focused
2082 focus: true
2083 interactive: root.interactive
2084 showDecoration: 1
2085 decorationHeight: priv.windowDecorationHeight
2086 maximizeButtonShown: appDelegate.canBeMaximized
2087 overlayShown: touchControls.overlayShown
2088 width: implicitWidth
2089 height: implicitHeight
2090 highlightSize: windowInfoItem.iconMargin
2091 boundsItem: root.availableDesktopArea
2092 panelState: root.panelState
2093 altDragEnabled: root.mode == "windowed"
2094
2095 requestedWidth: appDelegate.requestedWidth
2096 requestedHeight: appDelegate.requestedHeight
2097
2098 onCloseClicked: { appDelegate.close(); }
2099 onMaximizeClicked: {
2100 if (appDelegate.canBeMaximized) {
2101 appDelegate.anyMaximized ? appDelegate.requestRestore() : appDelegate.requestMaximize();
2102 }
2103 }
2104 onMaximizeHorizontallyClicked: {
2105 if (appDelegate.canBeMaximizedHorizontally) {
2106 appDelegate.maximizedHorizontally ? appDelegate.requestRestore() : appDelegate.requestMaximizeHorizontally()
2107 }
2108 }
2109 onMaximizeVerticallyClicked: {
2110 if (appDelegate.canBeMaximizedVertically) {
2111 appDelegate.maximizedVertically ? appDelegate.requestRestore() : appDelegate.requestMaximizeVertically()
2112 }
2113 }
2114 onMinimizeClicked: { appDelegate.requestMinimize(); }
2115 onDecorationPressed: { appDelegate.activate(); }
2116 onDecorationReleased: fakeRectangle.visible ? fakeRectangle.commit() : appDelegate.updateRestoredGeometry()
2117
2118 onDragResizePressed: {
2119 appDelegate.activate();
2120 resizeArea.pressedChangedEx(true, mouse);
2121 }
2122 onDragResizeReleased: resizeArea.pressedChangedEx(false, mouse);
2123 onDragResizePositionChanged: resizeArea.positionChangedEx(mouse);
2124
2125 property real angle: 0
2126 Behavior on angle { enabled: priv.closingIndex >= 0; LomiriNumberAnimation {} }
2127 property real itemScale: 1
2128 Behavior on itemScale { enabled: priv.closingIndex >= 0; LomiriNumberAnimation {} }
2129
2130 transform: [
2131 Scale {
2132 origin.x: 0
2133 origin.y: decoratedWindow.implicitHeight / 2
2134 xScale: decoratedWindow.itemScale
2135 yScale: decoratedWindow.itemScale
2136 },
2137 Rotation {
2138 origin { x: 0; y: (decoratedWindow.height / 2) }
2139 axis { x: 0; y: 1; z: 0 }
2140 angle: decoratedWindow.angle
2141 }
2142 ]
2143 }
2144
2145 OpacityMask {
2146 id: opacityEffect
2147 anchors.fill: decoratedWindow
2148 }
2149
2150 WindowControlsOverlay {
2151 id: touchControls
2152 anchors.fill: appDelegate
2153 target: appDelegate
2154 resizeArea: resizeArea
2155 enabled: false
2156 visible: enabled
2157 boundsItem: root.availableDesktopArea
2158
2159 onFakeMaximizeAnimationRequested: if (!appDelegate.maximized) fakeRectangle.maximize(amount, true)
2160 onFakeMaximizeLeftAnimationRequested: if (!appDelegate.maximizedLeft) fakeRectangle.maximizeLeft(amount, true)
2161 onFakeMaximizeRightAnimationRequested: if (!appDelegate.maximizedRight) fakeRectangle.maximizeRight(amount, true)
2162 onFakeMaximizeTopLeftAnimationRequested: if (!appDelegate.maximizedTopLeft) fakeRectangle.maximizeTopLeft(amount, true);
2163 onFakeMaximizeTopRightAnimationRequested: if (!appDelegate.maximizedTopRight) fakeRectangle.maximizeTopRight(amount, true);
2164 onFakeMaximizeBottomLeftAnimationRequested: if (!appDelegate.maximizedBottomLeft) fakeRectangle.maximizeBottomLeft(amount, true);
2165 onFakeMaximizeBottomRightAnimationRequested: if (!appDelegate.maximizedBottomRight) fakeRectangle.maximizeBottomRight(amount, true);
2166 onStopFakeAnimation: fakeRectangle.stop();
2167 onDragReleased: fakeRectangle.visible ? fakeRectangle.commit() : appDelegate.updateRestoredGeometry()
2168 }
2169
2170 WindowedFullscreenPolicy {
2171 id: windowedFullscreenPolicy
2172 }
2173 StagedFullscreenPolicy {
2174 id: stagedFullscreenPolicy
2175 active: root.mode == "staged" || root.mode == "stagedWithSideStage"
2176 surface: model.window.surface
2177 }
2178
2179 SpreadDelegateInputArea {
2180 id: dragArea
2181 objectName: "dragArea"
2182 anchors.fill: decoratedWindow
2183 enabled: false
2184 closeable: true
2185 stage: root
2186 dragDelegate: fakeDragItem
2187
2188 onClicked: {
2189 spreadItem.highlightedIndex = index;
2190 if (distance == 0) {
2191 priv.goneToSpread = false;
2192 }
2193 }
2194 onClose: {
2195 priv.closingIndex = index
2196 appDelegate.close();
2197 }
2198 }
2199
2200 WindowInfoItem {
2201 id: windowInfoItem
2202 objectName: "windowInfoItem"
2203 anchors { left: parent.left; top: decoratedWindow.bottom; topMargin: units.gu(1) }
2204 title: model.application.name
2205 iconSource: model.application.icon
2206 height: spreadItem.appInfoHeight
2207 opacity: 0
2208 z: 1
2209 visible: opacity > 0
2210 maxWidth: {
2211 var nextApp = appRepeater.itemAt(index + 1);
2212 if (nextApp) {
2213 return Math.max(iconHeight, nextApp.x - appDelegate.x - units.gu(1))
2214 }
2215 return appDelegate.width;
2216 }
2217
2218 onClicked: {
2219 spreadItem.highlightedIndex = index;
2220 priv.goneToSpread = false;
2221 }
2222 }
2223
2224 MouseArea {
2225 id: closeMouseArea
2226 objectName: "closeMouseArea"
2227 anchors { left: parent.left; top: parent.top; leftMargin: -height / 2; topMargin: -height / 2 + spreadMaths.closeIconOffset }
2228 readonly property var mousePos: hoverMouseArea.mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
2229 readonly property bool shown: dragArea.distance == 0
2230 && index == spreadItem.highlightedIndex
2231 && mousePos.y < (decoratedWindow.height / 3)
2232 && mousePos.y > -units.gu(4)
2233 && mousePos.x > -units.gu(4)
2234 && mousePos.x < (decoratedWindow.width * 2 / 3)
2235 opacity: shown ? 1 : 0
2236 visible: opacity > 0
2237 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
2238 height: units.gu(6)
2239 width: height
2240
2241 onClicked: {
2242 priv.closingIndex = index;
2243 appDelegate.close();
2244 }
2245 Image {
2246 id: closeImage
2247 source: "graphics/window-close.svg"
2248 anchors.fill: closeMouseArea
2249 anchors.margins: units.gu(2)
2250 sourceSize.width: width
2251 sourceSize.height: height
2252 }
2253 }
2254
2255 Item {
2256 // Group all child windows in this item so that we can fade them out together when going to the spread
2257 // (and fade them in back again when returning from it)
2258 readonly property bool stageOnProperState: root.state === "windowed"
2259 || root.state === "staged"
2260 || root.state === "stagedWithSideStage"
2261
2262 // TODO: Is it worth the extra cost of layering to avoid the opacity artifacts of intersecting children?
2263 // Btw, will involve more than uncommenting the line below as children won't necessarily fit this item's
2264 // geometry. This is just a reference.
2265 //layer.enabled: opacity !== 0.0 && opacity !== 1.0
2266
2267 opacity: stageOnProperState ? 1.0 : 0.0
2268 visible: opacity !== 0.0 // make it transparent to input as well
2269 Behavior on opacity { LomiriNumberAnimation {} }
2270
2271 Repeater {
2272 id: childWindowRepeater
2273 model: appDelegate.surface ? appDelegate.surface.childSurfaceList : null
2274
2275 delegate: ChildWindowTree {
2276 surface: model.surface
2277
2278 // Account for the displacement caused by window decoration in the top-level surface
2279 // Ie, the top-level surface is not positioned at (0,0) of this ChildWindow's parent (appDelegate)
2280 displacementX: appDelegate.clientAreaItem.x
2281 displacementY: appDelegate.clientAreaItem.y
2282
2283 boundsItem: root.availableDesktopArea
2284 decorationHeight: priv.windowDecorationHeight
2285
2286 z: childWindowRepeater.count - model.index
2287
2288 onFocusChanged: {
2289 if (focus) {
2290 // some child surface in this tree got focus.
2291 // Ensure we also have it at the top-level hierarchy
2292 appDelegate.claimFocus();
2293 }
2294 }
2295 }
2296 }
2297 }
2298 }
2299 }
2300 }
2301
2302 FakeMaximizeDelegate {
2303 id: fakeRectangle
2304 target: priv.focusedAppDelegate
2305 leftMargin: root.availableDesktopArea.x
2306 appContainerWidth: appContainer.width
2307 appContainerHeight: appContainer.height
2308 panelState: root.panelState
2309 }
2310
2311 WorkspaceSwitcher {
2312 id: workspaceSwitcher
2313 enabled: workspaceEnabled
2314 anchors.centerIn: parent
2315 height: units.gu(20)
2316 width: root.width - units.gu(8)
2317 background: root.background
2318 availableDesktopArea: root.availableDesktopArea
2319 onWorkspaceSelected: screensAndWorkspaces.activeWorkspace = selectedWorkspace;
2320 onActiveChanged: {
2321 if (!active) {
2322 appContainer.focus = true;
2323 }
2324 }
2325 }
2326
2327 PropertyAnimation {
2328 id: shortRightEdgeSwipeAnimation
2329 property: "x"
2330 to: 0
2331 duration: priv.animationDuration
2332 }
2333
2334 SwipeArea {
2335 id: rightEdgeDragArea
2336 objectName: "rightEdgeDragArea"
2337 direction: Direction.Leftwards
2338 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
2339 width: root.dragAreaWidth
2340 enabled: root.spreadEnabled
2341
2342 property var gesturePoints: []
2343 property bool cancelled: false
2344
2345 property real progress: -touchPosition.x / root.width
2346 onProgressChanged: {
2347 if (dragging) {
2348 draggedProgress = progress;
2349 }
2350 }
2351
2352 property real draggedProgress: 0
2353
2354 onTouchPositionChanged: {
2355 gesturePoints.push(touchPosition.x);
2356 if (gesturePoints.length > 10) {
2357 gesturePoints.splice(0, gesturePoints.length - 10)
2358 }
2359 }
2360
2361 onDraggingChanged: {
2362 if (dragging) {
2363 // A potential edge-drag gesture has started. Start recording it
2364 gesturePoints = [];
2365 cancelled = false;
2366 draggedProgress = 0;
2367 } else {
2368 // Ok. The user released. Did he drag far enough to go to full spread?
2369 if (gesturePoints[gesturePoints.length - 1] < -spreadItem.rightEdgeBreakPoint * spreadItem.width ) {
2370
2371 // He dragged far enough, but if the last movement was a flick to the right again, he wants to cancel the spread again.
2372 var oneWayFlickToRight = true;
2373 var smallestX = gesturePoints[0]-1;
2374 for (var i = 0; i < gesturePoints.length; i++) {
2375 if (gesturePoints[i] <= smallestX) {
2376 oneWayFlickToRight = false;
2377 break;
2378 }
2379 smallestX = gesturePoints[i];
2380 }
2381
2382 if (!oneWayFlickToRight) {
2383 // Ok, the user made it, let's go to spread!
2384 priv.goneToSpread = true;
2385 } else {
2386 cancelled = true;
2387 }
2388 } else {
2389 // Ok, the user didn't drag far enough to cross the breakPoint
2390 // Find out if it was a one-way movement to the left, in which case we just switch directly to next app.
2391 var oneWayFlick = true;
2392 var smallestX = rightEdgeDragArea.width;
2393 for (var i = 0; i < gesturePoints.length; i++) {
2394 if (gesturePoints[i] >= smallestX) {
2395 oneWayFlick = false;
2396 break;
2397 }
2398 smallestX = gesturePoints[i];
2399 }
2400
2401 if (appRepeater.count > 1 &&
2402 (oneWayFlick && rightEdgeDragArea.distance > units.gu(2) || rightEdgeDragArea.distance > spreadItem.rightEdgeBreakPoint * spreadItem.width)) {
2403 var nextStage = appRepeater.itemAt(priv.nextInStack).stage
2404 for (var i = 0; i < appRepeater.count; i++) {
2405 if (i != priv.nextInStack && appRepeater.itemAt(i).stage == nextStage) {
2406 appRepeater.itemAt(i).playHidingAnimation()
2407 break;
2408 }
2409 }
2410 appRepeater.itemAt(priv.nextInStack).playFocusAnimation()
2411 if (appRepeater.itemAt(priv.nextInStack).stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
2412 sideStage.show();
2413 }
2414
2415 } else {
2416 cancelled = true;
2417 }
2418
2419 gesturePoints = [];
2420 }
2421 }
2422 }
2423
2424 GestureAreaSizeHint {
2425 anchors.fill: parent
2426 }
2427 }
2428
2429 TabletSideStageTouchGesture {
2430 id: triGestureArea
2431 objectName: "triGestureArea"
2432 anchors.fill: parent
2433 enabled: false
2434 property Item appDelegate
2435
2436 dragComponent: dragComponent
2437 dragComponentProperties: { "appDelegate": appDelegate }
2438
2439 onPressed: {
2440 function matchDelegate(obj) { return String(obj.objectName).indexOf("appDelegate") >= 0; }
2441
2442 var delegateAtCenter = Functions.itemAt(appContainer, x, y, matchDelegate);
2443 if (!delegateAtCenter) return;
2444
2445 appDelegate = delegateAtCenter;
2446 }
2447
2448 onClicked: {
2449 priv.toggleSideStage()
2450 }
2451
2452 onDragStarted: {
2453 // If we're dragging to the sidestage.
2454 if (!sideStage.shown) {
2455 sideStage.show();
2456 }
2457 }
2458
2459 onDropped: {
2460 // Hide side stage if the app drag was cancelled
2461 if (!priv.sideStageDelegate) {
2462 sideStage.hide();
2463 }
2464 }
2465
2466 Component {
2467 id: dragComponent
2468 SurfaceContainer {
2469 property Item appDelegate
2470
2471 surface: appDelegate ? appDelegate.surface : null
2472
2473 consumesInput: false
2474 interactive: false
2475 focus: false
2476 requestedWidth: appDelegate ? appDelegate.requestedWidth : 0
2477 requestedHeight: appDelegate ? appDelegate.requestedHeight : 0
2478
2479 width: units.gu(40)
2480 height: units.gu(40)
2481
2482 Drag.hotSpot.x: width/2
2483 Drag.hotSpot.y: height/2
2484 // only accept opposite stage.
2485 Drag.keys: {
2486 if (!surface) return "Disabled";
2487
2488 if (appDelegate.stage === ApplicationInfo.MainStage) {
2489 if (appDelegate.application.supportedOrientations
2490 & (Qt.PortraitOrientation|Qt.InvertedPortraitOrientation)) {
2491 return "MainStage";
2492 }
2493 return "Disabled";
2494 }
2495 return "SideStage";
2496 }
2497 }
2498 }
2499 }
2500}