on 8c3166a help sign in
unity8/qml/Shell.qml
716 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 greeterMode: shell.mode === "greeter"
172 }
174 VolumeControl {
175 id: volumeControl
176 }
178 DashCommunicator {
179 id: dash
180 objectName: "dashCommunicator"
181 }
183 PhysicalKeysMapper {
184 id: physicalKeysMapper
186 onPowerKeyLongPressed: dialogs.showPowerDialog()
187 onVolumeDownTriggered: volumeControl.volumeDown();
188 onVolumeUpTriggered: volumeControl.volumeUp();
189 onScreenshotTriggered: screenGrabber.capture();
190 }
192 ScreenGrabber {
193 id: screenGrabber
194 z: dialogs.z + 10
195 enabled: Powerd.status === Powerd.On
196 }
198 Binding {
199 target: ApplicationManager
200 property: "forceDashActive"
201 value: launcher.shown || launcher.dashSwipe
202 }
204 WindowKeysFilter {
205 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
206 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
207 }
209 HomeKeyWatcher {
210 onActivated: { launcher.fadeOut(); shell.showHome(); }
211 }
213 Item {
214 id: stages
215 objectName: "stages"
216 width: parent.width
217 height: parent.height
219 Connections {
220 target: ApplicationManager
222 // This signal is also fired when we try to focus the current app
223 // again. We rely on this!
224 onFocusedApplicationIdChanged: {
225 var appId = ApplicationManager.focusedApplicationId;
227 if (tutorial.running && appId != "" && appId != "unity8-dash") {
228 // If this happens on first boot, we may be in edge
229 // tutorial or wizard while receiving a call. But a call
230 // is more important than wizard so just bail out of those.
231 tutorial.finish();
232 wizard.hide();
233 }
235 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
236 // If we are in the middle of a call, make dialer lockedApp and show it.
237 // This can happen if user backs out of dialer back to greeter, then
238 // launches dialer again.
239 greeter.lockedApp = appId;
240 }
241 greeter.notifyAppFocused(appId);
243 panel.indicators.hide();
244 }
246 onApplicationAdded: {
247 launcher.hide();
248 }
249 }
251 Loader {
252 id: applicationsDisplayLoader
253 objectName: "applicationsDisplayLoader"
254 anchors.fill: parent
256 // When we have a locked app, we only want to show that one app.
257 // FIXME: do this in a less traumatic way. We currently only allow
258 // locked apps in phone mode (see FIXME in Lockscreen component in
259 // this same file). When that changes, we need to do something
260 // nicer here. But this code is currently just to prevent a
261 // theoretical attack where user enters lockedApp mode, then makes
262 // the screen larger (maybe connects to monitor) and tries to enter
263 // tablet mode.
265 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
266 ? "phone"
267 : shell.usageScenario
268 source: {
269 if(shell.mode === "greeter") {
270 return "Stages/ShimStage.qml"
271 } else if (applicationsDisplayLoader.usageScenario === "phone") {
272 return "Stages/PhoneStage.qml";
273 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
274 return "Stages/TabletStage.qml";
275 } else {
276 return "Stages/DesktopStage.qml";
277 }
278 }
280 property bool interactive: tutorial.spreadEnabled
281 && (!greeter || !greeter.shown)
282 && panel.indicators.fullyClosed
283 && launcher.progress == 0
284 && !notifications.useModal
286 onInteractiveChanged: { if (interactive) { focus = true; } }
288 Binding {
289 target: applicationsDisplayLoader.item
290 property: "objectName"
291 value: "stage"
292 }
293 Binding {
294 target: applicationsDisplayLoader.item
295 property: "dragAreaWidth"
296 value: shell.edgeSize
297 }
298 Binding {
299 target: applicationsDisplayLoader.item
300 property: "maximizedAppTopMargin"
301 // Not just using panel.panelHeight as that changes depending on the focused app.
302 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
303 }
304 Binding {
305 target: applicationsDisplayLoader.item
306 property: "interactive"
307 value: applicationsDisplayLoader.interactive
308 }
309 Binding {
310 target: applicationsDisplayLoader.item
311 property: "spreadEnabled"
312 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
313 }
314 Binding {
315 target: applicationsDisplayLoader.item
316 property: "inverseProgress"
317 value: greeter && greeter.locked ? 0 : launcher.progress
318 }
319 Binding {
320 target: applicationsDisplayLoader.item
321 property: "shellOrientationAngle"
322 value: shell.orientationAngle
323 }
324 Binding {
325 target: applicationsDisplayLoader.item
326 property: "shellOrientation"
327 value: shell.orientation
328 }
329 Binding {
330 target: applicationsDisplayLoader.item
331 property: "background"
332 value: shell.background
333 }
334 Binding {
335 target: applicationsDisplayLoader.item
336 property: "shellPrimaryOrientation"
337 value: shell.primaryOrientation
338 }
339 Binding {
340 target: applicationsDisplayLoader.item
341 property: "nativeOrientation"
342 value: shell.nativeOrientation
343 }
344 Binding {
345 target: applicationsDisplayLoader.item
346 property: "nativeWidth"
347 value: shell.nativeWidth
348 }
349 Binding {
350 target: applicationsDisplayLoader.item
351 property: "nativeHeight"
352 value: shell.nativeHeight
353 }
354 Binding {
355 target: applicationsDisplayLoader.item
356 property: "beingResized"
357 value: shell.beingResized
358 }
359 }
361 Tutorial {
362 id: tutorial
363 objectName: "tutorial"
364 anchors.fill: parent
365 active: AccountsService.demoEdges && shell.mode !== "greeter"
366 paused: lightDM.greeter.active
367 launcher: launcher
368 panel: panel
369 edgeSize: shell.edgeSize
371 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
372 // we'll tell the tutorial to avoid using them on the Desktop. The
373 // Desktop doesn't use the same spread design anyway. The tutorial is
374 // all a bit of a placeholder on non-phone form factors right now.
375 // When the design team gives us more guidance, we can do something
376 // more clever here.
377 // TODO: use DeviceConfiguration instead of checking source
378 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
380 onFinished: {
381 AccountsService.demoEdges = false;
382 active = false; // for immediate response / if AS is having problems
383 }
384 }
385 }
387 InputMethod {
388 id: inputMethod
389 objectName: "inputMethod"
390 anchors { fill: parent; topMargin: panel.panelHeight }
391 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
392 }
394 Connections {
395 target: SurfaceManager
396 onSurfaceCreated: {
397 if (surface.type == MirSurfaceItem.InputMethod) {
398 inputMethod.surface = surface;
399 }
400 }
402 onSurfaceDestroyed: {
403 if (inputMethod.surface == surface) {
404 inputMethod.surface = null;
405 surface.parent = null;
406 }
407 if (!surface.parent) {
408 // there's no one displaying it. delete it right away
409 surface.release();
410 }
411 }
412 }
413 Connections {
414 target: SessionManager
415 onSessionStopping: {
416 if (!session.parentSession && !session.application) {
417 // nothing is using it. delete it right away
418 session.release();
419 }
420 }
421 }
423 Loader {
424 id: greeterLoader
425 anchors.fill: parent
426 anchors.topMargin: panel.panelHeight
427 sourceComponent: shell.mode != "shell" ? integratedGreeter :
428 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
429 onLoaded: {
430 item.objectName = "greeter"
431 }
432 }
434 Component {
435 id: integratedGreeter
436 Greeter {
438 hides: [launcher, panel.indicators]
439 tabletMode: shell.usageScenario != "phone"
440 launcherOffset: launcher.progress
441 forcedUnlock: tutorial.running
442 background: shell.background
444 // avoid overlapping with Launcher's edge drag area
445 // FIXME: Fix TouchRegistry & friends and remove this workaround
446 // Issue involves launcher's DDA getting disabled on a long
447 // left-edge drag
448 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
450 onSessionStarted: {
451 launcher.hide();
452 }
454 onTease: {
455 if (!tutorial.running) {
456 launcher.tease();
457 }
458 }
460 onEmergencyCall: startLockedApp("dialer-app")
462 Binding {
463 target: ApplicationManager
464 property: "suspended"
465 value: greeter.shown
466 }
467 }
468 }
470 Timer {
471 // See powerConnection for why this is useful
472 id: showGreeterDelayed
473 interval: 1
474 onTriggered: {
475 greeter.forceShow();
476 }
477 }
479 Connections {
480 id: callConnection
481 target: callManager
483 onHasCallsChanged: {
484 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
485 // We just received an incoming call while locked. The
486 // indicator will have already launched dialer-app for us, but
487 // there is a race between "hasCalls" changing and the dialer
488 // starting up. So in case we lose that race, we'll start/
489 // focus the dialer ourselves here too. Even if the indicator
490 // didn't launch the dialer for some reason (or maybe a call
491 // started via some other means), if an active call is
492 // happening, we want to be in the dialer.
493 startLockedApp("dialer-app")
494 }
495 }
496 }
498 Connections {
499 id: powerConnection
500 target: Powerd
502 onStatusChanged: {
503 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
504 !callManager.hasCalls && !tutorial.running) {
505 // We don't want to simply call greeter.showNow() here, because
506 // that will take too long. Qt will delay button event
507 // handling until the greeter is done loading and may think the
508 // user held down the power button the whole time, leading to a
509 // power dialog being shown. Instead, delay showing the
510 // greeter until we've finished handling the event. We could
511 // make the greeter load asynchronously instead, but that
512 // introduces a whole host of timing issues, especially with
513 // its animations. So this is simpler.
514 showGreeterDelayed.start();
515 }
516 }
517 }
519 function showHome() {
520 if (tutorial.running) {
521 return
522 }
524 greeter.notifyAboutToFocusApp("unity8-dash");
526 var animate = !lightDM.greeter.active && !stages.shown
527 dash.setCurrentScope(0, animate, false)
528 ApplicationManager.requestFocusApplication("unity8-dash")
529 }
531 function showDash() {
532 if (greeter.notifyShowingDashFromDrag()) {
533 launcher.fadeOut();
534 }
536 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
537 ApplicationManager.requestFocusApplication("unity8-dash")
538 launcher.fadeOut();
539 }
540 }
542 Item {
543 id: overlay
544 z: 10
546 anchors.fill: parent
548 Panel {
549 id: panel
550 objectName: "panel"
551 anchors.fill: parent //because this draws indicator menus
552 indicators {
553 hides: [launcher]
554 available: tutorial.panelEnabled
555 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
556 && (!greeter || !greeter.hasLockedApp)
557 contentEnabled: tutorial.panelContentEnabled
558 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
560 minimizedPanelHeight: units.gu(3)
561 expandedPanelHeight: units.gu(7)
563 indicatorsModel: Indicators.IndicatorsModel {
564 // tablet and phone both use the same profile
565 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
566 Component.onCompleted: load();
567 }
568 }
570 callHint {
571 greeterShown: greeter.shown
572 }
574 property bool mainAppIsFullscreen: shell.mainApp && shell.mainApp.fullscreen
575 fullscreenMode: (mainAppIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
576 || greeter.hasLockedApp
577 }
579 Launcher {
580 id: launcher
581 objectName: "launcher"
583 readonly property bool dashSwipe: progress > 0
585 anchors.top: parent.top
586 anchors.topMargin: inverted ? 0 : panel.panelHeight
587 anchors.bottom: parent.bottom
588 width: parent.width
589 dragAreaWidth: shell.edgeSize
590 available: tutorial.launcherEnabled
591 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
592 && !greeter.hasLockedApp
593 inverted: shell.usageScenario !== "desktop"
594 shadeBackground: !tutorial.running
596 onShowDashHome: showHome()
597 onDash: showDash()
598 onDashSwipeChanged: {
599 if (dashSwipe) {
600 dash.setCurrentScope(0, false, true)
601 }
602 }
603 onLauncherApplicationSelected: {
604 if (!tutorial.running) {
605 greeter.notifyAboutToFocusApp(appId);
606 shell.activateApplication(appId)
607 }
608 }
609 onShownChanged: {
610 if (shown) {
611 panel.indicators.hide()
612 }
613 }
614 }
616 Wizard {
617 id: wizard
618 objectName: "wizard"
619 anchors.fill: parent
620 background: shell.background
621 enabled: shell.mode !== "greeter"
623 function unlockWhenDoneWithWizard() {
624 if (!active) {
625 Connectivity.unlockAllModems();
626 }
627 }
629 Component.onCompleted: unlockWhenDoneWithWizard()
630 onActiveChanged: unlockWhenDoneWithWizard()
631 }
633 Rectangle {
634 id: modalNotificationBackground
636 visible: notifications.useModal
637 color: "#000000"
638 anchors.fill: parent
639 opacity: 0.9
641 MouseArea {
642 anchors.fill: parent
643 }
644 }
646 Notifications {
647 id: notifications
649 model: NotificationBackend.Model
650 margin: units.gu(1)
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 onPowerOffClicked: {
685 shutdownFadeOutRectangle.enabled = true;
686 shutdownFadeOutRectangle.visible = true;
687 shutdownFadeOut.start();
688 }
689 }
691 Connections {
692 target: SessionBroadcast
693 onShowHome: showHome()
694 }
696 Rectangle {
697 id: shutdownFadeOutRectangle
698 z: screenGrabber.z + 10
699 enabled: false
700 visible: false
701 color: "black"
702 anchors.fill: parent
703 opacity: 0.0
704 NumberAnimation on opacity {
705 id: shutdownFadeOut
706 from: 0.0
707 to: 1.0
708 onStopped: {
709 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
710 DBusUnitySessionService.Shutdown();
711 }
712 }
713 }
714 }