on 9eef0f3 help sign in
unity8/qml/Shell.qml
637 lines 22 kB history raw
1/*
2 * Copyright (C) 2013 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 GSettings 1.0
21import Unity.Application 0.1
22import Ubuntu.Components 0.1
23import Ubuntu.Components.Popups 1.0
24import Ubuntu.Gestures 0.1
25import Ubuntu.Telephony 0.1 as Telephony
26import Unity.Connectivity 0.1
27import Unity.Launcher 0.1
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
44Item {
45 id: shell
47 // Disable everything while greeter is waiting, so that the user can't swipe
48 // the greeter or launcher until we know whether the session is locked.
49 enabled: !greeter.waiting
51 // this is only here to select the width / height of the window if not running fullscreen
52 property bool tablet: false
53 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
54 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
56 property real edgeSize: units.gu(2)
57 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
58 property url background: asImageTester.status == Image.Ready ? asImageTester.source
59 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
61 property bool sideStageEnabled: shell.width >= units.gu(100)
62 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
64 property int orientation
65 readonly property int deviceOrientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
66 onDeviceOrientationAngleChanged: {
67 if (!OrientationLock.enabled) {
68 orientation = Screen.orientation;
69 }
70 }
71 readonly property bool orientationLockEnabled: OrientationLock.enabled
72 onOrientationLockEnabledChanged: {
73 if (orientationLockEnabled) {
74 OrientationLock.savedOrientation = Screen.orientation;
75 } else {
76 orientation = Screen.orientation;
77 }
78 }
80 // This is _only_ used to expose the property to autopilot tests
81 readonly property string testShellMode: shellMode
83 function activateApplication(appId) {
84 if (ApplicationManager.findApplication(appId)) {
85 ApplicationManager.requestFocusApplication(appId);
86 } else {
87 var execFlags = shell.sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
88 ApplicationManager.startApplication(appId, execFlags);
89 }
90 }
92 function startLockedApp(app) {
93 if (greeter.locked) {
94 greeter.lockedApp = app;
95 }
96 shell.activateApplication(app);
97 }
99 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
100 Image {
101 id: asImageTester
102 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
103 height: 0
104 width: 0
105 sourceSize.height: 0
106 sourceSize.width: 0
107 }
109 GSettings {
110 id: backgroundSettings
111 schema.id: "org.gnome.desktop.background"
112 }
114 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
115 Image {
116 id: gsImageTester
117 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
118 height: 0
119 width: 0
120 sourceSize.height: 0
121 sourceSize.width: 0
122 }
124 GSettings {
125 id: usageModeSettings
126 schema.id: "com.canonical.Unity8"
127 }
129 Binding {
130 target: LauncherModel
131 property: "applicationManager"
132 value: ApplicationManager
133 }
135 Component.onCompleted: {
136 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
137 if (ApplicationManager.count > 0) {
138 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
139 }
140 if (orientationLockEnabled) {
141 orientation = OrientationLock.savedOrientation;
142 }
143 }
145 VolumeControl {
146 id: volumeControl
147 }
149 DashCommunicator {
150 id: dash
151 objectName: "dashCommunicator"
152 }
154 PhysicalKeysMapper {
155 id: physicalKeysMapper
157 onPowerKeyLongPressed: dialogs.showPowerDialog()
158 onVolumeDownTriggered: volumeControl.volumeDown();
159 onVolumeUpTriggered: volumeControl.volumeUp();
160 onScreenshotTriggered: screenGrabber.capture();
161 }
163 ScreenGrabber {
164 id: screenGrabber
165 z: dialogs.z + 10
166 enabled: Powerd.status === Powerd.On
167 }
169 Binding {
170 target: ApplicationManager
171 property: "forceDashActive"
172 value: launcher.shown || launcher.dashSwipe
173 }
175 WindowKeysFilter {
176 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
177 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
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.
235 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
236 source: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
237 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
239 property bool interactive: tutorial.spreadEnabled
240 && !greeter.shown
241 && panel.indicators.fullyClosed
242 && launcher.progress == 0
243 && !notifications.useModal
245 onInteractiveChanged: { if (interactive) { focus = true; } }
247 Binding {
248 target: applicationsDisplayLoader.item
249 property: "objectName"
250 value: "stage"
251 }
252 Binding {
253 target: applicationsDisplayLoader.item
254 property: "dragAreaWidth"
255 value: shell.edgeSize
256 }
257 Binding {
258 target: applicationsDisplayLoader.item
259 property: "maximizedAppTopMargin"
260 // Not just using panel.panelHeight as that changes depending on the focused app.
261 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
262 }
263 Binding {
264 target: applicationsDisplayLoader.item
265 property: "interactive"
266 value: applicationsDisplayLoader.interactive
267 }
268 Binding {
269 target: applicationsDisplayLoader.item
270 property: "spreadEnabled"
271 value: tutorial.spreadEnabled && !greeter.hasLockedApp
272 }
273 Binding {
274 target: applicationsDisplayLoader.item
275 property: "inverseProgress"
276 value: greeter.locked ? 0 : launcher.progress
277 }
278 Binding {
279 target: applicationsDisplayLoader.item
280 property: "orientation"
281 value: shell.orientation
282 }
283 Binding {
284 target: applicationsDisplayLoader.item
285 property: "background"
286 value: shell.background
287 }
288 }
290 Tutorial {
291 id: tutorial
292 objectName: "tutorial"
293 anchors.fill: parent
294 active: AccountsService.demoEdges
295 paused: lightDMGreeterAPI.active
296 launcher: launcher
297 panel: panel
298 edgeSize: shell.edgeSize
300 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
301 // we'll tell the tutorial to avoid using them on the Desktop. The
302 // Desktop doesn't use the same spread design anyway. The tutorial is
303 // all a bit of a placeholder on non-phone form factors right now.
304 // When the design team gives us more guidance, we can do something
305 // more clever here.
306 // TODO: use DeviceConfiguration instead of checking source
307 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
309 onFinished: {
310 AccountsService.demoEdges = false;
311 active = false; // for immediate response / if AS is having problems
312 }
313 }
314 }
316 InputMethod {
317 id: inputMethod
318 objectName: "inputMethod"
319 anchors { fill: parent; topMargin: panel.panelHeight }
320 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
321 }
323 Connections {
324 target: SurfaceManager
325 onSurfaceCreated: {
326 if (surface.type == MirSurfaceItem.InputMethod) {
327 inputMethod.surface = surface;
328 }
329 }
331 onSurfaceDestroyed: {
332 if (inputMethod.surface == surface) {
333 inputMethod.surface = null;
334 surface.parent = null;
335 }
336 if (!surface.parent) {
337 // there's no one displaying it. delete it right away
338 surface.release();
339 }
340 }
341 }
342 Connections {
343 target: SessionManager
344 onSessionStopping: {
345 if (!session.parentSession && !session.application) {
346 // nothing is using it. delete it right away
347 session.release();
348 }
349 }
350 }
352 LightDMGreeterAPI{id:lightDMGreeterAPI} /* expose lightdm backend */
353 Greeter {
354 id: greeter
355 objectName: "greeter"
357 hides: [launcher, panel.indicators]
358 tabletMode: shell.sideStageEnabled
359 launcherOffset: launcher.progress
360 forcedUnlock: tutorial.running
361 background: shell.background
363 anchors.fill: parent
364 anchors.topMargin: panel.panelHeight
366 // avoid overlapping with Launcher's edge drag area
367 // FIXME: Fix TouchRegistry & friends and remove this workaround
368 // Issue involves launcher's DDA getting disabled on a long
369 // left-edge drag
370 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
372 onSessionStarted: {
373 launcher.hide();
374 }
376 onTease: {
377 if (!tutorial.running) {
378 launcher.tease();
379 }
380 }
382 onEmergencyCall: startLockedApp("dialer-app")
384 Timer {
385 // See powerConnection for why this is useful
386 id: showGreeterDelayed
387 interval: 1
388 onTriggered: {
389 greeter.forceShow();
390 }
391 }
393 Binding {
394 target: ApplicationManager
395 property: "suspended"
396 value: greeter.shown
397 }
398 }
400 Connections {
401 id: callConnection
402 target: callManager
404 onHasCallsChanged: {
405 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
406 // We just received an incoming call while locked. The
407 // indicator will have already launched dialer-app for us, but
408 // there is a race between "hasCalls" changing and the dialer
409 // starting up. So in case we lose that race, we'll start/
410 // focus the dialer ourselves here too. Even if the indicator
411 // didn't launch the dialer for some reason (or maybe a call
412 // started via some other means), if an active call is
413 // happening, we want to be in the dialer.
414 startLockedApp("dialer-app")
415 }
416 }
417 }
419 Connections {
420 id: powerConnection
421 target: Powerd
423 onStatusChanged: {
424 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
425 !callManager.hasCalls && !tutorial.running) {
426 // We don't want to simply call greeter.showNow() here, because
427 // that will take too long. Qt will delay button event
428 // handling until the greeter is done loading and may think the
429 // user held down the power button the whole time, leading to a
430 // power dialog being shown. Instead, delay showing the
431 // greeter until we've finished handling the event. We could
432 // make the greeter load asynchronously instead, but that
433 // introduces a whole host of timing issues, especially with
434 // its animations. So this is simpler.
435 showGreeterDelayed.start();
436 }
437 }
438 }
440 function showHome() {
441 if (tutorial.running) {
442 return
443 }
445 greeter.notifyAboutToFocusApp("unity8-dash");
447 var animate = !lightDMGreeterAPI.active && !stages.shown
448 dash.setCurrentScope(0, animate, false)
449 ApplicationManager.requestFocusApplication("unity8-dash")
450 }
452 function showDash() {
453 if (greeter.notifyShowingDashFromDrag()) {
454 launcher.fadeOut();
455 }
457 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
458 ApplicationManager.requestFocusApplication("unity8-dash")
459 launcher.fadeOut();
460 }
461 }
463 Item {
464 id: overlay
465 z: 10
467 anchors.fill: parent
469 Panel {
470 id: panel
471 objectName: "panel"
472 anchors.fill: parent //because this draws indicator menus
473 indicators {
474 hides: [launcher]
475 available: tutorial.panelEnabled
476 && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
477 && !greeter.hasLockedApp
478 contentEnabled: tutorial.panelContentEnabled
479 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
481 minimizedPanelHeight: units.gu(3)
482 expandedPanelHeight: units.gu(7)
484 indicatorsModel: Indicators.IndicatorsModel {
485 // TODO: This should be sourced by device type (e.g. "desktop", "tablet", "phone"...)
486 profile: indicatorProfile
487 Component.onCompleted: load()
488 }
489 }
490 callHint {
491 greeterShown: greeter.shown
492 }
494 property bool topmostApplicationIsFullscreen:
495 ApplicationManager.focusedApplicationId &&
496 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
498 fullscreenMode: (topmostApplicationIsFullscreen && !lightDMGreeterAPI.active && launcher.progress == 0)
499 || greeter.hasLockedApp
500 }
502 Launcher {
503 id: launcher
504 objectName: "launcher"
506 readonly property bool dashSwipe: progress > 0
508 anchors.top: parent.top
509 anchors.topMargin: inverted ? 0 : panel.panelHeight
510 anchors.bottom: parent.bottom
511 width: parent.width
512 dragAreaWidth: shell.edgeSize
513 available: tutorial.launcherEnabled
514 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
515 && !greeter.hasLockedApp
516 inverted: usageModeSettings.usageMode === "Staged"
517 shadeBackground: !tutorial.running
519 onShowDashHome: showHome()
520 onDash: showDash()
521 onDashSwipeChanged: {
522 if (dashSwipe) {
523 dash.setCurrentScope(0, false, true)
524 }
525 }
526 onLauncherApplicationSelected: {
527 if (!tutorial.running) {
528 greeter.notifyAboutToFocusApp(appId);
529 shell.activateApplication(appId)
530 }
531 }
532 onShownChanged: {
533 if (shown) {
534 panel.indicators.hide()
535 }
536 }
537 }
539 Wizard {
540 id: wizard
541 objectName: "wizard"
542 anchors.fill: parent
543 background: shell.background
545 function unlockWhenDoneWithWizard() {
546 if (!active) {
547 Connectivity.unlockAllModems();
548 }
549 }
551 Component.onCompleted: unlockWhenDoneWithWizard()
552 onActiveChanged: unlockWhenDoneWithWizard()
553 }
555 Rectangle {
556 id: modalNotificationBackground
558 visible: notifications.useModal && (notifications.state == "narrow")
559 color: "#000000"
560 anchors.fill: parent
561 opacity: 0.9
563 MouseArea {
564 anchors.fill: parent
565 }
566 }
568 Notifications {
569 id: notifications
571 model: NotificationBackend.Model
572 margin: units.gu(1)
574 y: topmostIsFullscreen ? 0 : panel.panelHeight
575 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
577 states: [
578 State {
579 name: "narrow"
580 when: overlay.width <= units.gu(60)
581 AnchorChanges {
582 target: notifications
583 anchors.left: parent.left
584 anchors.right: parent.right
585 }
586 },
587 State {
588 name: "wide"
589 when: overlay.width > units.gu(60)
590 AnchorChanges {
591 target: notifications
592 anchors.left: undefined
593 anchors.right: parent.right
594 }
595 PropertyChanges { target: notifications; width: units.gu(38) }
596 }
597 ]
598 }
599 }
601 Dialogs {
602 id: dialogs
603 anchors.fill: parent
604 z: overlay.z + 10
605 onPowerOffClicked: {
606 shutdownFadeOutRectangle.enabled = true;
607 shutdownFadeOutRectangle.visible = true;
608 shutdownFadeOut.start();
609 }
610 }
612 Connections {
613 target: SessionBroadcast
614 onShowHome: showHome()
615 }
617 Rectangle {
618 id: shutdownFadeOutRectangle
619 z: screenGrabber.z + 10
620 enabled: false
621 visible: false
622 color: "black"
623 anchors.fill: parent
624 opacity: 0.0
625 NumberAnimation on opacity {
626 id: shutdownFadeOut
627 from: 0.0
628 to: 1.0
629 onStopped: {
630 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
631 DBusUnitySessionService.Shutdown();
632 }
633 }
634 }
635 }