on 3165eb4 help sign in
unity8/qml/Shell.qml
698 lines 24 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 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
372 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
373 // we skip the tutorial on the Desktop to avoid using them. 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 active: usageScenario != "desktop" && AccountsService.demoEdges
380 paused: lightDM.greeter.active
381 launcher: launcher
382 panel: panel
383 edgeSize: shell.edgeSize
385 onFinished: {
386 AccountsService.demoEdges = false;
387 active = false; // for immediate response / if AS is having problems
388 }
389 }
390 }
392 InputMethod {
393 id: inputMethod
394 objectName: "inputMethod"
395 anchors { fill: parent; topMargin: panel.panelHeight }
396 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
397 }
399 Connections {
400 target: SessionManager
401 onSessionStopping: {
402 if (!session.parentSession && !session.application) {
403 // nothing is using it. delete it right away
404 session.release();
405 }
406 }
407 }
409 Loader {
410 id: greeterLoader
411 anchors.fill: parent
412 anchors.topMargin: panel.panelHeight
413 sourceComponent: shell.mode != "shell" ? integratedGreeter :
414 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
415 onLoaded: {
416 item.objectName = "greeter"
417 }
418 }
420 Component {
421 id: integratedGreeter
422 Greeter {
424 hides: [launcher, panel.indicators]
425 tabletMode: shell.usageScenario != "phone"
426 launcherOffset: launcher.progress
427 forcedUnlock: tutorial.running
428 background: shell.background
430 // avoid overlapping with Launcher's edge drag area
431 // FIXME: Fix TouchRegistry & friends and remove this workaround
432 // Issue involves launcher's DDA getting disabled on a long
433 // left-edge drag
434 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
436 onSessionStarted: {
437 launcher.hide();
438 }
440 onTease: {
441 if (!tutorial.running) {
442 launcher.tease();
443 }
444 }
446 onEmergencyCall: startLockedApp("dialer-app")
447 }
448 }
450 Timer {
451 // See powerConnection for why this is useful
452 id: showGreeterDelayed
453 interval: 1
454 onTriggered: {
455 greeter.forceShow();
456 }
457 }
459 Connections {
460 id: callConnection
461 target: callManager
463 onHasCallsChanged: {
464 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
465 // We just received an incoming call while locked. The
466 // indicator will have already launched dialer-app for us, but
467 // there is a race between "hasCalls" changing and the dialer
468 // starting up. So in case we lose that race, we'll start/
469 // focus the dialer ourselves here too. Even if the indicator
470 // didn't launch the dialer for some reason (or maybe a call
471 // started via some other means), if an active call is
472 // happening, we want to be in the dialer.
473 startLockedApp("dialer-app")
474 }
475 }
476 }
478 Connections {
479 id: powerConnection
480 target: Powerd
482 onStatusChanged: {
483 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
484 !callManager.hasCalls && !tutorial.running) {
485 // We don't want to simply call greeter.showNow() here, because
486 // that will take too long. Qt will delay button event
487 // handling until the greeter is done loading and may think the
488 // user held down the power button the whole time, leading to a
489 // power dialog being shown. Instead, delay showing the
490 // greeter until we've finished handling the event. We could
491 // make the greeter load asynchronously instead, but that
492 // introduces a whole host of timing issues, especially with
493 // its animations. So this is simpler.
494 showGreeterDelayed.start();
495 }
496 }
497 }
499 function showHome() {
500 if (tutorial.running) {
501 return
502 }
504 greeter.notifyAboutToFocusApp("unity8-dash");
506 var animate = !lightDM.greeter.active && !stages.shown
507 dash.setCurrentScope(0, animate, false)
508 ApplicationManager.requestFocusApplication("unity8-dash")
509 }
511 function showDash() {
512 if (greeter.notifyShowingDashFromDrag()) {
513 launcher.fadeOut();
514 }
516 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
517 ApplicationManager.requestFocusApplication("unity8-dash")
518 launcher.fadeOut();
519 }
520 }
522 Item {
523 id: overlay
524 z: 10
526 anchors.fill: parent
528 Panel {
529 id: panel
530 objectName: "panel"
531 anchors.fill: parent //because this draws indicator menus
532 indicators {
533 hides: [launcher]
534 available: tutorial.panelEnabled
535 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
536 && (!greeter || !greeter.hasLockedApp)
537 contentEnabled: tutorial.panelContentEnabled
538 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
540 minimizedPanelHeight: units.gu(3)
541 expandedPanelHeight: units.gu(7)
543 indicatorsModel: Indicators.IndicatorsModel {
544 // tablet and phone both use the same profile
545 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
546 Component.onCompleted: load();
547 }
548 }
550 callHint {
551 greeterShown: greeter.shown
552 }
554 property bool topmostApplicationIsFullscreen:
555 ApplicationManager.focusedApplicationId &&
556 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
558 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
559 || greeter.hasLockedApp
560 }
562 Launcher {
563 id: launcher
564 objectName: "launcher"
566 readonly property bool dashSwipe: progress > 0
568 anchors.top: parent.top
569 anchors.topMargin: inverted ? 0 : panel.panelHeight
570 anchors.bottom: parent.bottom
571 width: parent.width
572 dragAreaWidth: shell.edgeSize
573 available: tutorial.launcherEnabled
574 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
575 && !greeter.hasLockedApp
576 inverted: shell.usageScenario !== "desktop"
577 shadeBackground: !tutorial.running
579 onShowDashHome: showHome()
580 onDash: showDash()
581 onDashSwipeChanged: {
582 if (dashSwipe) {
583 dash.setCurrentScope(0, false, true)
584 }
585 }
586 onLauncherApplicationSelected: {
587 if (!tutorial.running) {
588 greeter.notifyAboutToFocusApp(appId);
589 shell.activateApplication(appId)
590 }
591 }
592 onShownChanged: {
593 if (shown) {
594 panel.indicators.hide()
595 }
596 }
597 }
599 Wizard {
600 id: wizard
601 objectName: "wizard"
602 anchors.fill: parent
603 background: shell.background
605 function unlockWhenDoneWithWizard() {
606 if (!active) {
607 Connectivity.unlockAllModems();
608 }
609 }
611 Component.onCompleted: unlockWhenDoneWithWizard()
612 onActiveChanged: unlockWhenDoneWithWizard()
613 }
615 Rectangle {
616 id: modalNotificationBackground
618 visible: notifications.useModal
619 color: "#000000"
620 anchors.fill: parent
621 opacity: 0.9
623 MouseArea {
624 anchors.fill: parent
625 }
626 }
628 Notifications {
629 id: notifications
631 model: NotificationBackend.Model
632 margin: units.gu(1)
634 y: topmostIsFullscreen ? 0 : panel.panelHeight
635 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
637 states: [
638 State {
639 name: "narrow"
640 when: overlay.width <= units.gu(60)
641 AnchorChanges {
642 target: notifications
643 anchors.left: parent.left
644 anchors.right: parent.right
645 }
646 },
647 State {
648 name: "wide"
649 when: overlay.width > units.gu(60)
650 AnchorChanges {
651 target: notifications
652 anchors.left: undefined
653 anchors.right: parent.right
654 }
655 PropertyChanges { target: notifications; width: units.gu(38) }
656 }
657 ]
658 }
659 }
661 Dialogs {
662 id: dialogs
663 objectName: "dialogs"
664 anchors.fill: parent
665 z: overlay.z + 10
666 onPowerOffClicked: {
667 shutdownFadeOutRectangle.enabled = true;
668 shutdownFadeOutRectangle.visible = true;
669 shutdownFadeOut.start();
670 }
671 }
673 Connections {
674 target: SessionBroadcast
675 onShowHome: showHome()
676 }
678 Rectangle {
679 id: shutdownFadeOutRectangle
680 z: screenGrabber.z + 10
681 enabled: false
682 visible: false
683 color: "black"
684 anchors.fill: parent
685 opacity: 0.0
686 NumberAnimation on opacity {
687 id: shutdownFadeOut
688 from: 0.0
689 to: 1.0
690 onStopped: {
691 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
692 DBusUnitySessionService.Shutdown();
693 }
694 }
695 }
696 }