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