on 846cd64 help sign in
unity8/qml/Shell.qml
723 lines 25 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 // Used by stage code
223 function isExemptFromLifecycle(appId) {
224 var shortAppId = appId.split('_')[0];
225 for (var i = 0; i < lifecycleExceptions.lifecycleExemptAppids.length; i++) {
226 if (shortAppId === lifecycleExceptions.lifecycleExemptAppids[i]) {
227 return true;
228 }
229 }
230 return false;
231 }
233 Connections {
234 target: ApplicationManager
236 // This signal is also fired when we try to focus the current app
237 // again. We rely on this!
238 onFocusedApplicationIdChanged: {
239 var appId = ApplicationManager.focusedApplicationId;
241 if (tutorial.running && appId != "" && appId != "unity8-dash") {
242 // If this happens on first boot, we may be in edge
243 // tutorial or wizard while receiving a call. But a call
244 // is more important than wizard so just bail out of those.
245 tutorial.finish();
246 wizard.hide();
247 }
249 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
250 // If we are in the middle of a call, make dialer lockedApp and show it.
251 // This can happen if user backs out of dialer back to greeter, then
252 // launches dialer again.
253 greeter.lockedApp = appId;
254 }
255 greeter.notifyAppFocused(appId);
257 panel.indicators.hide();
258 }
260 onApplicationAdded: {
261 launcher.hide();
262 }
263 }
265 Loader {
266 id: applicationsDisplayLoader
267 objectName: "applicationsDisplayLoader"
268 anchors.fill: parent
270 // When we have a locked app, we only want to show that one app.
271 // FIXME: do this in a less traumatic way. We currently only allow
272 // locked apps in phone mode (see FIXME in Lockscreen component in
273 // this same file). When that changes, we need to do something
274 // nicer here. But this code is currently just to prevent a
275 // theoretical attack where user enters lockedApp mode, then makes
276 // the screen larger (maybe connects to monitor) and tries to enter
277 // tablet mode.
279 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
280 ? "phone"
281 : shell.usageScenario
282 source: {
283 if(shell.mode === "greeter") {
284 return "Stages/ShimStage.qml"
285 } else if (applicationsDisplayLoader.usageScenario === "phone") {
286 return "Stages/PhoneStage.qml";
287 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
288 return "Stages/TabletStage.qml";
289 } else {
290 return "Stages/DesktopStage.qml";
291 }
292 }
294 property bool interactive: tutorial.spreadEnabled
295 && (!greeter || !greeter.shown)
296 && panel.indicators.fullyClosed
297 && launcher.progress == 0
298 && !notifications.useModal
300 onInteractiveChanged: { if (interactive) { focus = true; } }
302 Binding {
303 target: applicationsDisplayLoader.item
304 property: "objectName"
305 value: "stage"
306 }
307 Binding {
308 target: applicationsDisplayLoader.item
309 property: "dragAreaWidth"
310 value: shell.edgeSize
311 }
312 Binding {
313 target: applicationsDisplayLoader.item
314 property: "maximizedAppTopMargin"
315 // Not just using panel.panelHeight as that changes depending on the focused app.
316 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
317 }
318 Binding {
319 target: applicationsDisplayLoader.item
320 property: "interactive"
321 value: applicationsDisplayLoader.interactive
322 }
323 Binding {
324 target: applicationsDisplayLoader.item
325 property: "spreadEnabled"
326 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
327 }
328 Binding {
329 target: applicationsDisplayLoader.item
330 property: "inverseProgress"
331 value: greeter && greeter.locked ? 0 : launcher.progress
332 }
333 Binding {
334 target: applicationsDisplayLoader.item
335 property: "shellOrientationAngle"
336 value: shell.orientationAngle
337 }
338 Binding {
339 target: applicationsDisplayLoader.item
340 property: "shellOrientation"
341 value: shell.orientation
342 }
343 Binding {
344 target: applicationsDisplayLoader.item
345 property: "background"
346 value: shell.background
347 }
348 Binding {
349 target: applicationsDisplayLoader.item
350 property: "shellPrimaryOrientation"
351 value: shell.primaryOrientation
352 }
353 Binding {
354 target: applicationsDisplayLoader.item
355 property: "nativeOrientation"
356 value: shell.nativeOrientation
357 }
358 Binding {
359 target: applicationsDisplayLoader.item
360 property: "nativeWidth"
361 value: shell.nativeWidth
362 }
363 Binding {
364 target: applicationsDisplayLoader.item
365 property: "nativeHeight"
366 value: shell.nativeHeight
367 }
368 Binding {
369 target: applicationsDisplayLoader.item
370 property: "beingResized"
371 value: shell.beingResized
372 }
373 Binding {
374 target: applicationsDisplayLoader.item
375 property: "keepDashRunning"
376 value: launcher.shown || launcher.dashSwipe
377 }
378 Binding {
379 target: applicationsDisplayLoader.item
380 property: "suspended"
381 value: greeter.shown
382 }
383 Binding {
384 target: applicationsDisplayLoader.item
385 property: "altTabPressed"
386 value: physicalKeysMapper.altTabPressed
387 }
388 }
390 Tutorial {
391 id: tutorial
392 objectName: "tutorial"
393 anchors.fill: parent
395 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
396 // we skip the tutorial on the Desktop to avoid using them. The
397 // Desktop doesn't use the same spread design anyway. The tutorial is
398 // all a bit of a placeholder on non-phone form factors right now.
399 // When the design team gives us more guidance, we can do something
400 // more clever here.
401 active: usageScenario != "desktop" && AccountsService.demoEdges
403 paused: lightDM.greeter.active
404 launcher: launcher
405 panel: panel
406 edgeSize: shell.edgeSize
408 onFinished: {
409 AccountsService.demoEdges = false;
410 active = false; // for immediate response / if AS is having problems
411 }
412 }
413 }
415 InputMethod {
416 id: inputMethod
417 objectName: "inputMethod"
418 anchors { fill: parent; topMargin: panel.panelHeight }
419 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
420 }
422 Connections {
423 target: SessionManager
424 onSessionStopping: {
425 if (!session.parentSession && !session.application) {
426 // nothing is using it. delete it right away
427 session.release();
428 }
429 }
430 }
432 Loader {
433 id: greeterLoader
434 anchors.fill: parent
435 anchors.topMargin: panel.panelHeight
436 sourceComponent: shell.mode != "shell" ? integratedGreeter :
437 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
438 onLoaded: {
439 item.objectName = "greeter"
440 }
441 }
443 Component {
444 id: integratedGreeter
445 Greeter {
447 hides: [launcher, panel.indicators]
448 tabletMode: shell.usageScenario != "phone"
449 launcherOffset: launcher.progress
450 forcedUnlock: tutorial.running
451 background: shell.background
453 // avoid overlapping with Launcher's edge drag area
454 // FIXME: Fix TouchRegistry & friends and remove this workaround
455 // Issue involves launcher's DDA getting disabled on a long
456 // left-edge drag
457 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
459 onSessionStarted: {
460 launcher.hide();
461 }
463 onTease: {
464 if (!tutorial.running) {
465 launcher.tease();
466 }
467 }
469 onEmergencyCall: startLockedApp("dialer-app")
470 }
471 }
473 Timer {
474 // See powerConnection for why this is useful
475 id: showGreeterDelayed
476 interval: 1
477 onTriggered: {
478 greeter.forceShow();
479 }
480 }
482 Connections {
483 id: callConnection
484 target: callManager
486 onHasCallsChanged: {
487 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
488 // We just received an incoming call while locked. The
489 // indicator will have already launched dialer-app for us, but
490 // there is a race between "hasCalls" changing and the dialer
491 // starting up. So in case we lose that race, we'll start/
492 // focus the dialer ourselves here too. Even if the indicator
493 // didn't launch the dialer for some reason (or maybe a call
494 // started via some other means), if an active call is
495 // happening, we want to be in the dialer.
496 startLockedApp("dialer-app")
497 }
498 }
499 }
501 Connections {
502 id: powerConnection
503 target: Powerd
505 onStatusChanged: {
506 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
507 !callManager.hasCalls && !tutorial.running) {
508 // We don't want to simply call greeter.showNow() here, because
509 // that will take too long. Qt will delay button event
510 // handling until the greeter is done loading and may think the
511 // user held down the power button the whole time, leading to a
512 // power dialog being shown. Instead, delay showing the
513 // greeter until we've finished handling the event. We could
514 // make the greeter load asynchronously instead, but that
515 // introduces a whole host of timing issues, especially with
516 // its animations. So this is simpler.
517 showGreeterDelayed.start();
518 }
519 }
520 }
522 function showHome() {
523 if (tutorial.running) {
524 return
525 }
527 greeter.notifyAboutToFocusApp("unity8-dash");
529 var animate = !lightDM.greeter.active && !stages.shown
530 dash.setCurrentScope(0, animate, false)
531 ApplicationManager.requestFocusApplication("unity8-dash")
532 }
534 function showDash() {
535 if (greeter.notifyShowingDashFromDrag()) {
536 launcher.fadeOut();
537 }
539 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
540 ApplicationManager.requestFocusApplication("unity8-dash")
541 launcher.fadeOut();
542 }
543 }
545 Item {
546 id: overlay
547 z: 10
549 anchors.fill: parent
551 Panel {
552 id: panel
553 objectName: "panel"
554 anchors.fill: parent //because this draws indicator menus
555 indicators {
556 hides: [launcher]
557 available: tutorial.panelEnabled
558 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
559 && (!greeter || !greeter.hasLockedApp)
560 contentEnabled: tutorial.panelContentEnabled
561 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
563 minimizedPanelHeight: units.gu(3)
564 expandedPanelHeight: units.gu(7)
566 indicatorsModel: Indicators.IndicatorsModel {
567 // tablet and phone both use the same profile
568 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
569 Component.onCompleted: load();
570 }
571 }
573 callHint {
574 greeterShown: greeter.shown
575 }
577 property bool topmostApplicationIsFullscreen:
578 ApplicationManager.focusedApplicationId &&
579 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
581 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
582 || greeter.hasLockedApp
583 }
585 Launcher {
586 id: launcher
587 objectName: "launcher"
589 readonly property bool dashSwipe: progress > 0
591 anchors.top: parent.top
592 anchors.topMargin: inverted ? 0 : panel.panelHeight
593 anchors.bottom: parent.bottom
594 width: parent.width
595 dragAreaWidth: shell.edgeSize
596 available: tutorial.launcherEnabled
597 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
598 && !greeter.hasLockedApp
599 inverted: shell.usageScenario !== "desktop"
600 shadeBackground: !tutorial.running
602 onShowDashHome: showHome()
603 onDash: showDash()
604 onDashSwipeChanged: {
605 if (dashSwipe) {
606 dash.setCurrentScope(0, false, true)
607 }
608 }
609 onLauncherApplicationSelected: {
610 if (!tutorial.running) {
611 greeter.notifyAboutToFocusApp(appId);
612 shell.activateApplication(appId)
613 }
614 }
615 onShownChanged: {
616 if (shown) {
617 panel.indicators.hide()
618 }
619 }
620 }
622 Wizard {
623 id: wizard
624 objectName: "wizard"
625 anchors.fill: parent
626 background: shell.background
628 function unlockWhenDoneWithWizard() {
629 if (!active) {
630 Connectivity.unlockAllModems();
631 }
632 }
634 Component.onCompleted: unlockWhenDoneWithWizard()
635 onActiveChanged: unlockWhenDoneWithWizard()
636 }
638 Rectangle {
639 id: modalNotificationBackground
641 visible: notifications.useModal
642 color: "#000000"
643 anchors.fill: parent
644 opacity: 0.9
646 MouseArea {
647 anchors.fill: parent
648 }
649 }
651 Notifications {
652 id: notifications
654 model: NotificationBackend.Model
655 margin: units.gu(1)
656 hasMouse: shell.hasMouse
658 y: topmostIsFullscreen ? 0 : panel.panelHeight
659 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
661 states: [
662 State {
663 name: "narrow"
664 when: overlay.width <= units.gu(60)
665 AnchorChanges {
666 target: notifications
667 anchors.left: parent.left
668 anchors.right: parent.right
669 }
670 },
671 State {
672 name: "wide"
673 when: overlay.width > units.gu(60)
674 AnchorChanges {
675 target: notifications
676 anchors.left: undefined
677 anchors.right: parent.right
678 }
679 PropertyChanges { target: notifications; width: units.gu(38) }
680 }
681 ]
682 }
683 }
685 Dialogs {
686 id: dialogs
687 objectName: "dialogs"
688 anchors.fill: parent
689 z: overlay.z + 10
690 usageScenario: shell.usageScenario
691 onPowerOffClicked: {
692 shutdownFadeOutRectangle.enabled = true;
693 shutdownFadeOutRectangle.visible = true;
694 shutdownFadeOut.start();
695 }
696 }
698 Connections {
699 target: SessionBroadcast
700 onShowHome: showHome()
701 }
703 Rectangle {
704 id: shutdownFadeOutRectangle
705 z: screenGrabber.z + 10
706 enabled: false
707 visible: false
708 color: "black"
709 anchors.fill: parent
710 opacity: 0.0
711 NumberAnimation on opacity {
712 id: shutdownFadeOut
713 from: 0.0
714 to: 1.0
715 onStopped: {
716 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
717 DBusUnitySessionService.shutdown();
718 }
719 }
720 }
721 }