on ba738ae help sign in
unity8/qml/Shell.qml
715 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 LightDM 0.1 as LightDM
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
45Item {
46 id: shell
48 // to be set from outside
49 property int orientationAngle: 0
50 property int orientation
51 property int primaryOrientation
52 property int nativeOrientation
53 property real nativeWidth
54 property real nativeHeight
55 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
56 property bool beingResized
57 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
58 property string mode: "full-greeter"
59 function updateFocusedAppOrientation() {
60 applicationsDisplayLoader.item.updateFocusedAppOrientation();
61 }
62 function updateFocusedAppOrientationAnimated() {
63 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
64 }
66 // to be read from outside
67 readonly property int mainAppWindowOrientationAngle:
68 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
70 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
71 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
72 && (!greeter || !greeter.animating)
74 readonly property bool showingGreeter: greeter && greeter.shown
76 property bool startingUp: true
77 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
79 property int supportedOrientations: {
80 if (startingUp) {
81 // Ensure we don't rotate during start up
82 return Qt.PrimaryOrientation;
83 } else if (greeter && greeter.shown) {
84 return Qt.PrimaryOrientation;
85 } else if (mainApp) {
86 return mainApp.supportedOrientations;
87 } else {
88 // we just don't care
89 return Qt.PortraitOrientation
90 | Qt.LandscapeOrientation
91 | Qt.InvertedPortraitOrientation
92 | Qt.InvertedLandscapeOrientation;
93 }
94 }
96 // For autopilot consumption
97 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
99 // internal props from here onwards
100 readonly property var mainApp:
101 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
103 // Disable everything while greeter is waiting, so that the user can't swipe
104 // the greeter or launcher until we know whether the session is locked.
105 enabled: greeter && !greeter.waiting
107 property real edgeSize: units.gu(2)
108 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
109 property url background: asImageTester.status == Image.Ready ? asImageTester.source
110 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
112 readonly property alias greeter: greeterLoader.item
114 function activateApplication(appId) {
115 if (ApplicationManager.findApplication(appId)) {
116 ApplicationManager.requestFocusApplication(appId);
117 } else {
118 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
119 : ApplicationManager.NoFlag;
120 ApplicationManager.startApplication(appId, execFlags);
121 }
122 }
124 function startLockedApp(app) {
125 if (greeter.locked) {
126 greeter.lockedApp = app;
127 }
128 shell.activateApplication(app);
129 }
131 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
132 Image {
133 id: asImageTester
134 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
135 height: 0
136 width: 0
137 sourceSize.height: 0
138 sourceSize.width: 0
139 }
141 GSettings {
142 id: backgroundSettings
143 schema.id: "org.gnome.desktop.background"
144 }
146 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
147 Image {
148 id: gsImageTester
149 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
150 height: 0
151 width: 0
152 sourceSize.height: 0
153 sourceSize.width: 0
154 }
156 Binding {
157 target: LauncherModel
158 property: "applicationManager"
159 value: ApplicationManager
160 }
162 Component.onCompleted: {
163 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
164 if (ApplicationManager.count > 0) {
165 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
166 }
167 finishStartUpTimer.start();
168 }
170 VolumeControl {
171 id: volumeControl
172 indicators: panel.indicators
173 }
175 DashCommunicator {
176 id: dash
177 objectName: "dashCommunicator"
178 }
180 PhysicalKeysMapper {
181 id: physicalKeysMapper
182 objectName: "physicalKeysMapper"
184 onPowerKeyLongPressed: dialogs.showPowerDialog()
185 onVolumeDownTriggered: volumeControl.volumeDown();
186 onVolumeUpTriggered: volumeControl.volumeUp();
187 onScreenshotTriggered: screenGrabber.capture();
188 }
190 ScreenGrabber {
191 id: screenGrabber
192 z: dialogs.z + 10
193 }
195 WindowKeysFilter {
196 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
197 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
198 }
200 HomeKeyWatcher {
201 onActivated: { launcher.fadeOut(); shell.showHome(); }
202 }
204 Item {
205 id: stages
206 objectName: "stages"
207 width: parent.width
208 height: parent.height
210 Connections {
211 target: ApplicationManager
213 // This signal is also fired when we try to focus the current app
214 // again. We rely on this!
215 onFocusedApplicationIdChanged: {
216 var appId = ApplicationManager.focusedApplicationId;
218 if (tutorial.running && appId != "" && appId != "unity8-dash") {
219 // If this happens on first boot, we may be in edge
220 // tutorial or wizard while receiving a call. But a call
221 // is more important than wizard so just bail out of those.
222 tutorial.finish();
223 wizard.hide();
224 }
226 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
227 // If we are in the middle of a call, make dialer lockedApp and show it.
228 // This can happen if user backs out of dialer back to greeter, then
229 // launches dialer again.
230 greeter.lockedApp = appId;
231 }
232 greeter.notifyAppFocused(appId);
234 panel.indicators.hide();
235 }
237 onApplicationAdded: {
238 launcher.hide();
239 }
240 }
242 Loader {
243 id: applicationsDisplayLoader
244 objectName: "applicationsDisplayLoader"
245 anchors.fill: parent
247 // When we have a locked app, we only want to show that one app.
248 // FIXME: do this in a less traumatic way. We currently only allow
249 // locked apps in phone mode (see FIXME in Lockscreen component in
250 // this same file). When that changes, we need to do something
251 // nicer here. But this code is currently just to prevent a
252 // theoretical attack where user enters lockedApp mode, then makes
253 // the screen larger (maybe connects to monitor) and tries to enter
254 // tablet mode.
256 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
257 ? "phone"
258 : shell.usageScenario
259 source: {
260 if(shell.mode === "greeter") {
261 return "Stages/ShimStage.qml"
262 } else if (applicationsDisplayLoader.usageScenario === "phone") {
263 return "Stages/PhoneStage.qml";
264 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
265 return "Stages/TabletStage.qml";
266 } else {
267 return "Stages/DesktopStage.qml";
268 }
269 }
271 property bool interactive: tutorial.spreadEnabled
272 && (!greeter || !greeter.shown)
273 && panel.indicators.fullyClosed
274 && launcher.progress == 0
275 && !notifications.useModal
277 onInteractiveChanged: { if (interactive) { focus = true; } }
279 Binding {
280 target: applicationsDisplayLoader.item
281 property: "objectName"
282 value: "stage"
283 }
284 Binding {
285 target: applicationsDisplayLoader.item
286 property: "dragAreaWidth"
287 value: shell.edgeSize
288 }
289 Binding {
290 target: applicationsDisplayLoader.item
291 property: "maximizedAppTopMargin"
292 // Not just using panel.panelHeight as that changes depending on the focused app.
293 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
294 }
295 Binding {
296 target: applicationsDisplayLoader.item
297 property: "interactive"
298 value: applicationsDisplayLoader.interactive
299 }
300 Binding {
301 target: applicationsDisplayLoader.item
302 property: "spreadEnabled"
303 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
304 }
305 Binding {
306 target: applicationsDisplayLoader.item
307 property: "inverseProgress"
308 value: greeter && greeter.locked ? 0 : launcher.progress
309 }
310 Binding {
311 target: applicationsDisplayLoader.item
312 property: "shellOrientationAngle"
313 value: shell.orientationAngle
314 }
315 Binding {
316 target: applicationsDisplayLoader.item
317 property: "shellOrientation"
318 value: shell.orientation
319 }
320 Binding {
321 target: applicationsDisplayLoader.item
322 property: "background"
323 value: shell.background
324 }
325 Binding {
326 target: applicationsDisplayLoader.item
327 property: "shellPrimaryOrientation"
328 value: shell.primaryOrientation
329 }
330 Binding {
331 target: applicationsDisplayLoader.item
332 property: "nativeOrientation"
333 value: shell.nativeOrientation
334 }
335 Binding {
336 target: applicationsDisplayLoader.item
337 property: "nativeWidth"
338 value: shell.nativeWidth
339 }
340 Binding {
341 target: applicationsDisplayLoader.item
342 property: "nativeHeight"
343 value: shell.nativeHeight
344 }
345 Binding {
346 target: applicationsDisplayLoader.item
347 property: "beingResized"
348 value: shell.beingResized
349 }
350 Binding {
351 target: applicationsDisplayLoader.item
352 property: "keepDashRunning"
353 value: launcher.shown || launcher.dashSwipe
354 }
355 Binding {
356 target: applicationsDisplayLoader.item
357 property: "suspended"
358 value: greeter.shown
359 }
360 Binding {
361 target: applicationsDisplayLoader.item
362 property: "altTabPressed"
363 value: physicalKeysMapper.altTabPressed
364 }
365 }
367 Tutorial {
368 id: tutorial
369 objectName: "tutorial"
370 anchors.fill: parent
371 active: AccountsService.demoEdges
372 paused: LightDM.Greeter.active
373 launcher: launcher
374 panel: panel
375 edgeSize: shell.edgeSize
377 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
378 // we'll tell the tutorial to avoid using them on the Desktop. The
379 // Desktop doesn't use the same spread design anyway. The tutorial is
380 // all a bit of a placeholder on non-phone form factors right now.
381 // When the design team gives us more guidance, we can do something
382 // more clever here.
383 // TODO: use DeviceConfiguration instead of checking source
384 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
386 onFinished: {
387 AccountsService.demoEdges = false;
388 active = false; // for immediate response / if AS is having problems
389 }
390 }
391 }
393 InputMethod {
394 id: inputMethod
395 objectName: "inputMethod"
396 anchors { fill: parent; topMargin: panel.panelHeight }
397 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
398 }
400 Connections {
401 target: SurfaceManager
402 onSurfaceCreated: {
403 if (surface.type == MirSurfaceItem.InputMethod) {
404 inputMethod.surface = surface;
405 }
406 }
408 onSurfaceDestroyed: {
409 if (inputMethod.surface == surface) {
410 inputMethod.surface = null;
411 surface.parent = null;
412 }
413 if (!surface.parent) {
414 // there's no one displaying it. delete it right away
415 surface.release();
416 }
417 }
418 }
419 Connections {
420 target: SessionManager
421 onSessionStopping: {
422 if (!session.parentSession && !session.application) {
423 // nothing is using it. delete it right away
424 session.release();
425 }
426 }
427 }
429 Loader {
430 id: greeterLoader
431 anchors.fill: parent
432 anchors.topMargin: panel.panelHeight
433 sourceComponent: shell.mode != "shell" ? integratedGreeter :
434 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
435 onLoaded: {
436 item.objectName = "greeter"
437 }
438 }
440 Component {
441 id: integratedGreeter
442 Greeter {
444 hides: [launcher, panel.indicators]
445 tabletMode: shell.usageScenario != "phone"
446 launcherOffset: launcher.progress
447 forcedUnlock: tutorial.running
448 background: shell.background
450 // avoid overlapping with Launcher's edge drag area
451 // FIXME: Fix TouchRegistry & friends and remove this workaround
452 // Issue involves launcher's DDA getting disabled on a long
453 // left-edge drag
454 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
456 onSessionStarted: {
457 launcher.hide();
458 }
460 onTease: {
461 if (!tutorial.running) {
462 launcher.tease();
463 }
464 }
466 onEmergencyCall: startLockedApp("dialer-app")
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
622 function unlockWhenDoneWithWizard() {
623 if (!active) {
624 Connectivity.unlockAllModems();
625 }
626 }
628 Component.onCompleted: unlockWhenDoneWithWizard()
629 onActiveChanged: unlockWhenDoneWithWizard()
630 }
632 Rectangle {
633 id: modalNotificationBackground
635 visible: notifications.useModal
636 color: "#000000"
637 anchors.fill: parent
638 opacity: 0.9
640 MouseArea {
641 anchors.fill: parent
642 }
643 }
645 Notifications {
646 id: notifications
648 model: NotificationBackend.Model
649 margin: units.gu(1)
651 y: topmostIsFullscreen ? 0 : panel.panelHeight
652 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
654 states: [
655 State {
656 name: "narrow"
657 when: overlay.width <= units.gu(60)
658 AnchorChanges {
659 target: notifications
660 anchors.left: parent.left
661 anchors.right: parent.right
662 }
663 },
664 State {
665 name: "wide"
666 when: overlay.width > units.gu(60)
667 AnchorChanges {
668 target: notifications
669 anchors.left: undefined
670 anchors.right: parent.right
671 }
672 PropertyChanges { target: notifications; width: units.gu(38) }
673 }
674 ]
675 }
676 }
678 Dialogs {
679 id: dialogs
680 objectName: "dialogs"
681 anchors.fill: parent
682 z: overlay.z + 10
683 onPowerOffClicked: {
684 shutdownFadeOutRectangle.enabled = true;
685 shutdownFadeOutRectangle.visible = true;
686 shutdownFadeOut.start();
687 }
688 }
690 Connections {
691 target: SessionBroadcast
692 onShowHome: showHome()
693 }
695 Rectangle {
696 id: shutdownFadeOutRectangle
697 z: screenGrabber.z + 10
698 enabled: false
699 visible: false
700 color: "black"
701 anchors.fill: parent
702 opacity: 0.0
703 NumberAnimation on opacity {
704 id: shutdownFadeOut
705 from: 0.0
706 to: 1.0
707 onStopped: {
708 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
709 DBusUnitySessionService.Shutdown();
710 }
711 }
712 }
713 }