on 30ee98b help sign in
unity8/qml/Shell.qml
709 lines 24 kB history raw
1/*
2 * Copyright (C) 2013-2016 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.4
18import QtQuick.Window 2.2
19import AccountsService 0.1
20import Unity.Application 0.1
21import Ubuntu.Components 1.3
22import Ubuntu.Components.Popups 1.3
23import Ubuntu.Gestures 0.1
24import Ubuntu.Telephony 0.1 as Telephony
25import Unity.Connectivity 0.1
26import Unity.Launcher 0.1
27import GlobalShortcut 1.0 // has to be before Utils, because of WindowKeysFilter
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
43import Cursor 1.0
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 property alias oskEnabled: inputMethod.enabled
60 function updateFocusedAppOrientation() {
61 applicationsDisplayLoader.item.updateFocusedAppOrientation();
62 }
63 function updateFocusedAppOrientationAnimated() {
64 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
65 }
66 property bool hasMouse: false
68 // to be read from outside
69 readonly property int mainAppWindowOrientationAngle:
70 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
72 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
73 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
74 && (!greeter || !greeter.animating)
76 readonly property bool showingGreeter: greeter && greeter.shown
78 property bool startingUp: true
79 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
81 property int supportedOrientations: {
82 if (startingUp) {
83 // Ensure we don't rotate during start up
84 return Qt.PrimaryOrientation;
85 } else if (greeter && greeter.shown) {
86 return Qt.PrimaryOrientation;
87 } else if (applicationsDisplayLoader.item) {
88 return shell.orientations.map(applicationsDisplayLoader.item.supportedOrientations);
89 } else {
90 // we just don't care
91 return Qt.PortraitOrientation
92 | Qt.LandscapeOrientation
93 | Qt.InvertedPortraitOrientation
94 | Qt.InvertedLandscapeOrientation;
95 }
96 }
98 // For autopilot consumption
99 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
101 // internal props from here onwards
102 readonly property var mainApp:
103 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105 // Disable everything while greeter is waiting, so that the user can't swipe
106 // the greeter or launcher until we know whether the session is locked.
107 enabled: greeter && !greeter.waiting
109 property real edgeSize: units.gu(2)
111 WallpaperResolver {
112 id: wallpaperResolver
113 width: shell.width
114 }
116 readonly property alias greeter: greeterLoader.item
118 function activateApplication(appId) {
119 if (ApplicationManager.findApplication(appId)) {
120 ApplicationManager.requestFocusApplication(appId);
121 } else {
122 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
123 : ApplicationManager.NoFlag;
124 ApplicationManager.startApplication(appId, execFlags);
125 }
126 }
128 function startLockedApp(app) {
129 if (greeter.locked) {
130 greeter.lockedApp = app;
131 }
132 shell.activateApplication(app);
133 }
135 Binding {
136 target: LauncherModel
137 property: "applicationManager"
138 value: ApplicationManager
139 }
141 Component.onCompleted: {
142 theme.name = "Ubuntu.Components.Themes.SuruGradient"
143 if (ApplicationManager.count > 0) {
144 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
145 }
146 finishStartUpTimer.start();
147 }
149 VolumeControl {
150 id: volumeControl
151 indicators: panel.indicators
152 }
154 DashCommunicator {
155 id: dash
156 objectName: "dashCommunicator"
157 }
159 PhysicalKeysMapper {
160 id: physicalKeysMapper
161 objectName: "physicalKeysMapper"
163 onPowerKeyLongPressed: dialogs.showPowerDialog();
164 onVolumeDownTriggered: volumeControl.volumeDown();
165 onVolumeUpTriggered: volumeControl.volumeUp();
166 onScreenshotTriggered: screenGrabber.capture();
167 }
169 GlobalShortcut {
170 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
171 }
173 WindowKeysFilter {
174 Keys.onPressed: physicalKeysMapper.onKeyPressed(event, currentEventTimestamp);
175 Keys.onReleased: physicalKeysMapper.onKeyReleased(event, currentEventTimestamp);
176 }
178 WindowInputMonitor {
179 onHomeKeyActivated: { launcher.fadeOut(); shell.showHome(); }
180 onTouchBegun: { cursor.opacity = 0; }
181 onTouchEnded: {
182 // move the (hidden) cursor to the last known touch position
183 var mappedCoords = mapFromItem(null, pos.x, pos.y);
184 cursor.x = mappedCoords.x;
185 cursor.y = mappedCoords.y;
186 }
187 }
189 Item {
190 id: stages
191 objectName: "stages"
192 width: parent.width
193 height: parent.height
195 Connections {
196 target: ApplicationManager
198 // This signal is also fired when we try to focus the current app
199 // again. We rely on this!
200 onFocusedApplicationIdChanged: {
201 var appId = ApplicationManager.focusedApplicationId;
203 if (tutorial.running && appId != "" && appId != "unity8-dash") {
204 // If this happens on first boot, we may be in edge
205 // tutorial or wizard while receiving a call. But a call
206 // is more important than wizard so just bail out of those.
207 tutorial.finish();
208 wizard.hide();
209 }
211 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
212 // If we are in the middle of a call, make dialer lockedApp and show it.
213 // This can happen if user backs out of dialer back to greeter, then
214 // launches dialer again.
215 greeter.lockedApp = appId;
216 }
217 greeter.notifyAppFocused(appId);
219 panel.indicators.hide();
220 }
222 onApplicationAdded: {
223 launcher.hide();
224 }
225 }
227 Loader {
228 id: applicationsDisplayLoader
229 objectName: "applicationsDisplayLoader"
230 anchors.fill: parent
232 // When we have a locked app, we only want to show that one app.
233 // FIXME: do this in a less traumatic way. We currently only allow
234 // locked apps in phone mode (see FIXME in Lockscreen component in
235 // this same file). When that changes, we need to do something
236 // nicer here. But this code is currently just to prevent a
237 // theoretical attack where user enters lockedApp mode, then makes
238 // the screen larger (maybe connects to monitor) and tries to enter
239 // tablet mode.
241 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
242 ? "phone"
243 : shell.usageScenario
244 source: {
245 if(shell.mode === "greeter") {
246 return "Stages/ShimStage.qml"
247 } else if (applicationsDisplayLoader.usageScenario === "phone") {
248 return "Stages/PhoneStage.qml";
249 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
250 return "Stages/TabletStage.qml";
251 } else {
252 return "Stages/DesktopStage.qml";
253 }
254 }
256 property bool interactive: tutorial.spreadEnabled
257 && (!greeter || !greeter.shown)
258 && panel.indicators.fullyClosed
259 && launcher.progress == 0
260 && !notifications.useModal
262 onInteractiveChanged: { if (interactive) { focus = true; } }
264 Binding {
265 target: applicationsDisplayLoader.item
266 property: "objectName"
267 value: "stage"
268 }
269 Binding {
270 target: applicationsDisplayLoader.item
271 property: "dragAreaWidth"
272 value: shell.edgeSize
273 }
274 Binding {
275 target: applicationsDisplayLoader.item
276 property: "maximizedAppTopMargin"
277 // Not just using panel.panelHeight as that changes depending on the focused app.
278 value: panel.indicators.minimizedPanelHeight
279 }
280 Binding {
281 target: applicationsDisplayLoader.item
282 property: "interactive"
283 value: applicationsDisplayLoader.interactive
284 }
285 Binding {
286 target: applicationsDisplayLoader.item
287 property: "spreadEnabled"
288 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
289 }
290 Binding {
291 target: applicationsDisplayLoader.item
292 property: "inverseProgress"
293 value: greeter && greeter.locked ? 0 : launcher.progress
294 }
295 Binding {
296 target: applicationsDisplayLoader.item
297 property: "shellOrientationAngle"
298 value: shell.orientationAngle
299 }
300 Binding {
301 target: applicationsDisplayLoader.item
302 property: "shellOrientation"
303 value: shell.orientation
304 }
305 Binding {
306 target: applicationsDisplayLoader.item
307 property: "orientations"
308 value: shell.orientations
309 }
310 Binding {
311 target: applicationsDisplayLoader.item
312 property: "background"
313 value: wallpaperResolver.background
314 }
315 Binding {
316 target: applicationsDisplayLoader.item
317 property: "nativeWidth"
318 value: shell.nativeWidth
319 }
320 Binding {
321 target: applicationsDisplayLoader.item
322 property: "nativeHeight"
323 value: shell.nativeHeight
324 }
325 Binding {
326 target: applicationsDisplayLoader.item
327 property: "beingResized"
328 value: shell.beingResized
329 }
330 Binding {
331 target: applicationsDisplayLoader.item
332 property: "keepDashRunning"
333 value: launcher.shown || launcher.dashSwipe
334 }
335 Binding {
336 target: applicationsDisplayLoader.item
337 property: "suspended"
338 value: greeter.shown
339 }
340 Binding {
341 target: applicationsDisplayLoader.item
342 property: "altTabPressed"
343 value: physicalKeysMapper.altTabPressed
344 }
345 }
347 Tutorial {
348 id: tutorial
349 objectName: "tutorial"
350 anchors.fill: parent
352 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
353 // we skip the tutorial on the Desktop to avoid using them. The
354 // Desktop doesn't use the same spread design anyway. The tutorial is
355 // all a bit of a placeholder on non-phone form factors right now.
356 // When the design team gives us more guidance, we can do something
357 // more clever here.
358 active: usageScenario != "desktop" && AccountsService.demoEdges
360 paused: LightDMService.greeter.active
361 launcher: launcher
362 panel: panel
363 edgeSize: shell.edgeSize
365 onFinished: {
366 AccountsService.demoEdges = false;
367 active = false; // for immediate response / if AS is having problems
368 }
369 }
370 }
372 InputMethod {
373 id: inputMethod
374 objectName: "inputMethod"
375 anchors { fill: parent; topMargin: panel.panelHeight }
376 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
377 }
379 Connections {
380 target: SessionManager
381 onSessionStopping: {
382 if (!session.parentSession && !session.application) {
383 // nothing is using it. delete it right away
384 session.release();
385 }
386 }
387 }
389 Loader {
390 id: greeterLoader
391 anchors.fill: parent
392 anchors.topMargin: panel.panelHeight
393 sourceComponent: shell.mode != "shell" ? integratedGreeter :
394 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
395 onLoaded: {
396 item.objectName = "greeter"
397 }
398 }
400 Component {
401 id: integratedGreeter
402 Greeter {
404 hides: [launcher, panel.indicators]
405 tabletMode: shell.usageScenario != "phone"
406 launcherOffset: launcher.progress
407 forcedUnlock: tutorial.running
408 background: wallpaperResolver.background
410 // avoid overlapping with Launcher's edge drag area
411 // FIXME: Fix TouchRegistry & friends and remove this workaround
412 // Issue involves launcher's DDA getting disabled on a long
413 // left-edge drag
414 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
416 onSessionStarted: {
417 launcher.hide();
418 }
420 onTease: {
421 if (!tutorial.running) {
422 launcher.tease();
423 }
424 }
426 onEmergencyCall: startLockedApp("dialer-app")
427 }
428 }
430 Timer {
431 // See powerConnection for why this is useful
432 id: showGreeterDelayed
433 interval: 1
434 onTriggered: {
435 greeter.forceShow();
436 }
437 }
439 Connections {
440 id: callConnection
441 target: callManager
443 onHasCallsChanged: {
444 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
445 // We just received an incoming call while locked. The
446 // indicator will have already launched dialer-app for us, but
447 // there is a race between "hasCalls" changing and the dialer
448 // starting up. So in case we lose that race, we'll start/
449 // focus the dialer ourselves here too. Even if the indicator
450 // didn't launch the dialer for some reason (or maybe a call
451 // started via some other means), if an active call is
452 // happening, we want to be in the dialer.
453 startLockedApp("dialer-app")
454 }
455 }
456 }
458 Connections {
459 id: powerConnection
460 target: Powerd
462 onStatusChanged: {
463 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
464 !callManager.hasCalls && !tutorial.running) {
465 // We don't want to simply call greeter.showNow() here, because
466 // that will take too long. Qt will delay button event
467 // handling until the greeter is done loading and may think the
468 // user held down the power button the whole time, leading to a
469 // power dialog being shown. Instead, delay showing the
470 // greeter until we've finished handling the event. We could
471 // make the greeter load asynchronously instead, but that
472 // introduces a whole host of timing issues, especially with
473 // its animations. So this is simpler.
474 showGreeterDelayed.start();
475 }
476 }
477 }
479 function showHome() {
480 if (tutorial.running) {
481 return
482 }
484 greeter.notifyAboutToFocusApp("unity8-dash");
486 var animate = !LightDMService.greeter.active && !stages.shown
487 dash.setCurrentScope(0, animate, false)
488 ApplicationManager.requestFocusApplication("unity8-dash")
489 }
491 function showDash() {
492 if (greeter.notifyShowingDashFromDrag()) {
493 launcher.fadeOut();
494 }
496 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
497 ApplicationManager.requestFocusApplication("unity8-dash")
498 launcher.fadeOut();
499 }
500 }
502 Item {
503 id: overlay
504 z: 10
506 anchors.fill: parent
508 Panel {
509 id: panel
510 objectName: "panel"
511 anchors.fill: parent //because this draws indicator menus
512 indicators {
513 hides: [launcher]
514 available: tutorial.panelEnabled
515 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
516 && (!greeter || !greeter.hasLockedApp)
517 contentEnabled: tutorial.panelContentEnabled
518 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
520 minimizedPanelHeight: units.gu(3)
521 expandedPanelHeight: units.gu(7)
523 indicatorsModel: Indicators.IndicatorsModel {
524 // tablet and phone both use the same profile
525 profile: "phone"
526 Component.onCompleted: load();
527 }
528 }
530 callHint {
531 greeterShown: greeter.shown
532 }
534 readonly property bool topmostApplicationIsFullscreen:
535 ApplicationManager.focusedApplicationId &&
536 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
538 fullscreenMode: (topmostApplicationIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0)
539 || greeter.hasLockedApp
540 locked: greeter && greeter.active
541 }
543 Launcher {
544 id: launcher
545 objectName: "launcher"
547 readonly property bool dashSwipe: progress > 0
549 anchors.top: parent.top
550 anchors.topMargin: inverted ? 0 : panel.panelHeight
551 anchors.bottom: parent.bottom
552 width: parent.width
553 dragAreaWidth: shell.edgeSize
554 available: tutorial.launcherEnabled
555 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
556 && !greeter.hasLockedApp
557 inverted: shell.usageScenario !== "desktop"
558 shadeBackground: !tutorial.running
560 onShowDashHome: showHome()
561 onDash: showDash()
562 onDashSwipeChanged: {
563 if (dashSwipe) {
564 dash.setCurrentScope(0, false, true)
565 }
566 }
567 onLauncherApplicationSelected: {
568 if (!tutorial.running) {
569 greeter.notifyAboutToFocusApp(appId);
570 shell.activateApplication(appId)
571 }
572 }
573 onShownChanged: {
574 if (shown) {
575 panel.indicators.hide()
576 }
577 }
578 }
580 Wizard {
581 id: wizard
582 objectName: "wizard"
583 anchors.fill: parent
584 deferred: shell.mode === "greeter"
585 background: wallpaperResolver.background
587 function unlockWhenDoneWithWizard() {
588 if (!active) {
589 Connectivity.unlockAllModems();
590 }
591 }
593 Component.onCompleted: unlockWhenDoneWithWizard()
594 onActiveChanged: unlockWhenDoneWithWizard()
595 }
597 Rectangle {
598 id: modalNotificationBackground
600 visible: notifications.useModal
601 color: "#000000"
602 anchors.fill: parent
603 opacity: 0.9
605 MouseArea {
606 anchors.fill: parent
607 }
608 }
610 Notifications {
611 id: notifications
613 model: NotificationBackend.Model
614 margin: units.gu(1)
615 hasMouse: shell.hasMouse
616 background: wallpaperResolver.background
618 y: topmostIsFullscreen ? 0 : panel.panelHeight
619 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
621 states: [
622 State {
623 name: "narrow"
624 when: overlay.width <= units.gu(60)
625 AnchorChanges {
626 target: notifications
627 anchors.left: parent.left
628 anchors.right: parent.right
629 }
630 },
631 State {
632 name: "wide"
633 when: overlay.width > units.gu(60)
634 AnchorChanges {
635 target: notifications
636 anchors.left: undefined
637 anchors.right: parent.right
638 }
639 PropertyChanges { target: notifications; width: units.gu(38) }
640 }
641 ]
642 }
643 }
645 Dialogs {
646 id: dialogs
647 objectName: "dialogs"
648 anchors.fill: parent
649 z: overlay.z + 10
650 usageScenario: shell.usageScenario
651 onPowerOffClicked: {
652 shutdownFadeOutRectangle.enabled = true;
653 shutdownFadeOutRectangle.visible = true;
654 shutdownFadeOut.start();
655 }
656 }
658 Connections {
659 target: SessionBroadcast
660 onShowHome: showHome()
661 }
663 ScreenGrabber {
664 id: screenGrabber
665 rotationAngle: -shell.orientationAngle
666 z: dialogs.z + 10
667 }
669 Cursor {
670 id: cursor
671 visible: shell.hasMouse
672 z: screenGrabber.z + 1
674 onPushedLeftBoundary: {
675 if (buttons === Qt.NoButton) {
676 launcher.pushEdge(amount);
677 }
678 }
680 onPushedRightBoundary: {
681 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
682 && applicationsDisplayLoader.item.pushRightEdge) {
683 applicationsDisplayLoader.item.pushRightEdge(amount);
684 }
685 }
687 onMouseMoved: { cursor.opacity = 1; }
688 }
690 Rectangle {
691 id: shutdownFadeOutRectangle
692 z: cursor.z + 1
693 enabled: false
694 visible: false
695 color: "black"
696 anchors.fill: parent
697 opacity: 0.0
698 NumberAnimation on opacity {
699 id: shutdownFadeOut
700 from: 0.0
701 to: 1.0
702 onStopped: {
703 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
704 DBusUnitySessionService.shutdown();
705 }
706 }
707 }
708 }