on 3df724b help sign in
unity8/qml/Shell.qml
740 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 WindowInputFilter
28import GSettings 1.0
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
44import Cursor 1.0
47Item {
48 id: shell
50 // to be set from outside
51 property int orientationAngle: 0
52 property int orientation
53 property Orientations orientations
54 property real nativeWidth
55 property real nativeHeight
56 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
57 property bool beingResized
58 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
59 property string mode: "full-greeter"
60 property alias oskEnabled: inputMethod.enabled
61 function updateFocusedAppOrientation() {
62 applicationsDisplayLoader.item.updateFocusedAppOrientation();
63 }
64 function updateFocusedAppOrientationAnimated() {
65 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
66 }
67 property bool hasMouse: false
69 // to be read from outside
70 readonly property int mainAppWindowOrientationAngle:
71 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
73 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
74 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
75 && (!greeter || !greeter.animating)
77 readonly property bool showingGreeter: greeter && greeter.shown
79 property bool startingUp: true
80 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
82 property int supportedOrientations: {
83 if (startingUp) {
84 // Ensure we don't rotate during start up
85 return Qt.PrimaryOrientation;
86 } else if (greeter && greeter.shown) {
87 return Qt.PrimaryOrientation;
88 } else if (applicationsDisplayLoader.item) {
89 return shell.orientations.map(applicationsDisplayLoader.item.supportedOrientations);
90 } else {
91 // we just don't care
92 return Qt.PortraitOrientation
93 | Qt.LandscapeOrientation
94 | Qt.InvertedPortraitOrientation
95 | Qt.InvertedLandscapeOrientation;
96 }
97 }
99 // For autopilot consumption
100 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
102 // internal props from here onwards
103 readonly property var mainApp:
104 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
106 // Disable everything while greeter is waiting, so that the user can't swipe
107 // the greeter or launcher until we know whether the session is locked.
108 enabled: greeter && !greeter.waiting
110 property real edgeSize: units.gu(2)
112 WallpaperResolver {
113 id: wallpaperResolver
114 width: shell.width
115 }
117 readonly property alias greeter: greeterLoader.item
119 function activateApplication(appId) {
120 if (ApplicationManager.findApplication(appId)) {
121 ApplicationManager.requestFocusApplication(appId);
122 } else {
123 ApplicationManager.startApplication(appId);
124 }
125 }
127 function startLockedApp(app) {
128 if (greeter.locked) {
129 greeter.lockedApp = app;
130 }
131 shell.activateApplication(app);
132 }
134 Binding {
135 target: LauncherModel
136 property: "applicationManager"
137 value: ApplicationManager
138 }
140 Component.onCompleted: {
141 theme.name = "Ubuntu.Components.Themes.SuruDark"
142 if (ApplicationManager.count > 0) {
143 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
144 }
145 finishStartUpTimer.start();
146 }
148 LightDM{id: lightDM} // Provide backend access
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 WindowInputFilter
171 }
173 WindowInputFilter {
174 id: inputFilter
175 Keys.onPressed: physicalKeysMapper.onKeyPressed(event, lastInputTimestamp);
176 Keys.onReleased: physicalKeysMapper.onKeyReleased(event, lastInputTimestamp);
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 GSettings {
191 id: settings
192 schema.id: "com.canonical.Unity8"
193 }
195 Item {
196 id: stages
197 objectName: "stages"
198 width: parent.width
199 height: parent.height
201 Connections {
202 target: ApplicationManager
204 // This signal is also fired when we try to focus the current app
205 // again. We rely on this!
206 onFocusedApplicationIdChanged: {
207 var appId = ApplicationManager.focusedApplicationId;
209 if (wizard.active && appId != "" && appId != "unity8-dash") {
210 // If this happens on first boot, we may be in edge
211 // tutorial or wizard while receiving a call. But a call
212 // is more important than wizard so just bail out of those.
213 tutorial.finish();
214 wizard.hide();
215 }
217 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
218 // If we are in the middle of a call, make dialer lockedApp and show it.
219 // This can happen if user backs out of dialer back to greeter, then
220 // launches dialer again.
221 greeter.lockedApp = appId;
222 }
223 greeter.notifyAppFocused(appId);
225 panel.indicators.hide();
226 }
228 onApplicationAdded: {
229 launcher.hide();
230 }
231 }
233 Loader {
234 id: applicationsDisplayLoader
235 objectName: "applicationsDisplayLoader"
236 anchors.fill: parent
238 // When we have a locked app, we only want to show that one app.
239 // FIXME: do this in a less traumatic way. We currently only allow
240 // locked apps in phone mode (see FIXME in Lockscreen component in
241 // this same file). When that changes, we need to do something
242 // nicer here. But this code is currently just to prevent a
243 // theoretical attack where user enters lockedApp mode, then makes
244 // the screen larger (maybe connects to monitor) and tries to enter
245 // tablet mode.
247 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
248 ? "phone"
249 : shell.usageScenario
250 readonly property string qmlComponent: {
251 if(shell.mode === "greeter") {
252 return "Stages/ShimStage.qml"
253 } else if (applicationsDisplayLoader.usageScenario === "phone") {
254 return "Stages/PhoneStage.qml";
255 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
256 return "Stages/TabletStage.qml";
257 } else {
258 return "Stages/DesktopStage.qml";
259 }
260 }
261 onQmlComponentChanged: {
262 if (item) item.stageAboutToBeUnloaded();
263 source = qmlComponent;
264 }
266 property bool interactive: (!greeter || !greeter.shown)
267 && panel.indicators.fullyClosed
268 && launcher.progress == 0
269 && !notifications.useModal
271 onInteractiveChanged: { if (interactive) { focus = true; } }
273 Binding {
274 target: applicationsDisplayLoader.item
275 property: "objectName"
276 value: "stage"
277 }
278 Binding {
279 target: applicationsDisplayLoader.item
280 property: "dragAreaWidth"
281 value: shell.edgeSize
282 }
283 Binding {
284 target: applicationsDisplayLoader.item
285 property: "maximizedAppTopMargin"
286 // Not just using panel.panelHeight as that changes depending on the focused app.
287 value: panel.indicators.minimizedPanelHeight
288 }
289 Binding {
290 target: applicationsDisplayLoader.item
291 property: "interactive"
292 value: applicationsDisplayLoader.interactive
293 }
294 Binding {
295 target: applicationsDisplayLoader.item
296 property: "spreadEnabled"
297 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
298 }
299 Binding {
300 target: applicationsDisplayLoader.item
301 property: "inverseProgress"
302 value: greeter && greeter.locked ? 0 : launcher.progress
303 }
304 Binding {
305 target: applicationsDisplayLoader.item
306 property: "shellOrientationAngle"
307 value: shell.orientationAngle
308 }
309 Binding {
310 target: applicationsDisplayLoader.item
311 property: "shellOrientation"
312 value: shell.orientation
313 }
314 Binding {
315 target: applicationsDisplayLoader.item
316 property: "orientations"
317 value: shell.orientations
318 }
319 Binding {
320 target: applicationsDisplayLoader.item
321 property: "background"
322 value: wallpaperResolver.background
323 }
324 Binding {
325 target: applicationsDisplayLoader.item
326 property: "nativeWidth"
327 value: shell.nativeWidth
328 }
329 Binding {
330 target: applicationsDisplayLoader.item
331 property: "nativeHeight"
332 value: shell.nativeHeight
333 }
334 Binding {
335 target: applicationsDisplayLoader.item
336 property: "beingResized"
337 value: shell.beingResized
338 }
339 Binding {
340 target: applicationsDisplayLoader.item
341 property: "keepDashRunning"
342 value: launcher.shown || launcher.dashSwipe
343 }
344 Binding {
345 target: applicationsDisplayLoader.item
346 property: "suspended"
347 value: greeter.shown
348 }
349 Binding {
350 target: applicationsDisplayLoader.item
351 property: "altTabPressed"
352 value: physicalKeysMapper.altTabPressed
353 }
354 Binding {
355 target: applicationsDisplayLoader.item
356 property: "leftMargin"
357 value: shell.usageScenario == "desktop" && !settings.autohideLauncher ? launcher.panelWidth: 0
358 }
359 }
360 }
362 InputMethod {
363 id: inputMethod
364 objectName: "inputMethod"
365 anchors {
366 fill: parent
367 topMargin: panel.panelHeight
368 leftMargin: launcher.lockedVisible ? launcher.panelWidth : 0
369 }
370 z: notifications.useModal || panel.indicators.shown || wizard.active || tutorial.running ? overlay.z + 1 : overlay.z - 1
371 }
373 Connections {
374 target: SessionManager
375 onSessionStopping: {
376 if (!session.parentSession && !session.application) {
377 // nothing is using it. delete it right away
378 session.release();
379 }
380 }
381 }
383 Loader {
384 id: greeterLoader
385 anchors.fill: parent
386 anchors.topMargin: panel.panelHeight
387 sourceComponent: shell.mode != "shell" ? integratedGreeter :
388 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
389 onLoaded: {
390 item.objectName = "greeter"
391 }
392 }
394 Component {
395 id: integratedGreeter
396 Greeter {
398 hides: [launcher, panel.indicators]
399 tabletMode: shell.usageScenario != "phone"
400 launcherOffset: launcher.progress
401 forcedUnlock: wizard.active
402 background: wallpaperResolver.background
404 // avoid overlapping with Launcher's edge drag area
405 // FIXME: Fix TouchRegistry & friends and remove this workaround
406 // Issue involves launcher's DDA getting disabled on a long
407 // left-edge drag
408 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
410 onSessionStarted: {
411 launcher.hide();
412 }
414 onTease: {
415 if (!tutorial.running) {
416 launcher.tease();
417 }
418 }
420 onEmergencyCall: startLockedApp("dialer-app")
421 }
422 }
424 Timer {
425 // See powerConnection for why this is useful
426 id: showGreeterDelayed
427 interval: 1
428 onTriggered: {
429 greeter.forceShow();
430 }
431 }
433 Connections {
434 id: callConnection
435 target: callManager
437 onHasCallsChanged: {
438 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
439 // We just received an incoming call while locked. The
440 // indicator will have already launched dialer-app for us, but
441 // there is a race between "hasCalls" changing and the dialer
442 // starting up. So in case we lose that race, we'll start/
443 // focus the dialer ourselves here too. Even if the indicator
444 // didn't launch the dialer for some reason (or maybe a call
445 // started via some other means), if an active call is
446 // happening, we want to be in the dialer.
447 startLockedApp("dialer-app")
448 }
449 }
450 }
452 Connections {
453 id: powerConnection
454 target: Powerd
456 onStatusChanged: {
457 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
458 !callManager.hasCalls && !wizard.active) {
459 // We don't want to simply call greeter.showNow() here, because
460 // that will take too long. Qt will delay button event
461 // handling until the greeter is done loading and may think the
462 // user held down the power button the whole time, leading to a
463 // power dialog being shown. Instead, delay showing the
464 // greeter until we've finished handling the event. We could
465 // make the greeter load asynchronously instead, but that
466 // introduces a whole host of timing issues, especially with
467 // its animations. So this is simpler.
468 showGreeterDelayed.start();
469 }
470 }
471 }
473 function showHome() {
474 greeter.notifyAboutToFocusApp("unity8-dash");
476 var animate = !lightDM.greeter.active && !stages.shown
477 dash.setCurrentScope(0, animate, false)
478 ApplicationManager.requestFocusApplication("unity8-dash")
479 }
481 function showDash() {
482 if (greeter.notifyShowingDashFromDrag()) {
483 launcher.fadeOut();
484 }
486 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
487 ApplicationManager.requestFocusApplication("unity8-dash")
488 launcher.fadeOut();
489 }
490 }
492 Item {
493 id: overlay
494 z: 10
496 anchors.fill: parent
498 Panel {
499 id: panel
500 objectName: "panel"
501 anchors.fill: parent //because this draws indicator menus
502 indicators {
503 hides: [launcher]
504 available: tutorial.panelEnabled
505 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
506 && (!greeter || !greeter.hasLockedApp)
507 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
509 minimizedPanelHeight: units.gu(3)
510 expandedPanelHeight: units.gu(7)
512 indicatorsModel: Indicators.IndicatorsModel {
513 // tablet and phone both use the same profile
514 profile: "phone"
515 Component.onCompleted: load();
516 }
517 }
519 callHint {
520 greeterShown: greeter.shown
521 }
523 readonly property bool topmostApplicationIsFullscreen: mainApp && mainApp.fullscreen
525 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
526 || greeter.hasLockedApp
527 locked: greeter && greeter.active
528 }
530 Launcher {
531 id: launcher
532 objectName: "launcher"
534 readonly property bool dashSwipe: progress > 0
536 anchors.top: parent.top
537 anchors.topMargin: inverted ? 0 : panel.panelHeight
538 anchors.bottom: parent.bottom
539 width: parent.width
540 dragAreaWidth: shell.edgeSize
541 available: tutorial.launcherEnabled
542 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
543 && !greeter.hasLockedApp
544 inverted: shell.usageScenario !== "desktop"
545 superPressed: physicalKeysMapper.superPressed
546 superTabPressed: physicalKeysMapper.superTabPressed
547 panelWidth: units.gu(settings.launcherWidth)
548 lockedVisible: shell.usageScenario == "desktop" && !settings.autohideLauncher && !panel.fullscreenMode
550 onShowDashHome: showHome()
551 onDash: showDash()
552 onDashSwipeChanged: {
553 if (dashSwipe) {
554 dash.setCurrentScope(0, false, true)
555 }
556 }
557 onLauncherApplicationSelected: {
558 greeter.notifyAboutToFocusApp(appId);
559 shell.activateApplication(appId);
560 }
561 onShownChanged: {
562 if (shown) {
563 panel.indicators.hide()
564 }
565 }
566 onFocusChanged: {
567 if (!focus) {
568 applicationsDisplayLoader.focus = true;
569 }
570 }
572 GlobalShortcut {
573 shortcut: Qt.AltModifier | Qt.Key_F1
574 onTriggered: {
575 launcher.openForKeyboardNavigation();
576 }
577 }
578 GlobalShortcut {
579 shortcut: Qt.MetaModifier | Qt.Key_0
580 onTriggered: {
581 if (LauncherModel.get(9)) {
582 activateApplication(LauncherModel.get(9).appId);
583 }
584 }
585 }
586 Repeater {
587 model: 9
588 GlobalShortcut {
589 shortcut: Qt.MetaModifier | (Qt.Key_1 + index)
590 onTriggered: {
591 if (LauncherModel.get(index)) {
592 activateApplication(LauncherModel.get(index).appId);
593 }
594 }
595 }
596 }
597 }
599 Tutorial {
600 id: tutorial
601 objectName: "tutorial"
602 anchors.fill: parent
604 paused: callManager.hasCalls || greeter.shown
605 keyboardVisible: inputMethod.state === "shown"
606 usageScenario: shell.usageScenario
607 lastInputTimestamp: inputFilter.lastInputTimestamp
608 launcher: launcher
609 panel: panel
610 stage: applicationsDisplayLoader.item
611 }
613 Wizard {
614 id: wizard
615 objectName: "wizard"
616 anchors.fill: parent
618 function unlockWhenDoneWithWizard() {
619 if (!active) {
620 Connectivity.unlockAllModems();
621 }
622 }
624 Component.onCompleted: unlockWhenDoneWithWizard()
625 onActiveChanged: unlockWhenDoneWithWizard()
626 }
628 Rectangle {
629 id: modalNotificationBackground
631 visible: notifications.useModal
632 color: "#000000"
633 anchors.fill: parent
634 opacity: 0.9
636 MouseArea {
637 anchors.fill: parent
638 }
639 }
641 Notifications {
642 id: notifications
644 model: NotificationBackend.Model
645 margin: units.gu(1)
646 hasMouse: shell.hasMouse
647 background: wallpaperResolver.background
649 y: topmostIsFullscreen ? 0 : panel.panelHeight
650 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
652 states: [
653 State {
654 name: "narrow"
655 when: overlay.width <= units.gu(60)
656 AnchorChanges {
657 target: notifications
658 anchors.left: parent.left
659 anchors.right: parent.right
660 }
661 },
662 State {
663 name: "wide"
664 when: overlay.width > units.gu(60)
665 AnchorChanges {
666 target: notifications
667 anchors.left: undefined
668 anchors.right: parent.right
669 }
670 PropertyChanges { target: notifications; width: units.gu(38) }
671 }
672 ]
673 }
674 }
676 Dialogs {
677 id: dialogs
678 objectName: "dialogs"
679 anchors.fill: parent
680 z: overlay.z + 10
681 usageScenario: shell.usageScenario
682 onPowerOffClicked: {
683 shutdownFadeOutRectangle.enabled = true;
684 shutdownFadeOutRectangle.visible = true;
685 shutdownFadeOut.start();
686 }
687 }
689 Connections {
690 target: SessionBroadcast
691 onShowHome: showHome()
692 }
694 ScreenGrabber {
695 id: screenGrabber
696 rotationAngle: -shell.orientationAngle
697 z: dialogs.z + 10
698 }
700 Cursor {
701 id: cursor
702 visible: shell.hasMouse
703 z: screenGrabber.z + 1
705 onPushedLeftBoundary: {
706 if (buttons === Qt.NoButton) {
707 launcher.pushEdge(amount);
708 }
709 }
711 onPushedRightBoundary: {
712 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
713 && applicationsDisplayLoader.item.pushRightEdge) {
714 applicationsDisplayLoader.item.pushRightEdge(amount);
715 }
716 }
718 onMouseMoved: { cursor.opacity = 1; }
719 }
721 Rectangle {
722 id: shutdownFadeOutRectangle
723 z: cursor.z + 1
724 enabled: false
725 visible: false
726 color: "black"
727 anchors.fill: parent
728 opacity: 0.0
729 NumberAnimation on opacity {
730 id: shutdownFadeOut
731 from: 0.0
732 to: 1.0
733 onStopped: {
734 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
735 DBusUnitySessionService.shutdown();
736 }
737 }
738 }
739 }