on f34cb8b help sign in
unity8/qml/Shell.qml
706 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 Utils 0.1
29import Powerd 0.1
30import SessionBroadcast 0.1
31import "Greeter"
32import "Launcher"
33import "Panel"
34import "Components"
35import "Notifications"
36import "Stages"
37import "Tutorial"
38import "Wizard"
39import Unity.Notifications 1.0 as NotificationBackend
40import Unity.Session 0.1
41import Unity.DashCommunicator 0.1
42import Unity.Indicators 0.1 as Indicators
44Item {
45 id: shell
47 // to be set from outside
48 property int orientationAngle: 0
49 property int orientation
50 property int primaryOrientation
51 property int nativeOrientation
52 property real nativeWidth
53 property real nativeHeight
54 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
55 property bool beingResized
56 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
57 property string mode: "full-greeter"
58 function updateFocusedAppOrientation() {
59 applicationsDisplayLoader.item.updateFocusedAppOrientation();
60 }
61 function updateFocusedAppOrientationAnimated() {
62 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
63 }
65 // to be read from outside
66 readonly property int mainAppWindowOrientationAngle:
67 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
69 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
70 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
71 && (!greeter || !greeter.animating)
73 readonly property bool showingGreeter: greeter && greeter.shown
75 property bool startingUp: true
76 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
78 property int supportedOrientations: {
79 if (startingUp) {
80 // Ensure we don't rotate during start up
81 return Qt.PrimaryOrientation;
82 } else if (greeter && greeter.shown) {
83 return Qt.PrimaryOrientation;
84 } else if (mainApp) {
85 return mainApp.supportedOrientations;
86 } else {
87 // we just don't care
88 return Qt.PortraitOrientation
89 | Qt.LandscapeOrientation
90 | Qt.InvertedPortraitOrientation
91 | Qt.InvertedLandscapeOrientation;
92 }
93 }
95 // For autopilot consumption
96 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
98 // internal props from here onwards
99 readonly property var mainApp:
100 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
102 // Disable everything while greeter is waiting, so that the user can't swipe
103 // the greeter or launcher until we know whether the session is locked.
104 enabled: greeter && !greeter.waiting
106 property real edgeSize: units.gu(2)
107 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
108 property url background: asImageTester.status == Image.Ready ? asImageTester.source
109 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
111 readonly property alias greeter: greeterLoader.item
113 function activateApplication(appId) {
114 if (ApplicationManager.findApplication(appId)) {
115 ApplicationManager.requestFocusApplication(appId);
116 } else {
117 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
118 : ApplicationManager.NoFlag;
119 ApplicationManager.startApplication(appId, execFlags);
120 }
121 }
123 function startLockedApp(app) {
124 if (greeter.locked) {
125 greeter.lockedApp = app;
126 }
127 shell.activateApplication(app);
128 }
130 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
131 Image {
132 id: asImageTester
133 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
134 height: 0
135 width: 0
136 sourceSize.height: 0
137 sourceSize.width: 0
138 }
140 GSettings {
141 id: backgroundSettings
142 schema.id: "org.gnome.desktop.background"
143 }
145 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
146 Image {
147 id: gsImageTester
148 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
149 height: 0
150 width: 0
151 sourceSize.height: 0
152 sourceSize.width: 0
153 }
155 Binding {
156 target: LauncherModel
157 property: "applicationManager"
158 value: ApplicationManager
159 }
161 Component.onCompleted: {
162 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
163 if (ApplicationManager.count > 0) {
164 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
165 }
166 finishStartUpTimer.start();
167 }
169 LightDM{
170 id: lightDM
171 fullLightDM: shell.mode === "greeter"
172 }
174 VolumeControl {
175 id: volumeControl
176 indicators: panel.indicators
177 }
179 DashCommunicator {
180 id: dash
181 objectName: "dashCommunicator"
182 }
184 PhysicalKeysMapper {
185 id: physicalKeysMapper
186 objectName: "physicalKeysMapper"
188 onPowerKeyLongPressed: dialogs.showPowerDialog()
189 onVolumeDownTriggered: volumeControl.volumeDown();
190 onVolumeUpTriggered: volumeControl.volumeUp();
191 onScreenshotTriggered: screenGrabber.capture();
192 }
194 ScreenGrabber {
195 id: screenGrabber
196 z: dialogs.z + 10
197 }
199 WindowKeysFilter {
200 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
201 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
202 }
204 HomeKeyWatcher {
205 onActivated: { launcher.fadeOut(); shell.showHome(); }
206 }
208 Item {
209 id: stages
210 objectName: "stages"
211 width: parent.width
212 height: parent.height
214 Connections {
215 target: ApplicationManager
217 // This signal is also fired when we try to focus the current app
218 // again. We rely on this!
219 onFocusedApplicationIdChanged: {
220 var appId = ApplicationManager.focusedApplicationId;
222 if (tutorial.running && appId != "" && appId != "unity8-dash") {
223 // If this happens on first boot, we may be in edge
224 // tutorial or wizard while receiving a call. But a call
225 // is more important than wizard so just bail out of those.
226 tutorial.finish();
227 wizard.hide();
228 }
230 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
231 // If we are in the middle of a call, make dialer lockedApp and show it.
232 // This can happen if user backs out of dialer back to greeter, then
233 // launches dialer again.
234 greeter.lockedApp = appId;
235 }
236 greeter.notifyAppFocused(appId);
238 panel.indicators.hide();
239 }
241 onApplicationAdded: {
242 launcher.hide();
243 }
244 }
246 Loader {
247 id: applicationsDisplayLoader
248 objectName: "applicationsDisplayLoader"
249 anchors.fill: parent
251 // When we have a locked app, we only want to show that one app.
252 // FIXME: do this in a less traumatic way. We currently only allow
253 // locked apps in phone mode (see FIXME in Lockscreen component in
254 // this same file). When that changes, we need to do something
255 // nicer here. But this code is currently just to prevent a
256 // theoretical attack where user enters lockedApp mode, then makes
257 // the screen larger (maybe connects to monitor) and tries to enter
258 // tablet mode.
260 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
261 ? "phone"
262 : shell.usageScenario
263 source: {
264 if(shell.mode === "greeter") {
265 return "Stages/ShimStage.qml"
266 } else if (applicationsDisplayLoader.usageScenario === "phone") {
267 return "Stages/PhoneStage.qml";
268 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
269 return "Stages/TabletStage.qml";
270 } else {
271 return "Stages/DesktopStage.qml";
272 }
273 }
275 property bool interactive: tutorial.spreadEnabled
276 && (!greeter || !greeter.shown)
277 && panel.indicators.fullyClosed
278 && launcher.progress == 0
279 && !notifications.useModal
281 onInteractiveChanged: { if (interactive) { focus = true; } }
283 Binding {
284 target: applicationsDisplayLoader.item
285 property: "objectName"
286 value: "stage"
287 }
288 Binding {
289 target: applicationsDisplayLoader.item
290 property: "dragAreaWidth"
291 value: shell.edgeSize
292 }
293 Binding {
294 target: applicationsDisplayLoader.item
295 property: "maximizedAppTopMargin"
296 // Not just using panel.panelHeight as that changes depending on the focused app.
297 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
298 }
299 Binding {
300 target: applicationsDisplayLoader.item
301 property: "interactive"
302 value: applicationsDisplayLoader.interactive
303 }
304 Binding {
305 target: applicationsDisplayLoader.item
306 property: "spreadEnabled"
307 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
308 }
309 Binding {
310 target: applicationsDisplayLoader.item
311 property: "inverseProgress"
312 value: greeter && greeter.locked ? 0 : launcher.progress
313 }
314 Binding {
315 target: applicationsDisplayLoader.item
316 property: "shellOrientationAngle"
317 value: shell.orientationAngle
318 }
319 Binding {
320 target: applicationsDisplayLoader.item
321 property: "shellOrientation"
322 value: shell.orientation
323 }
324 Binding {
325 target: applicationsDisplayLoader.item
326 property: "background"
327 value: shell.background
328 }
329 Binding {
330 target: applicationsDisplayLoader.item
331 property: "shellPrimaryOrientation"
332 value: shell.primaryOrientation
333 }
334 Binding {
335 target: applicationsDisplayLoader.item
336 property: "nativeOrientation"
337 value: shell.nativeOrientation
338 }
339 Binding {
340 target: applicationsDisplayLoader.item
341 property: "nativeWidth"
342 value: shell.nativeWidth
343 }
344 Binding {
345 target: applicationsDisplayLoader.item
346 property: "nativeHeight"
347 value: shell.nativeHeight
348 }
349 Binding {
350 target: applicationsDisplayLoader.item
351 property: "beingResized"
352 value: shell.beingResized
353 }
354 Binding {
355 target: applicationsDisplayLoader.item
356 property: "keepDashRunning"
357 value: launcher.shown || launcher.dashSwipe
358 }
359 Binding {
360 target: applicationsDisplayLoader.item
361 property: "suspended"
362 value: greeter.shown
363 }
364 Binding {
365 target: applicationsDisplayLoader.item
366 property: "altTabPressed"
367 value: physicalKeysMapper.altTabPressed
368 }
369 }
371 Tutorial {
372 id: tutorial
373 objectName: "tutorial"
374 anchors.fill: parent
376 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
377 // we skip the tutorial on the Desktop to avoid using them. The
378 // Desktop doesn't use the same spread design anyway. The tutorial is
379 // all a bit of a placeholder on non-phone form factors right now.
380 // When the design team gives us more guidance, we can do something
381 // more clever here.
382 active: usageScenario != "desktop" && AccountsService.demoEdges
384 paused: lightDM.greeter.active
385 launcher: launcher
386 panel: panel
387 edgeSize: shell.edgeSize
389 onFinished: {
390 AccountsService.demoEdges = false;
391 active = false; // for immediate response / if AS is having problems
392 }
393 }
394 }
396 InputMethod {
397 id: inputMethod
398 objectName: "inputMethod"
399 anchors { fill: parent; topMargin: panel.panelHeight }
400 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
401 }
403 Connections {
404 target: SessionManager
405 onSessionStopping: {
406 if (!session.parentSession && !session.application) {
407 // nothing is using it. delete it right away
408 session.release();
409 }
410 }
411 }
413 Loader {
414 id: greeterLoader
415 anchors.fill: parent
416 anchors.topMargin: panel.panelHeight
417 sourceComponent: shell.mode != "shell" ? integratedGreeter :
418 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
419 onLoaded: {
420 item.objectName = "greeter"
421 }
422 }
424 Component {
425 id: integratedGreeter
426 Greeter {
428 hides: [launcher, panel.indicators]
429 tabletMode: shell.usageScenario != "phone"
430 launcherOffset: launcher.progress
431 forcedUnlock: tutorial.running
432 fullLightDM: shell.mode === "greeter"
433 background: shell.background
435 // avoid overlapping with Launcher's edge drag area
436 // FIXME: Fix TouchRegistry & friends and remove this workaround
437 // Issue involves launcher's DDA getting disabled on a long
438 // left-edge drag
439 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
441 onSessionStarted: {
442 launcher.hide();
443 }
445 onTease: {
446 if (!tutorial.running) {
447 launcher.tease();
448 }
449 }
451 onEmergencyCall: startLockedApp("dialer-app")
452 }
453 }
455 Timer {
456 // See powerConnection for why this is useful
457 id: showGreeterDelayed
458 interval: 1
459 onTriggered: {
460 greeter.forceShow();
461 }
462 }
464 Connections {
465 id: callConnection
466 target: callManager
468 onHasCallsChanged: {
469 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
470 // We just received an incoming call while locked. The
471 // indicator will have already launched dialer-app for us, but
472 // there is a race between "hasCalls" changing and the dialer
473 // starting up. So in case we lose that race, we'll start/
474 // focus the dialer ourselves here too. Even if the indicator
475 // didn't launch the dialer for some reason (or maybe a call
476 // started via some other means), if an active call is
477 // happening, we want to be in the dialer.
478 startLockedApp("dialer-app")
479 }
480 }
481 }
483 Connections {
484 id: powerConnection
485 target: Powerd
487 onStatusChanged: {
488 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
489 !callManager.hasCalls && !tutorial.running) {
490 // We don't want to simply call greeter.showNow() here, because
491 // that will take too long. Qt will delay button event
492 // handling until the greeter is done loading and may think the
493 // user held down the power button the whole time, leading to a
494 // power dialog being shown. Instead, delay showing the
495 // greeter until we've finished handling the event. We could
496 // make the greeter load asynchronously instead, but that
497 // introduces a whole host of timing issues, especially with
498 // its animations. So this is simpler.
499 showGreeterDelayed.start();
500 }
501 }
502 }
504 function showHome() {
505 if (tutorial.running) {
506 return
507 }
509 greeter.notifyAboutToFocusApp("unity8-dash");
511 var animate = !lightDM.greeter.active && !stages.shown
512 dash.setCurrentScope(0, animate, false)
513 ApplicationManager.requestFocusApplication("unity8-dash")
514 }
516 function showDash() {
517 if (greeter.notifyShowingDashFromDrag()) {
518 launcher.fadeOut();
519 }
521 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
522 ApplicationManager.requestFocusApplication("unity8-dash")
523 launcher.fadeOut();
524 }
525 }
527 Item {
528 id: overlay
529 z: 10
531 anchors.fill: parent
533 Panel {
534 id: panel
535 objectName: "panel"
536 anchors.fill: parent //because this draws indicator menus
537 indicators {
538 hides: [launcher]
539 available: tutorial.panelEnabled
540 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
541 && (!greeter || !greeter.hasLockedApp)
542 contentEnabled: tutorial.panelContentEnabled
543 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
545 minimizedPanelHeight: units.gu(3)
546 expandedPanelHeight: units.gu(7)
548 indicatorsModel: Indicators.IndicatorsModel {
549 // tablet and phone both use the same profile
550 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
551 Component.onCompleted: load();
552 }
553 }
555 callHint {
556 greeterShown: greeter.shown
557 }
559 property bool topmostApplicationIsFullscreen:
560 ApplicationManager.focusedApplicationId &&
561 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
563 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
564 || greeter.hasLockedApp
565 }
567 Launcher {
568 id: launcher
569 objectName: "launcher"
571 readonly property bool dashSwipe: progress > 0
573 anchors.top: parent.top
574 anchors.topMargin: inverted ? 0 : panel.panelHeight
575 anchors.bottom: parent.bottom
576 width: parent.width
577 dragAreaWidth: shell.edgeSize
578 available: tutorial.launcherEnabled
579 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
580 && !greeter.hasLockedApp
581 inverted: shell.usageScenario !== "desktop"
582 shadeBackground: !tutorial.running
584 onShowDashHome: showHome()
585 onDash: showDash()
586 onDashSwipeChanged: {
587 if (dashSwipe) {
588 dash.setCurrentScope(0, false, true)
589 }
590 }
591 onLauncherApplicationSelected: {
592 if (!tutorial.running) {
593 greeter.notifyAboutToFocusApp(appId);
594 shell.activateApplication(appId)
595 }
596 }
597 onShownChanged: {
598 if (shown) {
599 panel.indicators.hide()
600 }
601 }
602 }
604 Wizard {
605 id: wizard
606 objectName: "wizard"
607 anchors.fill: parent
608 background: shell.background
609 deferred: shell.mode === "greeter"
611 function unlockWhenDoneWithWizard() {
612 if (!active) {
613 Connectivity.unlockAllModems();
614 }
615 }
617 Component.onCompleted: unlockWhenDoneWithWizard()
618 onActiveChanged: unlockWhenDoneWithWizard()
619 }
621 Rectangle {
622 id: modalNotificationBackground
624 visible: notifications.useModal
625 color: "#000000"
626 anchors.fill: parent
627 opacity: 0.9
629 MouseArea {
630 anchors.fill: parent
631 }
632 }
634 Notifications {
635 id: notifications
637 model: NotificationBackend.Model
638 margin: units.gu(1)
640 y: topmostIsFullscreen ? 0 : panel.panelHeight
641 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
643 states: [
644 State {
645 name: "narrow"
646 when: overlay.width <= units.gu(60)
647 AnchorChanges {
648 target: notifications
649 anchors.left: parent.left
650 anchors.right: parent.right
651 }
652 },
653 State {
654 name: "wide"
655 when: overlay.width > units.gu(60)
656 AnchorChanges {
657 target: notifications
658 anchors.left: undefined
659 anchors.right: parent.right
660 }
661 PropertyChanges { target: notifications; width: units.gu(38) }
662 }
663 ]
664 }
665 }
667 Dialogs {
668 id: dialogs
669 objectName: "dialogs"
670 anchors.fill: parent
671 z: overlay.z + 10
672 onPowerOffClicked: {
673 shutdownFadeOutRectangle.enabled = true;
674 shutdownFadeOutRectangle.visible = true;
675 shutdownFadeOut.start();
676 }
677 fullLightDM: shell.mode === "greeter"
678 lightDM: lightDM
679 }
681 Connections {
682 target: SessionBroadcast
683 onShowHome: showHome()
684 }
686 Rectangle {
687 id: shutdownFadeOutRectangle
688 z: screenGrabber.z + 10
689 enabled: false
690 visible: false
691 color: "black"
692 anchors.fill: parent
693 opacity: 0.0
694 NumberAnimation on opacity {
695 id: shutdownFadeOut
696 from: 0.0
697 to: 1.0
698 onStopped: {
699 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
700 DBusUnitySessionService.Shutdown();
701 }
702 }
703 }
704 }