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