on 86a756f help sign in
unity8/qml/Shell.qml
710 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 }
174 DashCommunicator {
175 id: dash
176 objectName: "dashCommunicator"
177 }
179 PhysicalKeysMapper {
180 id: physicalKeysMapper
182 onPowerKeyLongPressed: dialogs.showPowerDialog()
183 onVolumeDownTriggered: volumeControl.volumeDown();
184 onVolumeUpTriggered: volumeControl.volumeUp();
185 onScreenshotTriggered: screenGrabber.capture();
186 }
188 ScreenGrabber {
189 id: screenGrabber
190 z: dialogs.z + 10
191 }
193 Binding {
194 target: ApplicationManager
195 property: "forceDashActive"
196 value: launcher.shown || launcher.dashSwipe
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 }
356 Tutorial {
357 id: tutorial
358 objectName: "tutorial"
359 anchors.fill: parent
360 active: AccountsService.demoEdges
361 paused: LightDM.Greeter.active
362 launcher: launcher
363 panel: panel
364 edgeSize: shell.edgeSize
366 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
367 // we'll tell the tutorial to avoid using them on the Desktop. The
368 // Desktop doesn't use the same spread design anyway. The tutorial is
369 // all a bit of a placeholder on non-phone form factors right now.
370 // When the design team gives us more guidance, we can do something
371 // more clever here.
372 // TODO: use DeviceConfiguration instead of checking source
373 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
375 onFinished: {
376 AccountsService.demoEdges = false;
377 active = false; // for immediate response / if AS is having problems
378 }
379 }
380 }
382 InputMethod {
383 id: inputMethod
384 objectName: "inputMethod"
385 anchors { fill: parent; topMargin: panel.panelHeight }
386 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
387 }
389 Connections {
390 target: SurfaceManager
391 onSurfaceCreated: {
392 if (surface.type == MirSurfaceItem.InputMethod) {
393 inputMethod.surface = surface;
394 }
395 }
397 onSurfaceDestroyed: {
398 if (inputMethod.surface == surface) {
399 inputMethod.surface = null;
400 surface.parent = null;
401 }
402 if (!surface.parent) {
403 // there's no one displaying it. delete it right away
404 surface.release();
405 }
406 }
407 }
408 Connections {
409 target: SessionManager
410 onSessionStopping: {
411 if (!session.parentSession && !session.application) {
412 // nothing is using it. delete it right away
413 session.release();
414 }
415 }
416 }
418 Loader {
419 id: greeterLoader
420 anchors.fill: parent
421 anchors.topMargin: panel.panelHeight
422 sourceComponent: shell.mode != "shell" ? integratedGreeter :
423 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
424 onLoaded: {
425 item.objectName = "greeter"
426 }
427 }
429 Component {
430 id: integratedGreeter
431 Greeter {
433 hides: [launcher, panel.indicators]
434 tabletMode: shell.usageScenario != "phone"
435 launcherOffset: launcher.progress
436 forcedUnlock: tutorial.running
437 background: shell.background
439 // avoid overlapping with Launcher's edge drag area
440 // FIXME: Fix TouchRegistry & friends and remove this workaround
441 // Issue involves launcher's DDA getting disabled on a long
442 // left-edge drag
443 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
445 onSessionStarted: {
446 launcher.hide();
447 }
449 onTease: {
450 if (!tutorial.running) {
451 launcher.tease();
452 }
453 }
455 onEmergencyCall: startLockedApp("dialer-app")
457 Binding {
458 target: ApplicationManager
459 property: "suspended"
460 value: greeter.shown
461 }
462 }
463 }
465 Timer {
466 // See powerConnection for why this is useful
467 id: showGreeterDelayed
468 interval: 1
469 onTriggered: {
470 greeter.forceShow();
471 }
472 }
474 Connections {
475 id: callConnection
476 target: callManager
478 onHasCallsChanged: {
479 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
480 // We just received an incoming call while locked. The
481 // indicator will have already launched dialer-app for us, but
482 // there is a race between "hasCalls" changing and the dialer
483 // starting up. So in case we lose that race, we'll start/
484 // focus the dialer ourselves here too. Even if the indicator
485 // didn't launch the dialer for some reason (or maybe a call
486 // started via some other means), if an active call is
487 // happening, we want to be in the dialer.
488 startLockedApp("dialer-app")
489 }
490 }
491 }
493 Connections {
494 id: powerConnection
495 target: Powerd
497 onStatusChanged: {
498 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
499 !callManager.hasCalls && !tutorial.running) {
500 // We don't want to simply call greeter.showNow() here, because
501 // that will take too long. Qt will delay button event
502 // handling until the greeter is done loading and may think the
503 // user held down the power button the whole time, leading to a
504 // power dialog being shown. Instead, delay showing the
505 // greeter until we've finished handling the event. We could
506 // make the greeter load asynchronously instead, but that
507 // introduces a whole host of timing issues, especially with
508 // its animations. So this is simpler.
509 showGreeterDelayed.start();
510 }
511 }
512 }
514 function showHome() {
515 if (tutorial.running) {
516 return
517 }
519 greeter.notifyAboutToFocusApp("unity8-dash");
521 var animate = !LightDM.Greeter.active && !stages.shown
522 dash.setCurrentScope(0, animate, false)
523 ApplicationManager.requestFocusApplication("unity8-dash")
524 }
526 function showDash() {
527 if (greeter.notifyShowingDashFromDrag()) {
528 launcher.fadeOut();
529 }
531 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
532 ApplicationManager.requestFocusApplication("unity8-dash")
533 launcher.fadeOut();
534 }
535 }
537 Item {
538 id: overlay
539 z: 10
541 anchors.fill: parent
543 Panel {
544 id: panel
545 objectName: "panel"
546 anchors.fill: parent //because this draws indicator menus
547 indicators {
548 hides: [launcher]
549 available: tutorial.panelEnabled
550 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
551 && (!greeter || !greeter.hasLockedApp)
552 contentEnabled: tutorial.panelContentEnabled
553 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
555 minimizedPanelHeight: units.gu(3)
556 expandedPanelHeight: units.gu(7)
558 indicatorsModel: Indicators.IndicatorsModel {
559 // tablet and phone both use the same profile
560 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
561 Component.onCompleted: load();
562 }
563 }
565 callHint {
566 greeterShown: greeter.shown
567 }
569 property bool mainAppIsFullscreen: shell.mainApp && shell.mainApp.fullscreen
570 fullscreenMode: (mainAppIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
571 || greeter.hasLockedApp
572 }
574 Launcher {
575 id: launcher
576 objectName: "launcher"
578 readonly property bool dashSwipe: progress > 0
580 anchors.top: parent.top
581 anchors.topMargin: inverted ? 0 : panel.panelHeight
582 anchors.bottom: parent.bottom
583 width: parent.width
584 dragAreaWidth: shell.edgeSize
585 available: tutorial.launcherEnabled
586 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
587 && !greeter.hasLockedApp
588 inverted: shell.usageScenario !== "desktop"
589 shadeBackground: !tutorial.running
591 onShowDashHome: showHome()
592 onDash: showDash()
593 onDashSwipeChanged: {
594 if (dashSwipe) {
595 dash.setCurrentScope(0, false, true)
596 }
597 }
598 onLauncherApplicationSelected: {
599 if (!tutorial.running) {
600 greeter.notifyAboutToFocusApp(appId);
601 shell.activateApplication(appId)
602 }
603 }
604 onShownChanged: {
605 if (shown) {
606 panel.indicators.hide()
607 }
608 }
609 }
611 Wizard {
612 id: wizard
613 objectName: "wizard"
614 anchors.fill: parent
615 background: shell.background
617 function unlockWhenDoneWithWizard() {
618 if (!active) {
619 Connectivity.unlockAllModems();
620 }
621 }
623 Component.onCompleted: unlockWhenDoneWithWizard()
624 onActiveChanged: unlockWhenDoneWithWizard()
625 }
627 Rectangle {
628 id: modalNotificationBackground
630 visible: notifications.useModal
631 color: "#000000"
632 anchors.fill: parent
633 opacity: 0.9
635 MouseArea {
636 anchors.fill: parent
637 }
638 }
640 Notifications {
641 id: notifications
643 model: NotificationBackend.Model
644 margin: units.gu(1)
646 y: topmostIsFullscreen ? 0 : panel.panelHeight
647 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
649 states: [
650 State {
651 name: "narrow"
652 when: overlay.width <= units.gu(60)
653 AnchorChanges {
654 target: notifications
655 anchors.left: parent.left
656 anchors.right: parent.right
657 }
658 },
659 State {
660 name: "wide"
661 when: overlay.width > units.gu(60)
662 AnchorChanges {
663 target: notifications
664 anchors.left: undefined
665 anchors.right: parent.right
666 }
667 PropertyChanges { target: notifications; width: units.gu(38) }
668 }
669 ]
670 }
671 }
673 Dialogs {
674 id: dialogs
675 objectName: "dialogs"
676 anchors.fill: parent
677 z: overlay.z + 10
678 onPowerOffClicked: {
679 shutdownFadeOutRectangle.enabled = true;
680 shutdownFadeOutRectangle.visible = true;
681 shutdownFadeOut.start();
682 }
683 }
685 Connections {
686 target: SessionBroadcast
687 onShowHome: showHome()
688 }
690 Rectangle {
691 id: shutdownFadeOutRectangle
692 z: screenGrabber.z + 10
693 enabled: false
694 visible: false
695 color: "black"
696 anchors.fill: parent
697 opacity: 0.0
698 NumberAnimation on opacity {
699 id: shutdownFadeOut
700 from: 0.0
701 to: 1.0
702 onStopped: {
703 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
704 DBusUnitySessionService.Shutdown();
705 }
706 }
707 }
708 }