on 85cbe53 help sign in
unity8/qml/Shell.qml
701 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 GlobalShortcut 1.0 // has to be before Utils, because of WindowKeysFilter
29import Utils 0.1
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
46Item {
47 id: shell
49 // to be set from outside
50 property int orientationAngle: 0
51 property int orientation
52 property Orientations orientations
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 }
65 property bool hasMouse
67 // to be read from outside
68 readonly property int mainAppWindowOrientationAngle:
69 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
71 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
72 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
73 && (!greeter || !greeter.animating)
75 readonly property bool showingGreeter: greeter && greeter.shown
77 property bool startingUp: true
78 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
80 property int supportedOrientations: {
81 if (startingUp) {
82 // Ensure we don't rotate during start up
83 return Qt.PrimaryOrientation;
84 } else if (greeter && greeter.shown) {
85 return Qt.PrimaryOrientation;
86 } else if (mainApp) {
87 return mainApp.supportedOrientations;
88 } else {
89 // we just don't care
90 return Qt.PortraitOrientation
91 | Qt.LandscapeOrientation
92 | Qt.InvertedPortraitOrientation
93 | Qt.InvertedLandscapeOrientation;
94 }
95 }
97 // For autopilot consumption
98 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
100 // internal props from here onwards
101 readonly property var mainApp:
102 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
104 // Disable everything while greeter is waiting, so that the user can't swipe
105 // the greeter or launcher until we know whether the session is locked.
106 enabled: greeter && !greeter.waiting
108 property real edgeSize: units.gu(2)
109 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
110 property url background: asImageTester.status == Image.Ready ? asImageTester.source
111 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
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 && 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 indicators: panel.indicators
175 }
177 DashCommunicator {
178 id: dash
179 objectName: "dashCommunicator"
180 }
182 PhysicalKeysMapper {
183 id: physicalKeysMapper
184 objectName: "physicalKeysMapper"
186 onPowerKeyLongPressed: dialogs.showPowerDialog();
187 onVolumeDownTriggered: volumeControl.volumeDown();
188 onVolumeUpTriggered: volumeControl.volumeUp();
189 onScreenshotTriggered: screenGrabber.capture();
190 }
192 ScreenGrabber {
193 id: screenGrabber
194 z: dialogs.z + 10
195 }
197 GlobalShortcut {
198 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
199 }
201 WindowKeysFilter {
202 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
203 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
204 }
206 HomeKeyWatcher {
207 onActivated: { launcher.fadeOut(); shell.showHome(); }
208 }
210 Item {
211 id: stages
212 objectName: "stages"
213 width: parent.width
214 height: parent.height
216 Connections {
217 target: ApplicationManager
219 // This signal is also fired when we try to focus the current app
220 // again. We rely on this!
221 onFocusedApplicationIdChanged: {
222 var appId = ApplicationManager.focusedApplicationId;
224 if (tutorial.running && appId != "" && appId != "unity8-dash") {
225 // If this happens on first boot, we may be in edge
226 // tutorial or wizard while receiving a call. But a call
227 // is more important than wizard so just bail out of those.
228 tutorial.finish();
229 wizard.hide();
230 }
232 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
233 // If we are in the middle of a call, make dialer lockedApp and show it.
234 // This can happen if user backs out of dialer back to greeter, then
235 // launches dialer again.
236 greeter.lockedApp = appId;
237 }
238 greeter.notifyAppFocused(appId);
240 panel.indicators.hide();
241 }
243 onApplicationAdded: {
244 launcher.hide();
245 }
246 }
248 Loader {
249 id: applicationsDisplayLoader
250 objectName: "applicationsDisplayLoader"
251 anchors.fill: parent
253 // When we have a locked app, we only want to show that one app.
254 // FIXME: do this in a less traumatic way. We currently only allow
255 // locked apps in phone mode (see FIXME in Lockscreen component in
256 // this same file). When that changes, we need to do something
257 // nicer here. But this code is currently just to prevent a
258 // theoretical attack where user enters lockedApp mode, then makes
259 // the screen larger (maybe connects to monitor) and tries to enter
260 // tablet mode.
262 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
263 ? "phone"
264 : shell.usageScenario
265 source: {
266 if(shell.mode === "greeter") {
267 return "Stages/ShimStage.qml"
268 } else if (applicationsDisplayLoader.usageScenario === "phone") {
269 return "Stages/PhoneStage.qml";
270 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
271 return "Stages/TabletStage.qml";
272 } else {
273 return "Stages/DesktopStage.qml";
274 }
275 }
277 property bool interactive: tutorial.spreadEnabled
278 && (!greeter || !greeter.shown)
279 && panel.indicators.fullyClosed
280 && launcher.progress == 0
281 && !notifications.useModal
283 onInteractiveChanged: { if (interactive) { focus = true; } }
285 Binding {
286 target: applicationsDisplayLoader.item
287 property: "objectName"
288 value: "stage"
289 }
290 Binding {
291 target: applicationsDisplayLoader.item
292 property: "dragAreaWidth"
293 value: shell.edgeSize
294 }
295 Binding {
296 target: applicationsDisplayLoader.item
297 property: "maximizedAppTopMargin"
298 // Not just using panel.panelHeight as that changes depending on the focused app.
299 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
300 }
301 Binding {
302 target: applicationsDisplayLoader.item
303 property: "interactive"
304 value: applicationsDisplayLoader.interactive
305 }
306 Binding {
307 target: applicationsDisplayLoader.item
308 property: "spreadEnabled"
309 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
310 }
311 Binding {
312 target: applicationsDisplayLoader.item
313 property: "inverseProgress"
314 value: greeter && greeter.locked ? 0 : launcher.progress
315 }
316 Binding {
317 target: applicationsDisplayLoader.item
318 property: "shellOrientationAngle"
319 value: shell.orientationAngle
320 }
321 Binding {
322 target: applicationsDisplayLoader.item
323 property: "shellOrientation"
324 value: shell.orientation
325 }
326 Binding {
327 target: applicationsDisplayLoader.item
328 property: "orientations"
329 value: shell.orientations
330 }
331 Binding {
332 target: applicationsDisplayLoader.item
333 property: "background"
334 value: shell.background
335 }
336 Binding {
337 target: applicationsDisplayLoader.item
338 property: "nativeWidth"
339 value: shell.nativeWidth
340 }
341 Binding {
342 target: applicationsDisplayLoader.item
343 property: "nativeHeight"
344 value: shell.nativeHeight
345 }
346 Binding {
347 target: applicationsDisplayLoader.item
348 property: "beingResized"
349 value: shell.beingResized
350 }
351 Binding {
352 target: applicationsDisplayLoader.item
353 property: "keepDashRunning"
354 value: launcher.shown || launcher.dashSwipe
355 }
356 Binding {
357 target: applicationsDisplayLoader.item
358 property: "suspended"
359 value: greeter.shown
360 }
361 Binding {
362 target: applicationsDisplayLoader.item
363 property: "altTabPressed"
364 value: physicalKeysMapper.altTabPressed
365 }
366 }
368 Tutorial {
369 id: tutorial
370 objectName: "tutorial"
371 anchors.fill: parent
373 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
374 // we skip the tutorial on the Desktop to avoid using them. The
375 // Desktop doesn't use the same spread design anyway. The tutorial is
376 // all a bit of a placeholder on non-phone form factors right now.
377 // When the design team gives us more guidance, we can do something
378 // more clever here.
379 active: usageScenario != "desktop" && AccountsService.demoEdges
381 paused: lightDM.greeter.active
382 launcher: launcher
383 panel: panel
384 edgeSize: shell.edgeSize
386 onFinished: {
387 AccountsService.demoEdges = false;
388 active = false; // for immediate response / if AS is having problems
389 }
390 }
391 }
393 InputMethod {
394 id: inputMethod
395 objectName: "inputMethod"
396 anchors { fill: parent; topMargin: panel.panelHeight }
397 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
398 }
400 Connections {
401 target: SessionManager
402 onSessionStopping: {
403 if (!session.parentSession && !session.application) {
404 // nothing is using it. delete it right away
405 session.release();
406 }
407 }
408 }
410 Loader {
411 id: greeterLoader
412 anchors.fill: parent
413 anchors.topMargin: panel.panelHeight
414 sourceComponent: shell.mode != "shell" ? integratedGreeter :
415 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
416 onLoaded: {
417 item.objectName = "greeter"
418 }
419 }
421 Component {
422 id: integratedGreeter
423 Greeter {
425 hides: [launcher, panel.indicators]
426 tabletMode: shell.usageScenario != "phone"
427 launcherOffset: launcher.progress
428 forcedUnlock: tutorial.running
429 background: shell.background
431 // avoid overlapping with Launcher's edge drag area
432 // FIXME: Fix TouchRegistry & friends and remove this workaround
433 // Issue involves launcher's DDA getting disabled on a long
434 // left-edge drag
435 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
437 onSessionStarted: {
438 launcher.hide();
439 }
441 onTease: {
442 if (!tutorial.running) {
443 launcher.tease();
444 }
445 }
447 onEmergencyCall: startLockedApp("dialer-app")
448 }
449 }
451 Timer {
452 // See powerConnection for why this is useful
453 id: showGreeterDelayed
454 interval: 1
455 onTriggered: {
456 greeter.forceShow();
457 }
458 }
460 Connections {
461 id: callConnection
462 target: callManager
464 onHasCallsChanged: {
465 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
466 // We just received an incoming call while locked. The
467 // indicator will have already launched dialer-app for us, but
468 // there is a race between "hasCalls" changing and the dialer
469 // starting up. So in case we lose that race, we'll start/
470 // focus the dialer ourselves here too. Even if the indicator
471 // didn't launch the dialer for some reason (or maybe a call
472 // started via some other means), if an active call is
473 // happening, we want to be in the dialer.
474 startLockedApp("dialer-app")
475 }
476 }
477 }
479 Connections {
480 id: powerConnection
481 target: Powerd
483 onStatusChanged: {
484 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
485 !callManager.hasCalls && !tutorial.running) {
486 // We don't want to simply call greeter.showNow() here, because
487 // that will take too long. Qt will delay button event
488 // handling until the greeter is done loading and may think the
489 // user held down the power button the whole time, leading to a
490 // power dialog being shown. Instead, delay showing the
491 // greeter until we've finished handling the event. We could
492 // make the greeter load asynchronously instead, but that
493 // introduces a whole host of timing issues, especially with
494 // its animations. So this is simpler.
495 showGreeterDelayed.start();
496 }
497 }
498 }
500 function showHome() {
501 if (tutorial.running) {
502 return
503 }
505 greeter.notifyAboutToFocusApp("unity8-dash");
507 var animate = !lightDM.greeter.active && !stages.shown
508 dash.setCurrentScope(0, animate, false)
509 ApplicationManager.requestFocusApplication("unity8-dash")
510 }
512 function showDash() {
513 if (greeter.notifyShowingDashFromDrag()) {
514 launcher.fadeOut();
515 }
517 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
518 ApplicationManager.requestFocusApplication("unity8-dash")
519 launcher.fadeOut();
520 }
521 }
523 Item {
524 id: overlay
525 z: 10
527 anchors.fill: parent
529 Panel {
530 id: panel
531 objectName: "panel"
532 anchors.fill: parent //because this draws indicator menus
533 indicators {
534 hides: [launcher]
535 available: tutorial.panelEnabled
536 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
537 && (!greeter || !greeter.hasLockedApp)
538 contentEnabled: tutorial.panelContentEnabled
539 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
541 minimizedPanelHeight: units.gu(3)
542 expandedPanelHeight: units.gu(7)
544 indicatorsModel: Indicators.IndicatorsModel {
545 // tablet and phone both use the same profile
546 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
547 Component.onCompleted: load();
548 }
549 }
551 callHint {
552 greeterShown: greeter.shown
553 }
555 property bool topmostApplicationIsFullscreen:
556 ApplicationManager.focusedApplicationId &&
557 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
559 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
560 || greeter.hasLockedApp
561 }
563 Launcher {
564 id: launcher
565 objectName: "launcher"
567 readonly property bool dashSwipe: progress > 0
569 anchors.top: parent.top
570 anchors.topMargin: inverted ? 0 : panel.panelHeight
571 anchors.bottom: parent.bottom
572 width: parent.width
573 dragAreaWidth: shell.edgeSize
574 available: tutorial.launcherEnabled
575 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
576 && !greeter.hasLockedApp
577 inverted: shell.usageScenario !== "desktop"
578 shadeBackground: !tutorial.running
580 onShowDashHome: showHome()
581 onDash: showDash()
582 onDashSwipeChanged: {
583 if (dashSwipe) {
584 dash.setCurrentScope(0, false, true)
585 }
586 }
587 onLauncherApplicationSelected: {
588 if (!tutorial.running) {
589 greeter.notifyAboutToFocusApp(appId);
590 shell.activateApplication(appId)
591 }
592 }
593 onShownChanged: {
594 if (shown) {
595 panel.indicators.hide()
596 }
597 }
598 }
600 Wizard {
601 id: wizard
602 objectName: "wizard"
603 anchors.fill: parent
604 background: shell.background
606 function unlockWhenDoneWithWizard() {
607 if (!active) {
608 Connectivity.unlockAllModems();
609 }
610 }
612 Component.onCompleted: unlockWhenDoneWithWizard()
613 onActiveChanged: unlockWhenDoneWithWizard()
614 }
616 Rectangle {
617 id: modalNotificationBackground
619 visible: notifications.useModal
620 color: "#000000"
621 anchors.fill: parent
622 opacity: 0.9
624 MouseArea {
625 anchors.fill: parent
626 }
627 }
629 Notifications {
630 id: notifications
632 model: NotificationBackend.Model
633 margin: units.gu(1)
634 hasMouse: shell.hasMouse
636 y: topmostIsFullscreen ? 0 : panel.panelHeight
637 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
639 states: [
640 State {
641 name: "narrow"
642 when: overlay.width <= units.gu(60)
643 AnchorChanges {
644 target: notifications
645 anchors.left: parent.left
646 anchors.right: parent.right
647 }
648 },
649 State {
650 name: "wide"
651 when: overlay.width > units.gu(60)
652 AnchorChanges {
653 target: notifications
654 anchors.left: undefined
655 anchors.right: parent.right
656 }
657 PropertyChanges { target: notifications; width: units.gu(38) }
658 }
659 ]
660 }
661 }
663 Dialogs {
664 id: dialogs
665 objectName: "dialogs"
666 anchors.fill: parent
667 z: overlay.z + 10
668 usageScenario: shell.usageScenario
669 onPowerOffClicked: {
670 shutdownFadeOutRectangle.enabled = true;
671 shutdownFadeOutRectangle.visible = true;
672 shutdownFadeOut.start();
673 }
674 }
676 Connections {
677 target: SessionBroadcast
678 onShowHome: showHome()
679 }
681 Rectangle {
682 id: shutdownFadeOutRectangle
683 z: screenGrabber.z + 10
684 enabled: false
685 visible: false
686 color: "black"
687 anchors.fill: parent
688 opacity: 0.0
689 NumberAnimation on opacity {
690 id: shutdownFadeOut
691 from: 0.0
692 to: 1.0
693 onStopped: {
694 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
695 DBusUnitySessionService.shutdown();
696 }
697 }
698 }
699 }