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