on e17b0ef help sign in
unity8/qml/Shell.qml
750 lines 26 kB history raw
1/*
2 * Copyright (C) 2013-2015 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 WindowKeysFilter
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 bool cursorVisible: false
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 (mainApp) {
89 return shell.orientations.map(mainApp.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
106 // Disable everything while greeter is waiting, so that the user can't swipe
107 // the greeter or launcher until we know whether the session is locked.
108 enabled: greeter && !greeter.waiting
110 property real edgeSize: units.gu(2)
112 WallpaperResolver {
113 id: wallpaperResolver
114 width: shell.width
115 }
117 readonly property alias greeter: greeterLoader.item
119 function activateApplication(appId) {
120 if (ApplicationManager.findApplication(appId)) {
121 ApplicationManager.requestFocusApplication(appId);
122 } else {
123 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
124 : ApplicationManager.NoFlag;
125 ApplicationManager.startApplication(appId, execFlags);
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.SuruGradient"
144 if (ApplicationManager.count > 0) {
145 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
146 }
147 finishStartUpTimer.start();
148 }
150 LightDM{id: lightDM} // Provide backend access
151 VolumeControl {
152 id: volumeControl
153 indicators: panel.indicators
154 }
156 DashCommunicator {
157 id: dash
158 objectName: "dashCommunicator"
159 }
161 PhysicalKeysMapper {
162 id: physicalKeysMapper
163 objectName: "physicalKeysMapper"
165 onPowerKeyLongPressed: dialogs.showPowerDialog();
166 onVolumeDownTriggered: volumeControl.volumeDown();
167 onVolumeUpTriggered: volumeControl.volumeUp();
168 onScreenshotTriggered: screenGrabber.capture();
169 }
171 GlobalShortcut {
172 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
173 }
175 WindowKeysFilter {
176 Keys.onPressed: physicalKeysMapper.onKeyPressed(event, currentEventTimestamp);
177 Keys.onReleased: physicalKeysMapper.onKeyReleased(event, currentEventTimestamp);
178 }
180 HomeKeyWatcher {
181 onActivated: { launcher.fadeOut(); shell.showHome(); }
182 }
184 GSettings {
185 id: settings
186 schema.id: "com.canonical.Unity8"
187 }
189 Item {
190 id: stages
191 objectName: "stages"
192 width: parent.width
193 height: parent.height
195 Connections {
196 target: ApplicationManager
198 // This signal is also fired when we try to focus the current app
199 // again. We rely on this!
200 onFocusedApplicationIdChanged: {
201 var appId = ApplicationManager.focusedApplicationId;
203 if (tutorial.running && appId != "" && appId != "unity8-dash") {
204 // If this happens on first boot, we may be in edge
205 // tutorial or wizard while receiving a call. But a call
206 // is more important than wizard so just bail out of those.
207 tutorial.finish();
208 wizard.hide();
209 }
211 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
212 // If we are in the middle of a call, make dialer lockedApp and show it.
213 // This can happen if user backs out of dialer back to greeter, then
214 // launches dialer again.
215 greeter.lockedApp = appId;
216 }
217 greeter.notifyAppFocused(appId);
219 panel.indicators.hide();
220 }
222 onApplicationAdded: {
223 launcher.hide();
224 }
225 }
227 Loader {
228 id: applicationsDisplayLoader
229 objectName: "applicationsDisplayLoader"
230 anchors.fill: parent
232 // When we have a locked app, we only want to show that one app.
233 // FIXME: do this in a less traumatic way. We currently only allow
234 // locked apps in phone mode (see FIXME in Lockscreen component in
235 // this same file). When that changes, we need to do something
236 // nicer here. But this code is currently just to prevent a
237 // theoretical attack where user enters lockedApp mode, then makes
238 // the screen larger (maybe connects to monitor) and tries to enter
239 // tablet mode.
241 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
242 ? "phone"
243 : shell.usageScenario
244 source: {
245 if(shell.mode === "greeter") {
246 return "Stages/ShimStage.qml"
247 } else if (applicationsDisplayLoader.usageScenario === "phone") {
248 return "Stages/PhoneStage.qml";
249 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
250 return "Stages/TabletStage.qml";
251 } else {
252 return "Stages/DesktopStage.qml";
253 }
254 }
256 property bool interactive: tutorial.spreadEnabled
257 && (!greeter || !greeter.shown)
258 && panel.indicators.fullyClosed
259 && launcher.progress == 0
260 && !notifications.useModal
262 onInteractiveChanged: { if (interactive) { focus = true; } }
264 Binding {
265 target: applicationsDisplayLoader.item
266 property: "objectName"
267 value: "stage"
268 }
269 Binding {
270 target: applicationsDisplayLoader.item
271 property: "dragAreaWidth"
272 value: shell.edgeSize
273 }
274 Binding {
275 target: applicationsDisplayLoader.item
276 property: "maximizedAppTopMargin"
277 // Not just using panel.panelHeight as that changes depending on the focused app.
278 value: panel.indicators.minimizedPanelHeight
279 }
280 Binding {
281 target: applicationsDisplayLoader.item
282 property: "interactive"
283 value: applicationsDisplayLoader.interactive
284 }
285 Binding {
286 target: applicationsDisplayLoader.item
287 property: "spreadEnabled"
288 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
289 }
290 Binding {
291 target: applicationsDisplayLoader.item
292 property: "inverseProgress"
293 value: greeter && greeter.locked ? 0 : launcher.progress
294 }
295 Binding {
296 target: applicationsDisplayLoader.item
297 property: "shellOrientationAngle"
298 value: shell.orientationAngle
299 }
300 Binding {
301 target: applicationsDisplayLoader.item
302 property: "shellOrientation"
303 value: shell.orientation
304 }
305 Binding {
306 target: applicationsDisplayLoader.item
307 property: "orientations"
308 value: shell.orientations
309 }
310 Binding {
311 target: applicationsDisplayLoader.item
312 property: "background"
313 value: wallpaperResolver.background
314 }
315 Binding {
316 target: applicationsDisplayLoader.item
317 property: "nativeWidth"
318 value: shell.nativeWidth
319 }
320 Binding {
321 target: applicationsDisplayLoader.item
322 property: "nativeHeight"
323 value: shell.nativeHeight
324 }
325 Binding {
326 target: applicationsDisplayLoader.item
327 property: "beingResized"
328 value: shell.beingResized
329 }
330 Binding {
331 target: applicationsDisplayLoader.item
332 property: "keepDashRunning"
333 value: launcher.shown || launcher.dashSwipe
334 }
335 Binding {
336 target: applicationsDisplayLoader.item
337 property: "suspended"
338 value: greeter.shown
339 }
340 Binding {
341 target: applicationsDisplayLoader.item
342 property: "altTabPressed"
343 value: physicalKeysMapper.altTabPressed
344 }
345 Binding {
346 target: applicationsDisplayLoader.item
347 property: "leftMargin"
348 value: launcher.lockedVisible ? launcher.panelWidth: 0
349 }
350 }
352 Tutorial {
353 id: tutorial
354 objectName: "tutorial"
355 anchors.fill: parent
357 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
358 // we skip the tutorial on the Desktop to avoid using them. The
359 // Desktop doesn't use the same spread design anyway. The tutorial is
360 // all a bit of a placeholder on non-phone form factors right now.
361 // When the design team gives us more guidance, we can do something
362 // more clever here.
363 active: usageScenario != "desktop" && AccountsService.demoEdges
365 paused: lightDM.greeter.active
366 launcher: launcher
367 panel: panel
368 edgeSize: shell.edgeSize
370 onFinished: {
371 AccountsService.demoEdges = false;
372 active = false; // for immediate response / if AS is having problems
373 }
374 }
375 }
377 InputMethod {
378 id: inputMethod
379 objectName: "inputMethod"
380 anchors {
381 fill: parent
382 topMargin: panel.panelHeight
383 leftMargin: launcher.lockedVisible ? launcher.panelWidth : 0
384 }
385 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
386 }
388 Connections {
389 target: SessionManager
390 onSessionStopping: {
391 if (!session.parentSession && !session.application) {
392 // nothing is using it. delete it right away
393 session.release();
394 }
395 }
396 }
398 Loader {
399 id: greeterLoader
400 anchors.fill: parent
401 anchors.topMargin: panel.panelHeight
402 sourceComponent: shell.mode != "shell" ? integratedGreeter :
403 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
404 onLoaded: {
405 item.objectName = "greeter"
406 }
407 }
409 Component {
410 id: integratedGreeter
411 Greeter {
413 hides: [launcher, panel.indicators]
414 tabletMode: shell.usageScenario != "phone"
415 launcherOffset: launcher.progress
416 forcedUnlock: tutorial.running
417 background: wallpaperResolver.background
419 // avoid overlapping with Launcher's edge drag area
420 // FIXME: Fix TouchRegistry & friends and remove this workaround
421 // Issue involves launcher's DDA getting disabled on a long
422 // left-edge drag
423 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
425 onSessionStarted: {
426 launcher.hide();
427 }
429 onTease: {
430 if (!tutorial.running) {
431 launcher.tease();
432 }
433 }
435 onEmergencyCall: startLockedApp("dialer-app")
436 }
437 }
439 Timer {
440 // See powerConnection for why this is useful
441 id: showGreeterDelayed
442 interval: 1
443 onTriggered: {
444 greeter.forceShow();
445 }
446 }
448 Connections {
449 id: callConnection
450 target: callManager
452 onHasCallsChanged: {
453 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
454 // We just received an incoming call while locked. The
455 // indicator will have already launched dialer-app for us, but
456 // there is a race between "hasCalls" changing and the dialer
457 // starting up. So in case we lose that race, we'll start/
458 // focus the dialer ourselves here too. Even if the indicator
459 // didn't launch the dialer for some reason (or maybe a call
460 // started via some other means), if an active call is
461 // happening, we want to be in the dialer.
462 startLockedApp("dialer-app")
463 }
464 }
465 }
467 Connections {
468 id: powerConnection
469 target: Powerd
471 onStatusChanged: {
472 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
473 !callManager.hasCalls && !tutorial.running) {
474 // We don't want to simply call greeter.showNow() here, because
475 // that will take too long. Qt will delay button event
476 // handling until the greeter is done loading and may think the
477 // user held down the power button the whole time, leading to a
478 // power dialog being shown. Instead, delay showing the
479 // greeter until we've finished handling the event. We could
480 // make the greeter load asynchronously instead, but that
481 // introduces a whole host of timing issues, especially with
482 // its animations. So this is simpler.
483 showGreeterDelayed.start();
484 }
485 }
486 }
488 function showHome() {
489 if (tutorial.running) {
490 return
491 }
493 greeter.notifyAboutToFocusApp("unity8-dash");
495 var animate = !lightDM.greeter.active && !stages.shown
496 dash.setCurrentScope(0, animate, false)
497 ApplicationManager.requestFocusApplication("unity8-dash")
498 }
500 function showDash() {
501 if (greeter.notifyShowingDashFromDrag()) {
502 launcher.fadeOut();
503 }
505 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
506 ApplicationManager.requestFocusApplication("unity8-dash")
507 launcher.fadeOut();
508 }
509 }
511 Item {
512 id: overlay
513 z: 10
515 anchors.fill: parent
517 Panel {
518 id: panel
519 objectName: "panel"
520 anchors.fill: parent //because this draws indicator menus
521 indicators {
522 hides: [launcher]
523 available: tutorial.panelEnabled
524 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
525 && (!greeter || !greeter.hasLockedApp)
526 contentEnabled: tutorial.panelContentEnabled
527 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
529 minimizedPanelHeight: units.gu(3)
530 expandedPanelHeight: units.gu(7)
532 indicatorsModel: Indicators.IndicatorsModel {
533 // tablet and phone both use the same profile
534 profile: "phone"
535 Component.onCompleted: load();
536 }
537 }
539 callHint {
540 greeterShown: greeter.shown
541 }
543 readonly property bool topmostApplicationIsFullscreen:
544 ApplicationManager.focusedApplicationId &&
545 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
547 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
548 || greeter.hasLockedApp
549 locked: greeter && greeter.active
550 }
552 Launcher {
553 id: launcher
554 objectName: "launcher"
556 readonly property bool dashSwipe: progress > 0
558 anchors.top: parent.top
559 anchors.topMargin: inverted ? 0 : panel.panelHeight
560 anchors.bottom: parent.bottom
561 width: parent.width
562 dragAreaWidth: shell.edgeSize
563 available: tutorial.launcherEnabled
564 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
565 && !greeter.hasLockedApp
566 inverted: shell.usageScenario !== "desktop"
567 shadeBackground: !tutorial.running
568 superPressed: physicalKeysMapper.superPressed
569 superTabPressed: physicalKeysMapper.superTabPressed
570 panelWidth: units.gu(launcherSettings.launcherWidth)
571 lockedVisible: shell.usageScenario == "desktop" && !settings.autohideLauncher
573 onShowDashHome: showHome()
574 onDash: showDash()
575 onDashSwipeChanged: {
576 if (dashSwipe) {
577 dash.setCurrentScope(0, false, true)
578 }
579 }
580 onLauncherApplicationSelected: {
581 if (!tutorial.running) {
582 greeter.notifyAboutToFocusApp(appId);
583 shell.activateApplication(appId)
584 }
585 }
586 onShownChanged: {
587 if (shown) {
588 panel.indicators.hide()
589 }
590 }
591 onFocusChanged: {
592 if (!focus) {
593 applicationsDisplayLoader.focus = true;
594 }
595 }
597 GlobalShortcut {
598 shortcut: Qt.AltModifier | Qt.Key_F1
599 onTriggered: {
600 launcher.openForKeyboardNavigation();
601 }
602 }
603 GlobalShortcut {
604 shortcut: Qt.MetaModifier | Qt.Key_0
605 onTriggered: {
606 if (LauncherModel.get(9)) {
607 activateApplication(LauncherModel.get(9).appId);
608 }
609 }
610 }
611 Repeater {
612 model: 9
613 GlobalShortcut {
614 shortcut: Qt.MetaModifier | (Qt.Key_1 + index)
615 onTriggered: {
616 if (LauncherModel.get(index)) {
617 activateApplication(LauncherModel.get(index).appId);
618 }
619 }
620 }
621 }
622 }
624 Wizard {
625 id: wizard
626 objectName: "wizard"
627 anchors.fill: parent
628 background: wallpaperResolver.background
630 function unlockWhenDoneWithWizard() {
631 if (!active) {
632 Connectivity.unlockAllModems();
633 }
634 }
636 Component.onCompleted: unlockWhenDoneWithWizard()
637 onActiveChanged: unlockWhenDoneWithWizard()
638 }
640 Rectangle {
641 id: modalNotificationBackground
643 visible: notifications.useModal
644 color: "#000000"
645 anchors.fill: parent
646 opacity: 0.9
648 MouseArea {
649 anchors.fill: parent
650 }
651 }
653 Notifications {
654 id: notifications
656 model: NotificationBackend.Model
657 margin: units.gu(1)
658 hasMouse: shell.hasMouse
659 background: wallpaperResolver.background
661 y: topmostIsFullscreen ? 0 : panel.panelHeight
662 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
664 states: [
665 State {
666 name: "narrow"
667 when: overlay.width <= units.gu(60)
668 AnchorChanges {
669 target: notifications
670 anchors.left: parent.left
671 anchors.right: parent.right
672 }
673 },
674 State {
675 name: "wide"
676 when: overlay.width > units.gu(60)
677 AnchorChanges {
678 target: notifications
679 anchors.left: undefined
680 anchors.right: parent.right
681 }
682 PropertyChanges { target: notifications; width: units.gu(38) }
683 }
684 ]
685 }
686 }
688 Dialogs {
689 id: dialogs
690 objectName: "dialogs"
691 anchors.fill: parent
692 z: overlay.z + 10
693 usageScenario: shell.usageScenario
694 onPowerOffClicked: {
695 shutdownFadeOutRectangle.enabled = true;
696 shutdownFadeOutRectangle.visible = true;
697 shutdownFadeOut.start();
698 }
699 }
701 Connections {
702 target: SessionBroadcast
703 onShowHome: showHome()
704 }
706 ScreenGrabber {
707 id: screenGrabber
708 rotationAngle: -shell.orientationAngle
709 z: dialogs.z + 10
710 }
712 Cursor {
713 id: cursor
714 visible: shell.hasMouse
715 z: screenGrabber.z + 1
717 onPushedLeftBoundary: {
718 if (buttons === Qt.NoButton) {
719 launcher.pushEdge(amount);
720 }
721 }
723 onPushedRightBoundary: {
724 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
725 && applicationsDisplayLoader.item.pushRightEdge) {
726 applicationsDisplayLoader.item.pushRightEdge(amount);
727 }
728 }
729 }
731 Rectangle {
732 id: shutdownFadeOutRectangle
733 z: cursor.z + 1
734 enabled: false
735 visible: false
736 color: "black"
737 anchors.fill: parent
738 opacity: 0.0
739 NumberAnimation on opacity {
740 id: shutdownFadeOut
741 from: 0.0
742 to: 1.0
743 onStopped: {
744 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
745 DBusUnitySessionService.shutdown();
746 }
747 }
748 }
749 }