on 924ea90 help sign in
unity8/qml/Shell.qml
791 lines 27 kB history raw
1/*
2 * Copyright (C) 2013-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 */
17import QtQuick 2.4
18import QtQuick.Window 2.2
19import AccountsService 0.1
20import Unity.Application 0.1
21import Ubuntu.Components 1.3
22import Ubuntu.Components.Popups 1.3
23import Ubuntu.Gestures 0.1
24import Ubuntu.Telephony 0.1 as Telephony
25import Unity.Connectivity 0.1
26import Unity.Launcher 0.1
27import GlobalShortcut 1.0 // has to be before Utils, because of WindowInputFilter
28import GSettings 1.0
29import Utils 0.1
30import Powerd 0.1
31import SessionBroadcast 0.1
32import "Greeter"
33import "Launcher"
34import "Panel"
35import "Components"
36import "Notifications"
37import "Stages"
38import "Tutorial"
39import "Wizard"
40import Unity.Notifications 1.0 as NotificationBackend
41import Unity.Session 0.1
42import Unity.DashCommunicator 0.1
43import Unity.Indicators 0.1 as Indicators
44import Cursor 1.0
47Item {
48 id: shell
50 // to be set from outside
51 property int orientationAngle: 0
52 property int orientation
53 property Orientations orientations
54 property real nativeWidth
55 property real nativeHeight
56 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
57 property bool beingResized
58 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
59 property string mode: "full-greeter"
60 property alias oskEnabled: inputMethod.enabled
61 function updateFocusedAppOrientation() {
62 applicationsDisplayLoader.item.updateFocusedAppOrientation();
63 }
64 function updateFocusedAppOrientationAnimated() {
65 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
66 }
67 property bool hasMouse: false
69 // to be read from outside
70 readonly property int mainAppWindowOrientationAngle:
71 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
73 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
74 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
75 && (!greeter || !greeter.animating)
77 readonly property bool showingGreeter: greeter && greeter.shown
79 property bool startingUp: true
80 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
82 property int supportedOrientations: {
83 if (startingUp) {
84 // Ensure we don't rotate during start up
85 return Qt.PrimaryOrientation;
86 } else if (greeter && greeter.shown) {
87 return Qt.PrimaryOrientation;
88 } else if (applicationsDisplayLoader.item) {
89 return shell.orientations.map(applicationsDisplayLoader.item.supportedOrientations);
90 } else {
91 // we just don't care
92 return Qt.PortraitOrientation
93 | Qt.LandscapeOrientation
94 | Qt.InvertedPortraitOrientation
95 | Qt.InvertedLandscapeOrientation;
96 }
97 }
99 // For autopilot consumption
100 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
102 // internal props from here onwards
103 readonly property var mainApp:
104 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105 readonly property var mainAppWindow:
106 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindow : null
108 // Disable everything while greeter is waiting, so that the user can't swipe
109 // the greeter or launcher until we know whether the session is locked.
110 enabled: greeter && !greeter.waiting
112 property real edgeSize: units.gu(2)
114 WallpaperResolver {
115 id: wallpaperResolver
116 width: shell.width
117 }
119 readonly property alias greeter: greeterLoader.item
121 function activateApplication(appId) {
122 if (ApplicationManager.findApplication(appId)) {
123 ApplicationManager.requestFocusApplication(appId);
124 } else {
125 ApplicationManager.startApplication(appId);
126 }
127 }
129 function startLockedApp(app) {
130 if (greeter.locked) {
131 greeter.lockedApp = app;
132 }
133 shell.activateApplication(app);
134 }
136 Binding {
137 target: LauncherModel
138 property: "applicationManager"
139 value: ApplicationManager
140 }
142 Component.onCompleted: {
143 theme.name = "Ubuntu.Components.Themes.SuruDark"
144 if (ApplicationManager.count > 0) {
145 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
146 }
147 finishStartUpTimer.start();
148 }
150 VolumeControl {
151 id: volumeControl
152 indicators: panel.indicators
153 }
155 DashCommunicator {
156 id: dash
157 objectName: "dashCommunicator"
158 }
160 PhysicalKeysMapper {
161 id: physicalKeysMapper
162 objectName: "physicalKeysMapper"
164 onPowerKeyLongPressed: dialogs.showPowerDialog();
165 onVolumeDownTriggered: volumeControl.volumeDown();
166 onVolumeUpTriggered: volumeControl.volumeUp();
167 onScreenshotTriggered: screenGrabber.capture();
168 }
170 GlobalShortcut {
171 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowInputFilter
172 }
174 WindowInputFilter {
175 id: inputFilter
176 Keys.onPressed: physicalKeysMapper.onKeyPressed(event, lastInputTimestamp);
177 Keys.onReleased: physicalKeysMapper.onKeyReleased(event, lastInputTimestamp);
178 }
180 WindowInputMonitor {
181 onHomeKeyActivated: { launcher.fadeOut(); shell.showHome(); }
182 onTouchBegun: { cursor.opacity = 0; }
183 onTouchEnded: {
184 // move the (hidden) cursor to the last known touch position
185 var mappedCoords = mapFromItem(null, pos.x, pos.y);
186 cursor.x = mappedCoords.x;
187 cursor.y = mappedCoords.y;
188 }
189 }
191 GSettings {
192 id: settings
193 schema.id: "com.canonical.Unity8"
194 }
196 Item {
197 id: stages
198 objectName: "stages"
199 width: parent.width
200 height: parent.height
202 Connections {
203 target: ApplicationManager
205 // This signal is also fired when we try to focus the current app
206 // again. We rely on this!
207 onFocusedApplicationIdChanged: {
208 var appId = ApplicationManager.focusedApplicationId;
210 if (wizard.active && appId != "" && appId != "unity8-dash") {
211 // If this happens on first boot, we may be in edge
212 // tutorial or wizard while receiving a call. But a call
213 // is more important than wizard so just bail out of those.
214 tutorial.finish();
215 wizard.hide();
216 }
218 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
219 // If we are in the middle of a call, make dialer lockedApp and show it.
220 // This can happen if user backs out of dialer back to greeter, then
221 // launches dialer again.
222 greeter.lockedApp = appId;
223 }
224 greeter.notifyAppFocused(appId);
226 panel.indicators.hide();
227 }
229 onApplicationAdded: {
230 launcher.hide();
231 }
232 }
234 Loader {
235 id: applicationsDisplayLoader
236 objectName: "applicationsDisplayLoader"
237 anchors.fill: parent
239 // When we have a locked app, we only want to show that one app.
240 // FIXME: do this in a less traumatic way. We currently only allow
241 // locked apps in phone mode (see FIXME in Lockscreen component in
242 // this same file). When that changes, we need to do something
243 // nicer here. But this code is currently just to prevent a
244 // theoretical attack where user enters lockedApp mode, then makes
245 // the screen larger (maybe connects to monitor) and tries to enter
246 // tablet mode.
248 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
249 ? "phone"
250 : shell.usageScenario
251 readonly property string qmlComponent: {
252 if(shell.mode === "greeter") {
253 return "Stages/ShimStage.qml"
254 } else if (applicationsDisplayLoader.usageScenario === "phone") {
255 return "Stages/PhoneStage.qml";
256 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
257 return "Stages/TabletStage.qml";
258 } else {
259 return "Stages/DesktopStage.qml";
260 }
261 }
262 onQmlComponentChanged: {
263 if (item) item.stageAboutToBeUnloaded();
264 source = qmlComponent;
265 }
267 property bool interactive: (!greeter || !greeter.shown)
268 && panel.indicators.fullyClosed
269 && launcher.progress == 0
270 && !notifications.useModal
272 onInteractiveChanged: { if (interactive) { focus = true; } }
274 Binding {
275 target: applicationsDisplayLoader.item
276 property: "objectName"
277 value: "stage"
278 }
279 Binding {
280 target: applicationsDisplayLoader.item
281 property: "dragAreaWidth"
282 value: shell.edgeSize
283 }
284 Binding {
285 target: applicationsDisplayLoader.item
286 property: "maximizedAppTopMargin"
287 // Not just using panel.panelHeight as that changes depending on the focused app.
288 value: panel.indicators.minimizedPanelHeight
289 }
290 Binding {
291 target: applicationsDisplayLoader.item
292 property: "interactive"
293 value: applicationsDisplayLoader.interactive
294 }
295 Binding {
296 target: applicationsDisplayLoader.item
297 property: "spreadEnabled"
298 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
299 }
300 Binding {
301 target: applicationsDisplayLoader.item
302 property: "inverseProgress"
303 value: greeter && greeter.locked ? 0 : launcher.progress
304 }
305 Binding {
306 target: applicationsDisplayLoader.item
307 property: "shellOrientationAngle"
308 value: shell.orientationAngle
309 }
310 Binding {
311 target: applicationsDisplayLoader.item
312 property: "shellOrientation"
313 value: shell.orientation
314 }
315 Binding {
316 target: applicationsDisplayLoader.item
317 property: "orientations"
318 value: shell.orientations
319 }
320 Binding {
321 target: applicationsDisplayLoader.item
322 property: "background"
323 value: wallpaperResolver.background
324 }
325 Binding {
326 target: applicationsDisplayLoader.item
327 property: "nativeWidth"
328 value: shell.nativeWidth
329 }
330 Binding {
331 target: applicationsDisplayLoader.item
332 property: "nativeHeight"
333 value: shell.nativeHeight
334 }
335 Binding {
336 target: applicationsDisplayLoader.item
337 property: "beingResized"
338 value: shell.beingResized
339 }
340 Binding {
341 target: applicationsDisplayLoader.item
342 property: "keepDashRunning"
343 value: launcher.shown || launcher.dashSwipe
344 }
345 Binding {
346 target: applicationsDisplayLoader.item
347 property: "suspended"
348 value: greeter.shown
349 }
350 Binding {
351 target: applicationsDisplayLoader.item
352 property: "altTabPressed"
353 value: physicalKeysMapper.altTabPressed
354 }
355 Binding {
356 target: applicationsDisplayLoader.item
357 property: "leftMargin"
358 value: shell.usageScenario == "desktop" && !settings.autohideLauncher ? launcher.panelWidth: 0
359 }
360 }
362 InputMethod {
363 id: inputMethod
364 objectName: "inputMethod"
365 anchors {
366 fill: parent
367 topMargin: panel.panelHeight
368 leftMargin: launcher.lockedVisible ? launcher.panelWidth : 0
369 }
370 z: notifications.useModal || panel.indicators.shown || wizard.active || tutorial.running ? overlay.z + 1 : overlay.z - 1
371 }
373 Connections {
374 target: SessionManager
375 onSessionStopping: {
376 if (!session.parentSession && !session.application) {
377 // nothing is using it. delete it right away
378 session.release();
379 }
380 }
381 }
383 Loader {
384 id: greeterLoader
385 anchors.fill: parent
386 anchors.topMargin: panel.panelHeight
387 sourceComponent: shell.mode != "shell" ? integratedGreeter :
388 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
389 onLoaded: {
390 item.objectName = "greeter"
391 }
392 }
394 Component {
395 id: integratedGreeter
396 Greeter {
398 hides: [launcher, panel.indicators]
399 tabletMode: shell.usageScenario != "phone"
400 launcherOffset: launcher.progress
401 forcedUnlock: wizard.active
402 background: wallpaperResolver.background
404 // avoid overlapping with Launcher's edge drag area
405 // FIXME: Fix TouchRegistry & friends and remove this workaround
406 // Issue involves launcher's DDA getting disabled on a long
407 // left-edge drag
408 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
410 onSessionStarted: {
411 launcher.hide();
412 }
414 onTease: {
415 if (!tutorial.running) {
416 launcher.tease();
417 }
418 }
420 onEmergencyCall: startLockedApp("dialer-app")
421 }
422 }
424 Timer {
425 // See powerConnection for why this is useful
426 id: showGreeterDelayed
427 interval: 1
428 onTriggered: {
429 greeter.forceShow();
430 }
431 }
433 Connections {
434 id: callConnection
435 target: callManager
437 onHasCallsChanged: {
438 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
439 // We just received an incoming call while locked. The
440 // indicator will have already launched dialer-app for us, but
441 // there is a race between "hasCalls" changing and the dialer
442 // starting up. So in case we lose that race, we'll start/
443 // focus the dialer ourselves here too. Even if the indicator
444 // didn't launch the dialer for some reason (or maybe a call
445 // started via some other means), if an active call is
446 // happening, we want to be in the dialer.
447 startLockedApp("dialer-app")
448 }
449 }
450 }
452 Connections {
453 id: powerConnection
454 target: Powerd
456 onStatusChanged: {
457 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
458 !callManager.hasCalls && !wizard.active) {
459 // We don't want to simply call greeter.showNow() here, because
460 // that will take too long. Qt will delay button event
461 // handling until the greeter is done loading and may think the
462 // user held down the power button the whole time, leading to a
463 // power dialog being shown. Instead, delay showing the
464 // greeter until we've finished handling the event. We could
465 // make the greeter load asynchronously instead, but that
466 // introduces a whole host of timing issues, especially with
467 // its animations. So this is simpler.
468 showGreeterDelayed.start();
469 }
470 }
471 }
473 function showHome() {
474 greeter.notifyAboutToFocusApp("unity8-dash");
476 var animate = !LightDMService.greeter.active && !stages.shown
477 dash.setCurrentScope(0, animate, false)
478 ApplicationManager.requestFocusApplication("unity8-dash")
479 }
481 function showDash() {
482 if (greeter.notifyShowingDashFromDrag()) {
483 launcher.fadeOut();
484 }
486 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
487 ApplicationManager.requestFocusApplication("unity8-dash")
488 launcher.fadeOut();
489 }
490 }
492 Item {
493 id: overlay
494 z: 10
496 anchors.fill: parent
498 Panel {
499 id: panel
500 objectName: "panel"
501 anchors.fill: parent //because this draws indicator menus
502 indicators {
503 hides: [launcher]
504 available: tutorial.panelEnabled
505 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
506 && (!greeter || !greeter.hasLockedApp)
507 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
509 minimizedPanelHeight: units.gu(3)
510 expandedPanelHeight: units.gu(7)
512 indicatorsModel: Indicators.IndicatorsModel {
513 // tablet and phone both use the same profile
514 profile: "phone"
515 Component.onCompleted: load();
516 }
517 }
519 callHint {
520 greeterShown: greeter.shown
521 }
523 readonly property bool topmostApplicationIsFullscreen: mainApp && mainApp.fullscreen
525 fullscreenMode: (topmostApplicationIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0)
526 || greeter.hasLockedApp
527 locked: greeter && greeter.active
528 }
530 Launcher {
531 id: launcher
532 objectName: "launcher"
534 readonly property bool dashSwipe: progress > 0
536 anchors.top: parent.top
537 anchors.topMargin: inverted ? 0 : panel.panelHeight
538 anchors.bottom: parent.bottom
539 width: parent.width
540 dragAreaWidth: shell.edgeSize
541 available: tutorial.launcherEnabled
542 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
543 && !greeter.hasLockedApp
544 inverted: shell.usageScenario !== "desktop"
545 superPressed: physicalKeysMapper.superPressed
546 superTabPressed: physicalKeysMapper.superTabPressed
547 panelWidth: units.gu(settings.launcherWidth)
548 lockedVisible: shell.usageScenario == "desktop" && !settings.autohideLauncher && !panel.fullscreenMode
550 onShowDashHome: showHome()
551 onDash: showDash()
552 onDashSwipeChanged: {
553 if (dashSwipe) {
554 dash.setCurrentScope(0, false, true)
555 }
556 }
557 onLauncherApplicationSelected: {
558 greeter.notifyAboutToFocusApp(appId);
559 shell.activateApplication(appId);
560 }
561 onShownChanged: {
562 if (shown) {
563 panel.indicators.hide()
564 }
565 }
566 onFocusChanged: {
567 if (!focus) {
568 applicationsDisplayLoader.focus = true;
569 }
570 }
572 GlobalShortcut {
573 shortcut: Qt.AltModifier | Qt.Key_F1
574 onTriggered: {
575 launcher.openForKeyboardNavigation();
576 }
577 }
578 GlobalShortcut {
579 shortcut: Qt.MetaModifier | Qt.Key_0
580 onTriggered: {
581 if (LauncherModel.get(9)) {
582 activateApplication(LauncherModel.get(9).appId);
583 }
584 }
585 }
586 Repeater {
587 model: 9
588 GlobalShortcut {
589 shortcut: Qt.MetaModifier | (Qt.Key_1 + index)
590 onTriggered: {
591 if (LauncherModel.get(index)) {
592 activateApplication(LauncherModel.get(index).appId);
593 }
594 }
595 }
596 }
597 }
599 Tutorial {
600 id: tutorial
601 objectName: "tutorial"
602 anchors.fill: parent
604 paused: callManager.hasCalls || greeter.shown
605 keyboardVisible: inputMethod.state === "shown"
606 usageScenario: shell.usageScenario
607 lastInputTimestamp: inputFilter.lastInputTimestamp
608 launcher: launcher
609 panel: panel
610 stage: applicationsDisplayLoader.item
611 }
613 Wizard {
614 id: wizard
615 objectName: "wizard"
616 anchors.fill: parent
617 deferred: shell.mode === "greeter"
618 background: wallpaperResolver.background
620 function unlockWhenDoneWithWizard() {
621 if (!active) {
622 Connectivity.unlockAllModems();
623 }
624 }
626 Component.onCompleted: unlockWhenDoneWithWizard()
627 onActiveChanged: unlockWhenDoneWithWizard()
628 }
630 Rectangle {
631 id: modalNotificationBackground
633 visible: notifications.useModal
634 color: "#000000"
635 anchors.fill: parent
636 opacity: 0.9
638 MouseArea {
639 anchors.fill: parent
640 }
641 }
643 Notifications {
644 id: notifications
646 model: NotificationBackend.Model
647 margin: units.gu(1)
648 hasMouse: shell.hasMouse
649 inverseMode: panel.indicators.shown
650 background: wallpaperResolver.background
652 y: topmostIsFullscreen ? 0 : panel.panelHeight
653 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
655 states: [
656 State {
657 name: "narrow"
658 when: overlay.width <= units.gu(60)
659 AnchorChanges {
660 target: notifications
661 anchors.left: parent.left
662 anchors.right: parent.right
663 }
664 },
665 State {
666 name: "wide"
667 when: overlay.width > units.gu(60)
668 AnchorChanges {
669 target: notifications
670 anchors.left: undefined
671 anchors.right: parent.right
672 }
673 PropertyChanges { target: notifications; width: units.gu(38) }
674 }
675 ]
676 }
677 }
679 Dialogs {
680 id: dialogs
681 objectName: "dialogs"
682 anchors.fill: parent
683 z: overlay.z + 10
684 usageScenario: shell.usageScenario
685 onPowerOffClicked: {
686 shutdownFadeOutRectangle.enabled = true;
687 shutdownFadeOutRectangle.visible = true;
688 shutdownFadeOut.start();
689 }
690 }
692 Connections {
693 target: SessionBroadcast
694 onShowHome: showHome()
695 }
697 ScreenGrabber {
698 id: screenGrabber
699 rotationAngle: -shell.orientationAngle
700 z: dialogs.z + 10
701 }
703 Cursor {
704 id: cursor
705 visible: shell.hasMouse
706 z: screenGrabber.z + 1
708 onPushedLeftBoundary: {
709 if (buttons === Qt.NoButton) {
710 launcher.pushEdge(amount);
711 }
712 }
714 onPushedRightBoundary: {
715 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
716 && applicationsDisplayLoader.item.pushRightEdge) {
717 applicationsDisplayLoader.item.pushRightEdge(amount);
718 }
719 }
721 onMouseMoved: { cursor.opacity = 1; }
722 }
724 // keymap switching
725 GlobalShortcut {
726 shortcut: Qt.MetaModifier|Qt.Key_Space
727 onTriggered: keymapPriv.nextKeymap()
728 active: keymapPriv.keymapCount > 1
729 }
731 GlobalShortcut {
732 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
733 onTriggered: keymapPriv.previousKeymap()
734 active: keymapPriv.keymapCount > 1
735 }
737 QtObject {
738 id: keymapPriv
740 readonly property var keymaps: AccountsService.keymaps
741 readonly property int keymapCount: keymaps.length
742 property int currentKeymapIndex: 0 // the new one that we're setting
743 onCurrentKeymapIndexChanged: switchToKeymap();
745 function nextKeymap() {
746 var nextIndex = 0;
748 if (currentKeymapIndex !== -1 && currentKeymapIndex < keymapCount - 1) {
749 nextIndex = currentKeymapIndex + 1;
750 }
751 currentKeymapIndex = nextIndex;
752 }
754 function previousKeymap() {
755 var prevIndex = keymapCount - 1;
757 if (currentKeymapIndex > 0) {
758 prevIndex = currentKeymapIndex - 1;
759 }
760 currentKeymapIndex = prevIndex;
761 }
763 function switchToKeymap() {
764 if (mainAppWindow) {
765 mainAppWindow.switchToKeymap(keymaps[currentKeymapIndex]);
766 }
767 }
768 }
770 onMainAppWindowChanged: keymapPriv.switchToKeymap()
772 Rectangle {
773 id: shutdownFadeOutRectangle
774 z: cursor.z + 1
775 enabled: false
776 visible: false
777 color: "black"
778 anchors.fill: parent
779 opacity: 0.0
780 NumberAnimation on opacity {
781 id: shutdownFadeOut
782 from: 0.0
783 to: 1.0
784 onStopped: {
785 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
786 DBusUnitySessionService.shutdown();
787 }
788 }
789 }
790 }