on b83f384 help sign in
unity8/qml/Shell.qml
737 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.0
18import QtQuick.Window 2.0
19import AccountsService 0.1
20import GSettings 1.0
21import Unity.Application 0.1
22import Ubuntu.Components 0.1
23import Ubuntu.Components.Popups 1.0
24import Ubuntu.Gestures 0.1
25import Ubuntu.Telephony 0.1 as Telephony
26import Unity.Connectivity 0.1
27import Unity.Launcher 0.1
28import GlobalShortcut 1.0 // has to be before Utils, because of WindowKeysFilter
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
46Item {
47 id: shell
49 // to be set from outside
50 property int orientationAngle: 0
51 property int orientation
52 property int primaryOrientation
53 property int nativeOrientation
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 function updateFocusedAppOrientation() {
61 applicationsDisplayLoader.item.updateFocusedAppOrientation();
62 }
63 function updateFocusedAppOrientationAnimated() {
64 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
65 }
66 property bool hasMouse
68 // to be read from outside
69 readonly property int mainAppWindowOrientationAngle:
70 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
72 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
73 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
74 && (!greeter || !greeter.animating)
76 readonly property bool showingGreeter: greeter && greeter.shown
78 property bool startingUp: true
79 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
81 property int supportedOrientations: {
82 if (startingUp) {
83 // Ensure we don't rotate during start up
84 return Qt.PrimaryOrientation;
85 } else if (greeter && greeter.shown) {
86 return Qt.PrimaryOrientation;
87 } else if (mainApp) {
88 return mainApp.supportedOrientations;
89 } else {
90 // we just don't care
91 return Qt.PortraitOrientation
92 | Qt.LandscapeOrientation
93 | Qt.InvertedPortraitOrientation
94 | Qt.InvertedLandscapeOrientation;
95 }
96 }
98 // For autopilot consumption
99 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
101 // internal props from here onwards
102 readonly property var mainApp:
103 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105 // Disable everything while greeter is waiting, so that the user can't swipe
106 // the greeter or launcher until we know whether the session is locked.
107 enabled: greeter && !greeter.waiting
109 property real edgeSize: units.gu(2)
110 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
111 property url background: asImageTester.status == Image.Ready ? asImageTester.source
112 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
114 readonly property alias greeter: greeterLoader.item
116 function activateApplication(appId) {
117 if (ApplicationManager.findApplication(appId)) {
118 ApplicationManager.requestFocusApplication(appId);
119 } else {
120 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
121 : ApplicationManager.NoFlag;
122 ApplicationManager.startApplication(appId, execFlags);
123 }
124 }
126 function startLockedApp(app) {
127 if (greeter.locked) {
128 greeter.lockedApp = app;
129 }
130 shell.activateApplication(app);
131 }
133 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
134 Image {
135 id: asImageTester
136 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
137 height: 0
138 width: 0
139 sourceSize.height: 0
140 sourceSize.width: 0
141 }
143 GSettings {
144 id: backgroundSettings
145 schema.id: "org.gnome.desktop.background"
146 }
148 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
149 Image {
150 id: gsImageTester
151 source: backgroundSettings.pictureUri && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
152 height: 0
153 width: 0
154 sourceSize.height: 0
155 sourceSize.width: 0
156 }
158 Binding {
159 target: LauncherModel
160 property: "applicationManager"
161 value: ApplicationManager
162 }
164 Component.onCompleted: {
165 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
166 if (ApplicationManager.count > 0) {
167 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
168 }
169 finishStartUpTimer.start();
170 }
172 LightDM{id: lightDM} // Provide backend access
173 VolumeControl {
174 id: volumeControl
175 indicators: panel.indicators
176 }
178 DashCommunicator {
179 id: dash
180 objectName: "dashCommunicator"
181 }
183 PhysicalKeysMapper {
184 id: physicalKeysMapper
185 objectName: "physicalKeysMapper"
187 onPowerKeyLongPressed: dialogs.showPowerDialog();
188 onVolumeDownTriggered: volumeControl.volumeDown();
189 onVolumeUpTriggered: volumeControl.volumeUp();
190 onScreenshotTriggered: screenGrabber.capture();
191 }
193 ScreenGrabber {
194 id: screenGrabber
195 z: dialogs.z + 10
196 }
198 GlobalShortcut {
199 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
200 }
202 WindowKeysFilter {
203 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
204 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
205 }
207 HomeKeyWatcher {
208 onActivated: { launcher.fadeOut(); shell.showHome(); }
209 }
211 Item {
212 id: stages
213 objectName: "stages"
214 width: parent.width
215 height: parent.height
217 GSettings {
218 id: lifecycleExceptions
219 schema.id: "com.canonical.qtmir"
220 }
222 function isExemptFromLifecycle(appId) {
223 for (var i = 0; i < lifecycleExceptions.lifecycleExemptAppids.length; i++) {
224 if (appId === lifecycleExceptions.lifecycleExemptAppids[i]) {
225 return true;
226 }
227 }
228 return false;
229 }
231 Connections {
232 target: ApplicationManager
234 // This signal is also fired when we try to focus the current app
235 // again. We rely on this!
236 onFocusedApplicationIdChanged: {
237 var appId = ApplicationManager.focusedApplicationId;
239 if (tutorial.running && appId != "" && appId != "unity8-dash") {
240 // If this happens on first boot, we may be in edge
241 // tutorial or wizard while receiving a call. But a call
242 // is more important than wizard so just bail out of those.
243 tutorial.finish();
244 wizard.hide();
245 }
247 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
248 // If we are in the middle of a call, make dialer lockedApp and show it.
249 // This can happen if user backs out of dialer back to greeter, then
250 // launches dialer again.
251 greeter.lockedApp = appId;
252 }
253 greeter.notifyAppFocused(appId);
255 panel.indicators.hide();
256 }
258 onApplicationAdded: {
259 launcher.hide();
261 // Apply lifecycle policy when an app is opened
262 var app = ApplicationManager.findApplication(appId);
263 if (app) {
264 // We don't bother with a Qt.binding because isTouchApp is
265 // marked as CONSTANT by unity-api, and we neither expect
266 // the gsettings to change on us during the life of the app,
267 // nor does it make a whole lot of sense to adjust the
268 // lifecycle policy while the app is running.
269 app.canSuspend = app.isTouchApp && !stages.isExemptFromLifecycle(appId);
270 }
271 }
272 }
274 Loader {
275 id: applicationsDisplayLoader
276 objectName: "applicationsDisplayLoader"
277 anchors.fill: parent
279 // When we have a locked app, we only want to show that one app.
280 // FIXME: do this in a less traumatic way. We currently only allow
281 // locked apps in phone mode (see FIXME in Lockscreen component in
282 // this same file). When that changes, we need to do something
283 // nicer here. But this code is currently just to prevent a
284 // theoretical attack where user enters lockedApp mode, then makes
285 // the screen larger (maybe connects to monitor) and tries to enter
286 // tablet mode.
288 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
289 ? "phone"
290 : shell.usageScenario
291 source: {
292 if(shell.mode === "greeter") {
293 return "Stages/ShimStage.qml"
294 } else if (applicationsDisplayLoader.usageScenario === "phone") {
295 return "Stages/PhoneStage.qml";
296 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
297 return "Stages/TabletStage.qml";
298 } else {
299 return "Stages/DesktopStage.qml";
300 }
301 }
303 property bool interactive: tutorial.spreadEnabled
304 && (!greeter || !greeter.shown)
305 && panel.indicators.fullyClosed
306 && launcher.progress == 0
307 && !notifications.useModal
309 onInteractiveChanged: { if (interactive) { focus = true; } }
311 Binding {
312 target: applicationsDisplayLoader.item
313 property: "objectName"
314 value: "stage"
315 }
316 Binding {
317 target: applicationsDisplayLoader.item
318 property: "dragAreaWidth"
319 value: shell.edgeSize
320 }
321 Binding {
322 target: applicationsDisplayLoader.item
323 property: "maximizedAppTopMargin"
324 // Not just using panel.panelHeight as that changes depending on the focused app.
325 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
326 }
327 Binding {
328 target: applicationsDisplayLoader.item
329 property: "interactive"
330 value: applicationsDisplayLoader.interactive
331 }
332 Binding {
333 target: applicationsDisplayLoader.item
334 property: "spreadEnabled"
335 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
336 }
337 Binding {
338 target: applicationsDisplayLoader.item
339 property: "inverseProgress"
340 value: greeter && greeter.locked ? 0 : launcher.progress
341 }
342 Binding {
343 target: applicationsDisplayLoader.item
344 property: "shellOrientationAngle"
345 value: shell.orientationAngle
346 }
347 Binding {
348 target: applicationsDisplayLoader.item
349 property: "shellOrientation"
350 value: shell.orientation
351 }
352 Binding {
353 target: applicationsDisplayLoader.item
354 property: "background"
355 value: shell.background
356 }
357 Binding {
358 target: applicationsDisplayLoader.item
359 property: "shellPrimaryOrientation"
360 value: shell.primaryOrientation
361 }
362 Binding {
363 target: applicationsDisplayLoader.item
364 property: "nativeOrientation"
365 value: shell.nativeOrientation
366 }
367 Binding {
368 target: applicationsDisplayLoader.item
369 property: "nativeWidth"
370 value: shell.nativeWidth
371 }
372 Binding {
373 target: applicationsDisplayLoader.item
374 property: "nativeHeight"
375 value: shell.nativeHeight
376 }
377 Binding {
378 target: applicationsDisplayLoader.item
379 property: "beingResized"
380 value: shell.beingResized
381 }
382 Binding {
383 target: applicationsDisplayLoader.item
384 property: "keepDashRunning"
385 value: launcher.shown || launcher.dashSwipe
386 }
387 Binding {
388 target: applicationsDisplayLoader.item
389 property: "suspended"
390 value: greeter.shown
391 }
392 Binding {
393 target: applicationsDisplayLoader.item
394 property: "altTabPressed"
395 value: physicalKeysMapper.altTabPressed
396 }
397 }
399 Tutorial {
400 id: tutorial
401 objectName: "tutorial"
402 anchors.fill: parent
404 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
405 // we skip the tutorial on the Desktop to avoid using them. The
406 // Desktop doesn't use the same spread design anyway. The tutorial is
407 // all a bit of a placeholder on non-phone form factors right now.
408 // When the design team gives us more guidance, we can do something
409 // more clever here.
410 active: usageScenario != "desktop" && AccountsService.demoEdges
412 paused: lightDM.greeter.active
413 launcher: launcher
414 panel: panel
415 edgeSize: shell.edgeSize
417 onFinished: {
418 AccountsService.demoEdges = false;
419 active = false; // for immediate response / if AS is having problems
420 }
421 }
422 }
424 InputMethod {
425 id: inputMethod
426 objectName: "inputMethod"
427 anchors { fill: parent; topMargin: panel.panelHeight }
428 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
429 }
431 Connections {
432 target: SessionManager
433 onSessionStopping: {
434 if (!session.parentSession && !session.application) {
435 // nothing is using it. delete it right away
436 session.release();
437 }
438 }
439 }
441 Loader {
442 id: greeterLoader
443 anchors.fill: parent
444 anchors.topMargin: panel.panelHeight
445 sourceComponent: shell.mode != "shell" ? integratedGreeter :
446 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
447 onLoaded: {
448 item.objectName = "greeter"
449 }
450 }
452 Component {
453 id: integratedGreeter
454 Greeter {
456 hides: [launcher, panel.indicators]
457 tabletMode: shell.usageScenario != "phone"
458 launcherOffset: launcher.progress
459 forcedUnlock: tutorial.running
460 background: shell.background
462 // avoid overlapping with Launcher's edge drag area
463 // FIXME: Fix TouchRegistry & friends and remove this workaround
464 // Issue involves launcher's DDA getting disabled on a long
465 // left-edge drag
466 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
468 onSessionStarted: {
469 launcher.hide();
470 }
472 onTease: {
473 if (!tutorial.running) {
474 launcher.tease();
475 }
476 }
478 onEmergencyCall: startLockedApp("dialer-app")
479 }
480 }
482 Timer {
483 // See powerConnection for why this is useful
484 id: showGreeterDelayed
485 interval: 1
486 onTriggered: {
487 greeter.forceShow();
488 }
489 }
491 Connections {
492 id: callConnection
493 target: callManager
495 onHasCallsChanged: {
496 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
497 // We just received an incoming call while locked. The
498 // indicator will have already launched dialer-app for us, but
499 // there is a race between "hasCalls" changing and the dialer
500 // starting up. So in case we lose that race, we'll start/
501 // focus the dialer ourselves here too. Even if the indicator
502 // didn't launch the dialer for some reason (or maybe a call
503 // started via some other means), if an active call is
504 // happening, we want to be in the dialer.
505 startLockedApp("dialer-app")
506 }
507 }
508 }
510 Connections {
511 id: powerConnection
512 target: Powerd
514 onStatusChanged: {
515 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
516 !callManager.hasCalls && !tutorial.running) {
517 // We don't want to simply call greeter.showNow() here, because
518 // that will take too long. Qt will delay button event
519 // handling until the greeter is done loading and may think the
520 // user held down the power button the whole time, leading to a
521 // power dialog being shown. Instead, delay showing the
522 // greeter until we've finished handling the event. We could
523 // make the greeter load asynchronously instead, but that
524 // introduces a whole host of timing issues, especially with
525 // its animations. So this is simpler.
526 showGreeterDelayed.start();
527 }
528 }
529 }
531 function showHome() {
532 if (tutorial.running) {
533 return
534 }
536 greeter.notifyAboutToFocusApp("unity8-dash");
538 var animate = !lightDM.greeter.active && !stages.shown
539 dash.setCurrentScope(0, animate, false)
540 ApplicationManager.requestFocusApplication("unity8-dash")
541 }
543 function showDash() {
544 if (greeter.notifyShowingDashFromDrag()) {
545 launcher.fadeOut();
546 }
548 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
549 ApplicationManager.requestFocusApplication("unity8-dash")
550 launcher.fadeOut();
551 }
552 }
554 Item {
555 id: overlay
556 z: 10
558 anchors.fill: parent
560 Panel {
561 id: panel
562 objectName: "panel"
563 anchors.fill: parent //because this draws indicator menus
564 indicators {
565 hides: [launcher]
566 available: tutorial.panelEnabled
567 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
568 && (!greeter || !greeter.hasLockedApp)
569 contentEnabled: tutorial.panelContentEnabled
570 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
572 minimizedPanelHeight: units.gu(3)
573 expandedPanelHeight: units.gu(7)
575 indicatorsModel: Indicators.IndicatorsModel {
576 // tablet and phone both use the same profile
577 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
578 Component.onCompleted: load();
579 }
580 }
582 callHint {
583 greeterShown: greeter.shown
584 }
586 property bool topmostApplicationIsFullscreen:
587 ApplicationManager.focusedApplicationId &&
588 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
590 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
591 || greeter.hasLockedApp
592 }
594 Launcher {
595 id: launcher
596 objectName: "launcher"
598 readonly property bool dashSwipe: progress > 0
600 anchors.top: parent.top
601 anchors.topMargin: inverted ? 0 : panel.panelHeight
602 anchors.bottom: parent.bottom
603 width: parent.width
604 dragAreaWidth: shell.edgeSize
605 available: tutorial.launcherEnabled
606 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
607 && !greeter.hasLockedApp
608 inverted: shell.usageScenario !== "desktop"
609 shadeBackground: !tutorial.running
611 onShowDashHome: showHome()
612 onDash: showDash()
613 onDashSwipeChanged: {
614 if (dashSwipe) {
615 dash.setCurrentScope(0, false, true)
616 }
617 }
618 onLauncherApplicationSelected: {
619 if (!tutorial.running) {
620 greeter.notifyAboutToFocusApp(appId);
621 shell.activateApplication(appId)
622 }
623 }
624 onShownChanged: {
625 if (shown) {
626 panel.indicators.hide()
627 }
628 }
629 }
631 Wizard {
632 id: wizard
633 objectName: "wizard"
634 anchors.fill: parent
635 background: shell.background
637 function unlockWhenDoneWithWizard() {
638 if (!active) {
639 Connectivity.unlockAllModems();
640 }
641 }
643 Component.onCompleted: unlockWhenDoneWithWizard()
644 onActiveChanged: unlockWhenDoneWithWizard()
645 }
647 Rectangle {
648 id: modalNotificationBackground
650 visible: notifications.useModal
651 color: "#000000"
652 anchors.fill: parent
653 opacity: 0.9
655 MouseArea {
656 anchors.fill: parent
657 }
658 }
660 Notifications {
661 id: notifications
663 model: NotificationBackend.Model
664 margin: units.gu(1)
665 hasMouse: shell.hasMouse
667 y: topmostIsFullscreen ? 0 : panel.panelHeight
668 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
670 states: [
671 State {
672 name: "narrow"
673 when: overlay.width <= units.gu(60)
674 AnchorChanges {
675 target: notifications
676 anchors.left: parent.left
677 anchors.right: parent.right
678 }
679 },
680 State {
681 name: "wide"
682 when: overlay.width > units.gu(60)
683 AnchorChanges {
684 target: notifications
685 anchors.left: undefined
686 anchors.right: parent.right
687 }
688 PropertyChanges { target: notifications; width: units.gu(38) }
689 }
690 ]
691 }
692 }
694 Dialogs {
695 id: dialogs
696 objectName: "dialogs"
697 anchors.fill: parent
698 z: overlay.z + 10
699 usageScenario: shell.usageScenario
700 onPowerOffClicked: {
701 shutdownFadeOutRectangle.enabled = true;
702 shutdownFadeOutRectangle.visible = true;
703 shutdownFadeOut.start();
704 }
705 }
707 Connections {
708 target: SessionBroadcast
709 onShowHome: showHome()
710 }
712 Rectangle {
713 id: shutdownFadeOutRectangle
714 z: screenGrabber.z + 10
715 enabled: false
716 visible: false
717 color: "black"
718 anchors.fill: parent
719 opacity: 0.0
720 NumberAnimation on opacity {
721 id: shutdownFadeOut
722 from: 0.0
723 to: 1.0
724 onStopped: {
725 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
726 DBusUnitySessionService.shutdown();
727 }
728 }
729 }
730 }
732 ApplicationsFilterModel {
733 id: legacyAppsModel
734 applicationsModel: ApplicationManager
735 filterTouchApps: true
736 }