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