on 3d53e68 help sign in
unity8/qml/Shell.qml
691 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 Unity.Application 0.1
21import Ubuntu.Components 0.1
22import Ubuntu.Components.Popups 1.0
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 int primaryOrientation
53 property int nativeOrientation
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 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 (mainApp) {
88 return mainApp.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);
176 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
177 }
179 HomeKeyWatcher {
180 onActivated: { launcher.fadeOut(); shell.showHome(); }
181 }
183 Item {
184 id: stages
185 objectName: "stages"
186 width: parent.width
187 height: parent.height
189 Connections {
190 target: ApplicationManager
192 // This signal is also fired when we try to focus the current app
193 // again. We rely on this!
194 onFocusedApplicationIdChanged: {
195 var appId = ApplicationManager.focusedApplicationId;
197 if (tutorial.running && appId != "" && appId != "unity8-dash") {
198 // If this happens on first boot, we may be in edge
199 // tutorial or wizard while receiving a call. But a call
200 // is more important than wizard so just bail out of those.
201 tutorial.finish();
202 wizard.hide();
203 }
205 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
206 // If we are in the middle of a call, make dialer lockedApp and show it.
207 // This can happen if user backs out of dialer back to greeter, then
208 // launches dialer again.
209 greeter.lockedApp = appId;
210 }
211 greeter.notifyAppFocused(appId);
213 panel.indicators.hide();
214 }
216 onApplicationAdded: {
217 launcher.hide();
218 }
219 }
221 Loader {
222 id: applicationsDisplayLoader
223 objectName: "applicationsDisplayLoader"
224 anchors.fill: parent
226 // When we have a locked app, we only want to show that one app.
227 // FIXME: do this in a less traumatic way. We currently only allow
228 // locked apps in phone mode (see FIXME in Lockscreen component in
229 // this same file). When that changes, we need to do something
230 // nicer here. But this code is currently just to prevent a
231 // theoretical attack where user enters lockedApp mode, then makes
232 // the screen larger (maybe connects to monitor) and tries to enter
233 // tablet mode.
235 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
236 ? "phone"
237 : shell.usageScenario
238 source: {
239 if(shell.mode === "greeter") {
240 return "Stages/ShimStage.qml"
241 } else if (applicationsDisplayLoader.usageScenario === "phone") {
242 return "Stages/PhoneStage.qml";
243 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
244 return "Stages/TabletStage.qml";
245 } else {
246 return "Stages/DesktopStage.qml";
247 }
248 }
250 property bool interactive: tutorial.spreadEnabled
251 && (!greeter || !greeter.shown)
252 && panel.indicators.fullyClosed
253 && launcher.progress == 0
254 && !notifications.useModal
256 onInteractiveChanged: { if (interactive) { focus = true; } }
258 Binding {
259 target: applicationsDisplayLoader.item
260 property: "objectName"
261 value: "stage"
262 }
263 Binding {
264 target: applicationsDisplayLoader.item
265 property: "dragAreaWidth"
266 value: shell.edgeSize
267 }
268 Binding {
269 target: applicationsDisplayLoader.item
270 property: "maximizedAppTopMargin"
271 // Not just using panel.panelHeight as that changes depending on the focused app.
272 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
273 }
274 Binding {
275 target: applicationsDisplayLoader.item
276 property: "interactive"
277 value: applicationsDisplayLoader.interactive
278 }
279 Binding {
280 target: applicationsDisplayLoader.item
281 property: "spreadEnabled"
282 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
283 }
284 Binding {
285 target: applicationsDisplayLoader.item
286 property: "inverseProgress"
287 value: greeter && greeter.locked ? 0 : launcher.progress
288 }
289 Binding {
290 target: applicationsDisplayLoader.item
291 property: "shellOrientationAngle"
292 value: shell.orientationAngle
293 }
294 Binding {
295 target: applicationsDisplayLoader.item
296 property: "shellOrientation"
297 value: shell.orientation
298 }
299 Binding {
300 target: applicationsDisplayLoader.item
301 property: "background"
302 value: wallpaperResolver.background
303 }
304 Binding {
305 target: applicationsDisplayLoader.item
306 property: "shellPrimaryOrientation"
307 value: shell.primaryOrientation
308 }
309 Binding {
310 target: applicationsDisplayLoader.item
311 property: "nativeOrientation"
312 value: shell.nativeOrientation
313 }
314 Binding {
315 target: applicationsDisplayLoader.item
316 property: "nativeWidth"
317 value: shell.nativeWidth
318 }
319 Binding {
320 target: applicationsDisplayLoader.item
321 property: "nativeHeight"
322 value: shell.nativeHeight
323 }
324 Binding {
325 target: applicationsDisplayLoader.item
326 property: "beingResized"
327 value: shell.beingResized
328 }
329 Binding {
330 target: applicationsDisplayLoader.item
331 property: "keepDashRunning"
332 value: launcher.shown || launcher.dashSwipe
333 }
334 Binding {
335 target: applicationsDisplayLoader.item
336 property: "suspended"
337 value: greeter.shown
338 }
339 Binding {
340 target: applicationsDisplayLoader.item
341 property: "altTabPressed"
342 value: physicalKeysMapper.altTabPressed
343 }
344 }
346 Tutorial {
347 id: tutorial
348 objectName: "tutorial"
349 anchors.fill: parent
351 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
352 // we skip the tutorial on the Desktop to avoid using them. The
353 // Desktop doesn't use the same spread design anyway. The tutorial is
354 // all a bit of a placeholder on non-phone form factors right now.
355 // When the design team gives us more guidance, we can do something
356 // more clever here.
357 active: usageScenario != "desktop" && AccountsService.demoEdges
359 paused: lightDM.greeter.active
360 launcher: launcher
361 panel: panel
362 edgeSize: shell.edgeSize
364 onFinished: {
365 AccountsService.demoEdges = false;
366 active = false; // for immediate response / if AS is having problems
367 }
368 }
369 }
371 InputMethod {
372 id: inputMethod
373 objectName: "inputMethod"
374 anchors { fill: parent; topMargin: panel.panelHeight }
375 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
376 }
378 Connections {
379 target: SessionManager
380 onSessionStopping: {
381 if (!session.parentSession && !session.application) {
382 // nothing is using it. delete it right away
383 session.release();
384 }
385 }
386 }
388 Loader {
389 id: greeterLoader
390 anchors.fill: parent
391 anchors.topMargin: panel.panelHeight
392 sourceComponent: shell.mode != "shell" ? integratedGreeter :
393 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
394 onLoaded: {
395 item.objectName = "greeter"
396 }
397 }
399 Component {
400 id: integratedGreeter
401 Greeter {
403 hides: [launcher, panel.indicators]
404 tabletMode: shell.usageScenario != "phone"
405 launcherOffset: launcher.progress
406 forcedUnlock: tutorial.running
407 background: wallpaperResolver.background
409 // avoid overlapping with Launcher's edge drag area
410 // FIXME: Fix TouchRegistry & friends and remove this workaround
411 // Issue involves launcher's DDA getting disabled on a long
412 // left-edge drag
413 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
415 onSessionStarted: {
416 launcher.hide();
417 }
419 onTease: {
420 if (!tutorial.running) {
421 launcher.tease();
422 }
423 }
425 onEmergencyCall: startLockedApp("dialer-app")
426 }
427 }
429 Timer {
430 // See powerConnection for why this is useful
431 id: showGreeterDelayed
432 interval: 1
433 onTriggered: {
434 greeter.forceShow();
435 }
436 }
438 Connections {
439 id: callConnection
440 target: callManager
442 onHasCallsChanged: {
443 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
444 // We just received an incoming call while locked. The
445 // indicator will have already launched dialer-app for us, but
446 // there is a race between "hasCalls" changing and the dialer
447 // starting up. So in case we lose that race, we'll start/
448 // focus the dialer ourselves here too. Even if the indicator
449 // didn't launch the dialer for some reason (or maybe a call
450 // started via some other means), if an active call is
451 // happening, we want to be in the dialer.
452 startLockedApp("dialer-app")
453 }
454 }
455 }
457 Connections {
458 id: powerConnection
459 target: Powerd
461 onStatusChanged: {
462 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
463 !callManager.hasCalls && !tutorial.running) {
464 // We don't want to simply call greeter.showNow() here, because
465 // that will take too long. Qt will delay button event
466 // handling until the greeter is done loading and may think the
467 // user held down the power button the whole time, leading to a
468 // power dialog being shown. Instead, delay showing the
469 // greeter until we've finished handling the event. We could
470 // make the greeter load asynchronously instead, but that
471 // introduces a whole host of timing issues, especially with
472 // its animations. So this is simpler.
473 showGreeterDelayed.start();
474 }
475 }
476 }
478 function showHome() {
479 if (tutorial.running) {
480 return
481 }
483 greeter.notifyAboutToFocusApp("unity8-dash");
485 var animate = !lightDM.greeter.active && !stages.shown
486 dash.setCurrentScope(0, animate, false)
487 ApplicationManager.requestFocusApplication("unity8-dash")
488 }
490 function showDash() {
491 if (greeter.notifyShowingDashFromDrag()) {
492 launcher.fadeOut();
493 }
495 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
496 ApplicationManager.requestFocusApplication("unity8-dash")
497 launcher.fadeOut();
498 }
499 }
501 Item {
502 id: overlay
503 z: 10
505 anchors.fill: parent
507 Panel {
508 id: panel
509 objectName: "panel"
510 anchors.fill: parent //because this draws indicator menus
511 indicators {
512 hides: [launcher]
513 available: tutorial.panelEnabled
514 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
515 && (!greeter || !greeter.hasLockedApp)
516 contentEnabled: tutorial.panelContentEnabled
517 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
519 minimizedPanelHeight: units.gu(3)
520 expandedPanelHeight: units.gu(7)
522 indicatorsModel: Indicators.IndicatorsModel {
523 // tablet and phone both use the same profile
524 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
525 Component.onCompleted: load();
526 }
527 }
529 callHint {
530 greeterShown: greeter.shown
531 }
533 property bool topmostApplicationIsFullscreen:
534 ApplicationManager.focusedApplicationId &&
535 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
537 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
538 || greeter.hasLockedApp
539 }
541 Launcher {
542 id: launcher
543 objectName: "launcher"
545 readonly property bool dashSwipe: progress > 0
547 anchors.top: parent.top
548 anchors.topMargin: inverted ? 0 : panel.panelHeight
549 anchors.bottom: parent.bottom
550 width: parent.width
551 dragAreaWidth: shell.edgeSize
552 available: tutorial.launcherEnabled
553 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
554 && !greeter.hasLockedApp
555 inverted: shell.usageScenario !== "desktop"
556 shadeBackground: !tutorial.running
558 onShowDashHome: showHome()
559 onDash: showDash()
560 onDashSwipeChanged: {
561 if (dashSwipe) {
562 dash.setCurrentScope(0, false, true)
563 }
564 }
565 onLauncherApplicationSelected: {
566 if (!tutorial.running) {
567 greeter.notifyAboutToFocusApp(appId);
568 shell.activateApplication(appId)
569 }
570 }
571 onShownChanged: {
572 if (shown) {
573 panel.indicators.hide()
574 }
575 }
576 }
578 Wizard {
579 id: wizard
580 objectName: "wizard"
581 anchors.fill: parent
582 background: wallpaperResolver.background
584 function unlockWhenDoneWithWizard() {
585 if (!active) {
586 Connectivity.unlockAllModems();
587 }
588 }
590 Component.onCompleted: unlockWhenDoneWithWizard()
591 onActiveChanged: unlockWhenDoneWithWizard()
592 }
594 Rectangle {
595 id: modalNotificationBackground
597 visible: notifications.useModal
598 color: "#000000"
599 anchors.fill: parent
600 opacity: 0.9
602 MouseArea {
603 anchors.fill: parent
604 }
605 }
607 Notifications {
608 id: notifications
610 model: NotificationBackend.Model
611 margin: units.gu(1)
612 hasMouse: shell.hasMouse
613 background: wallpaperResolver.background
615 y: topmostIsFullscreen ? 0 : panel.panelHeight
616 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
618 states: [
619 State {
620 name: "narrow"
621 when: overlay.width <= units.gu(60)
622 AnchorChanges {
623 target: notifications
624 anchors.left: parent.left
625 anchors.right: parent.right
626 }
627 },
628 State {
629 name: "wide"
630 when: overlay.width > units.gu(60)
631 AnchorChanges {
632 target: notifications
633 anchors.left: undefined
634 anchors.right: parent.right
635 }
636 PropertyChanges { target: notifications; width: units.gu(38) }
637 }
638 ]
639 }
640 }
642 Dialogs {
643 id: dialogs
644 objectName: "dialogs"
645 anchors.fill: parent
646 z: overlay.z + 10
647 usageScenario: shell.usageScenario
648 onPowerOffClicked: {
649 shutdownFadeOutRectangle.enabled = true;
650 shutdownFadeOutRectangle.visible = true;
651 shutdownFadeOut.start();
652 }
653 }
655 Connections {
656 target: SessionBroadcast
657 onShowHome: showHome()
658 }
660 ScreenGrabber {
661 id: screenGrabber
662 rotationAngle: -shell.orientationAngle
663 z: dialogs.z + 10
664 }
666 Cursor {
667 id: cursor
668 visible: shell.hasMouse
669 z: screenGrabber.z + 1
670 }
672 Rectangle {
673 id: shutdownFadeOutRectangle
674 z: cursor.z + 1
675 enabled: false
676 visible: false
677 color: "black"
678 anchors.fill: parent
679 opacity: 0.0
680 NumberAnimation on opacity {
681 id: shutdownFadeOut
682 from: 0.0
683 to: 1.0
684 onStopped: {
685 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
686 DBusUnitySessionService.shutdown();
687 }
688 }
689 }
690 }