on fcccc72 help sign in
unity8/qml/Shell.qml
686 lines 23 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 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.animating
73 property bool startingUp: true
74 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
76 property int supportedOrientations: {
77 if (startingUp) {
78 // Ensure we don't rotate during start up
79 return Qt.PrimaryOrientation;
80 } else if (greeter.shown) {
81 return Qt.PrimaryOrientation;
82 } else if (mainApp) {
83 return mainApp.supportedOrientations;
84 } else {
85 // we just don't care
86 return Qt.PortraitOrientation
87 | Qt.LandscapeOrientation
88 | Qt.InvertedPortraitOrientation
89 | Qt.InvertedLandscapeOrientation;
90 }
91 }
93 // For autopilot consumption
94 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
96 // internal props from here onwards
97 readonly property var mainApp:
98 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
100 // Disable everything while greeter is waiting, so that the user can't swipe
101 // the greeter or launcher until we know whether the session is locked.
102 enabled: !greeter.waiting
104 property real edgeSize: units.gu(2)
105 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
106 property url background: asImageTester.status == Image.Ready ? asImageTester.source
107 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
108 readonly property real panelHeight: panel.panelHeight
110 function activateApplication(appId) {
111 if (ApplicationManager.findApplication(appId)) {
112 ApplicationManager.requestFocusApplication(appId);
113 } else {
114 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
115 : ApplicationManager.NoFlag;
116 ApplicationManager.startApplication(appId, execFlags);
117 }
118 }
120 function startLockedApp(app) {
121 if (greeter.locked) {
122 greeter.lockedApp = app;
123 }
124 shell.activateApplication(app);
125 }
127 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
128 Image {
129 id: asImageTester
130 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
131 height: 0
132 width: 0
133 sourceSize.height: 0
134 sourceSize.width: 0
135 }
137 GSettings {
138 id: backgroundSettings
139 objectName: "backgroundSettings"
140 schema.id: "org.gnome.desktop.background"
141 }
143 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
144 Image {
145 id: gsImageTester
146 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
147 height: 0
148 width: 0
149 sourceSize.height: 0
150 sourceSize.width: 0
151 }
153 Binding {
154 target: LauncherModel
155 property: "applicationManager"
156 value: ApplicationManager
157 }
159 Component.onCompleted: {
160 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
161 if (ApplicationManager.count > 0) {
162 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
163 }
164 finishStartUpTimer.start();
165 }
167 VolumeControl {
168 id: volumeControl
169 }
171 DashCommunicator {
172 id: dash
173 objectName: "dashCommunicator"
174 }
176 PhysicalKeysMapper {
177 id: physicalKeysMapper
179 onPowerKeyLongPressed: dialogs.showPowerDialog()
180 onVolumeDownTriggered: volumeControl.volumeDown();
181 onVolumeUpTriggered: volumeControl.volumeUp();
182 onScreenshotTriggered: screenGrabber.capture();
183 }
185 ScreenGrabber {
186 id: screenGrabber
187 z: dialogs.z + 10
188 enabled: Powerd.status === Powerd.On
189 }
191 Binding {
192 target: ApplicationManager
193 property: "forceDashActive"
194 value: launcher.shown || launcher.dashSwipe
195 }
197 WindowKeysFilter {
198 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
199 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
200 }
202 Item {
203 id: stages
204 objectName: "stages"
205 width: parent.width
206 height: parent.height
207 visible: !ApplicationManager.empty
209 Connections {
210 target: ApplicationManager
212 // This signal is also fired when we try to focus the current app
213 // again. We rely on this!
214 onFocusedApplicationIdChanged: {
215 var appId = ApplicationManager.focusedApplicationId;
217 if (tutorial.running && appId != "" && appId != "unity8-dash") {
218 // If this happens on first boot, we may be in edge
219 // tutorial or wizard while receiving a call. But a call
220 // is more important than wizard so just bail out of those.
221 tutorial.finish();
222 wizard.hide();
223 }
225 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
226 // If we are in the middle of a call, make dialer lockedApp and show it.
227 // This can happen if user backs out of dialer back to greeter, then
228 // launches dialer again.
229 greeter.lockedApp = appId;
230 }
231 greeter.notifyAppFocused(appId);
233 panel.indicators.hide();
234 }
236 onApplicationAdded: {
237 launcher.hide();
238 }
239 }
241 Loader {
242 id: applicationsDisplayLoader
243 objectName: "applicationsDisplayLoader"
244 anchors.fill: parent
246 // When we have a locked app, we only want to show that one app.
247 // FIXME: do this in a less traumatic way. We currently only allow
248 // locked apps in phone mode (see FIXME in Lockscreen component in
249 // this same file). When that changes, we need to do something
250 // nicer here. But this code is currently just to prevent a
251 // theoretical attack where user enters lockedApp mode, then makes
252 // the screen larger (maybe connects to monitor) and tries to enter
253 // tablet mode.
255 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
256 ? "phone"
257 : shell.usageScenario
258 source: {
259 if (applicationsDisplayLoader.usageScenario === "phone") {
260 return "Stages/PhoneStage.qml";
261 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
262 return "Stages/TabletStage.qml";
263 } else {
264 return "Stages/DesktopStage.qml";
265 }
266 }
268 property bool interactive: tutorial.spreadEnabled
269 && !greeter.shown
270 && panel.indicators.fullyClosed
271 && launcher.progress == 0
272 && !notifications.useModal
274 onInteractiveChanged: { if (interactive) { focus = true; } }
276 Binding {
277 target: applicationsDisplayLoader.item
278 property: "objectName"
279 value: "stage"
280 }
281 Binding {
282 target: applicationsDisplayLoader.item
283 property: "dragAreaWidth"
284 value: shell.edgeSize
285 }
286 Binding {
287 target: applicationsDisplayLoader.item
288 property: "maximizedAppTopMargin"
289 // Not just using panel.panelHeight as that changes depending on the focused app.
290 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
291 }
292 Binding {
293 target: applicationsDisplayLoader.item
294 property: "interactive"
295 value: applicationsDisplayLoader.interactive
296 }
297 Binding {
298 target: applicationsDisplayLoader.item
299 property: "spreadEnabled"
300 value: tutorial.spreadEnabled && !greeter.hasLockedApp
301 }
302 Binding {
303 target: applicationsDisplayLoader.item
304 property: "inverseProgress"
305 value: greeter.locked ? 0 : launcher.progress
306 }
307 Binding {
308 target: applicationsDisplayLoader.item
309 property: "shellOrientationAngle"
310 value: shell.orientationAngle
311 }
312 Binding {
313 target: applicationsDisplayLoader.item
314 property: "shellOrientation"
315 value: shell.orientation
316 }
317 Binding {
318 target: applicationsDisplayLoader.item
319 property: "background"
320 value: shell.background
321 }
322 Binding {
323 target: applicationsDisplayLoader.item
324 property: "shellPrimaryOrientation"
325 value: shell.primaryOrientation
326 }
327 Binding {
328 target: applicationsDisplayLoader.item
329 property: "nativeOrientation"
330 value: shell.nativeOrientation
331 }
332 Binding {
333 target: applicationsDisplayLoader.item
334 property: "nativeWidth"
335 value: shell.nativeWidth
336 }
337 Binding {
338 target: applicationsDisplayLoader.item
339 property: "nativeHeight"
340 value: shell.nativeHeight
341 }
342 Binding {
343 target: applicationsDisplayLoader.item
344 property: "beingResized"
345 value: shell.beingResized
346 }
347 }
348 }
350 InputMethod {
351 id: inputMethod
352 objectName: "inputMethod"
353 anchors { fill: parent; topMargin: panel.panelHeight }
354 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
355 }
357 Connections {
358 target: SurfaceManager
359 onSurfaceCreated: {
360 if (surface.type == MirSurfaceItem.InputMethod) {
361 inputMethod.surface = surface;
362 }
363 }
365 onSurfaceDestroyed: {
366 if (inputMethod.surface == surface) {
367 inputMethod.surface = null;
368 surface.parent = null;
369 }
370 if (!surface.parent) {
371 // there's no one displaying it. delete it right away
372 surface.release();
373 }
374 }
375 }
376 Connections {
377 target: SessionManager
378 onSessionStopping: {
379 if (!session.parentSession && !session.application) {
380 // nothing is using it. delete it right away
381 session.release();
382 }
383 }
384 }
386 Greeter {
387 id: greeter
388 objectName: "greeter"
390 hides: [launcher, panel.indicators]
391 tabletMode: shell.usageScenario !== "phone"
392 launcherOffset: launcher.progress
393 forcedUnlock: tutorial.running
394 background: shell.background
396 anchors.fill: parent
397 anchors.topMargin: panel.panelHeight
399 // avoid overlapping with Launcher's edge drag area
400 // FIXME: Fix TouchRegistry & friends and remove this workaround
401 // Issue involves launcher's DDA getting disabled on a long
402 // left-edge drag
403 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
405 onSessionStarted: {
406 launcher.hide();
407 }
409 onTease: {
410 if (!tutorial.running) {
411 launcher.tease();
412 }
413 }
415 onEmergencyCall: startLockedApp("dialer-app")
417 Timer {
418 // See powerConnection for why this is useful
419 id: showGreeterDelayed
420 interval: 1
421 onTriggered: {
422 greeter.forceShow();
423 }
424 }
426 Binding {
427 target: ApplicationManager
428 property: "suspended"
429 value: greeter.shown
430 }
431 }
433 Connections {
434 id: callConnection
435 target: callManager
437 onHasCallsChanged: {
438 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
439 // We just received an incoming call while locked. The
440 // indicator will have already launched dialer-app for us, but
441 // there is a race between "hasCalls" changing and the dialer
442 // starting up. So in case we lose that race, we'll start/
443 // focus the dialer ourselves here too. Even if the indicator
444 // didn't launch the dialer for some reason (or maybe a call
445 // started via some other means), if an active call is
446 // happening, we want to be in the dialer.
447 startLockedApp("dialer-app")
448 }
449 }
450 }
452 Connections {
453 id: powerConnection
454 target: Powerd
456 onStatusChanged: {
457 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
458 !callManager.hasCalls && !tutorial.running) {
459 // We don't want to simply call greeter.showNow() here, because
460 // that will take too long. Qt will delay button event
461 // handling until the greeter is done loading and may think the
462 // user held down the power button the whole time, leading to a
463 // power dialog being shown. Instead, delay showing the
464 // greeter until we've finished handling the event. We could
465 // make the greeter load asynchronously instead, but that
466 // introduces a whole host of timing issues, especially with
467 // its animations. So this is simpler.
468 showGreeterDelayed.start();
469 }
470 }
471 }
473 function showHome() {
474 if (tutorial.running) {
475 return
476 }
478 greeter.notifyAboutToFocusApp("unity8-dash");
480 var animate = !LightDM.Greeter.active && !stages.shown
481 dash.setCurrentScope(0, animate, false)
482 ApplicationManager.requestFocusApplication("unity8-dash")
483 }
485 function showDash() {
486 if (greeter.notifyShowingDashFromDrag()) {
487 launcher.fadeOut();
488 }
490 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
491 ApplicationManager.requestFocusApplication("unity8-dash")
492 launcher.fadeOut();
493 }
494 }
496 Item {
497 id: overlay
498 z: 10
500 anchors.fill: parent
502 Panel {
503 id: panel
504 objectName: "panel"
505 anchors.fill: parent //because this draws indicator menus
506 indicators {
507 hides: [launcher]
508 available: tutorial.panelEnabled
509 && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
510 && !greeter.hasLockedApp
511 contentEnabled: tutorial.panelContentEnabled
512 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
514 minimizedPanelHeight: units.gu(3)
515 expandedPanelHeight: units.gu(7)
517 indicatorsModel: Indicators.IndicatorsModel {
518 // tablet and phone both use the same profile
519 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
520 Component.onCompleted: load();
521 }
522 }
524 callHint {
525 greeterShown: greeter.shown
526 }
528 property bool mainAppIsFullscreen: shell.mainApp && shell.mainApp.fullscreen
529 fullscreenMode: (mainAppIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
530 || greeter.hasLockedApp
531 }
533 Launcher {
534 id: launcher
535 objectName: "launcher"
537 readonly property bool dashSwipe: progress > 0
539 anchors.top: parent.top
540 anchors.topMargin: inverted ? 0 : panel.panelHeight
541 anchors.bottom: parent.bottom
542 width: parent.width
543 dragAreaWidth: shell.edgeSize
544 available: tutorial.launcherEnabled
545 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
546 && !greeter.hasLockedApp
547 inverted: shell.usageScenario !== "desktop"
548 shadeBackground: !tutorial.running
550 onShowDashHome: showHome()
551 onDash: showDash()
552 onDashSwipeChanged: {
553 if (dashSwipe) {
554 dash.setCurrentScope(0, false, true)
555 }
556 }
557 onLauncherApplicationSelected: {
558 if (!tutorial.running) {
559 greeter.notifyAboutToFocusApp(appId);
560 shell.activateApplication(appId)
561 }
562 }
563 onShownChanged: {
564 if (shown) {
565 panel.indicators.hide()
566 }
567 }
568 }
570 Wizard {
571 id: wizard
572 objectName: "wizard"
573 anchors.fill: parent
574 background: shell.background
576 function unlockWhenDoneWithWizard() {
577 if (!active) {
578 Connectivity.unlockAllModems();
579 }
580 }
582 Component.onCompleted: unlockWhenDoneWithWizard()
583 onActiveChanged: unlockWhenDoneWithWizard()
584 }
586 Rectangle {
587 id: modalNotificationBackground
589 visible: notifications.useModal
590 color: "#000000"
591 anchors.fill: parent
592 opacity: 0.9
594 MouseArea {
595 anchors.fill: parent
596 }
597 }
599 Notifications {
600 id: notifications
602 model: NotificationBackend.Model
603 margin: units.gu(1)
605 y: topmostIsFullscreen ? 0 : panel.panelHeight
606 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
608 states: [
609 State {
610 name: "narrow"
611 when: overlay.width <= units.gu(60)
612 AnchorChanges {
613 target: notifications
614 anchors.left: parent.left
615 anchors.right: parent.right
616 }
617 },
618 State {
619 name: "wide"
620 when: overlay.width > units.gu(60)
621 AnchorChanges {
622 target: notifications
623 anchors.left: undefined
624 anchors.right: parent.right
625 }
626 PropertyChanges { target: notifications; width: units.gu(38) }
627 }
628 ]
629 }
630 }
632 Dialogs {
633 id: dialogs
634 objectName: "dialogs"
635 anchors.fill: parent
636 z: overlay.z + 10
637 onPowerOffClicked: {
638 shutdownFadeOutRectangle.enabled = true;
639 shutdownFadeOutRectangle.visible = true;
640 shutdownFadeOut.start();
641 }
642 }
644 Tutorial {
645 id: tutorial
646 objectName: "tutorial"
647 active: AccountsService.demoEdges
648 paused: LightDM.Greeter.active
649 launcher: launcher
650 panel: panel
651 stages: stages
652 overlay: overlay
653 edgeSize: shell.edgeSize
655 onFinished: {
656 AccountsService.demoEdges = false;
657 active = false; // for immediate response / if AS is having problems
658 }
659 }
661 Connections {
662 target: SessionBroadcast
663 onShowHome: showHome()
664 }
666 Rectangle {
667 id: shutdownFadeOutRectangle
668 z: screenGrabber.z + 10
669 enabled: false
670 visible: false
671 color: "black"
672 anchors.fill: parent
673 opacity: 0.0
674 NumberAnimation on opacity {
675 id: shutdownFadeOut
676 from: 0.0
677 to: 1.0
678 onStopped: {
679 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
680 DBusUnitySessionService.Shutdown();
681 }
682 }
683 }
684 }