on ee042fd help sign in
unity8/qml/Shell.qml
649 lines 23 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 LightDM 0.1 as LightDM
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
45Item {
46 id: shell
48 // Disable everything while greeter is waiting, so that the user can't swipe
49 // the greeter or launcher until we know whether the session is locked.
50 enabled: !greeter.waiting
52 // this is only here to select the width / height of the window if not running fullscreen
53 property bool tablet: false
54 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
55 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
57 property real edgeSize: units.gu(2)
58 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
59 property url background: asImageTester.status == Image.Ready ? asImageTester.source
60 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
61 readonly property real panelHeight: panel.panelHeight
63 property bool sideStageEnabled: shell.width >= units.gu(100)
64 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
66 property int orientation
67 readonly property int deviceOrientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
68 onDeviceOrientationAngleChanged: {
69 if (!OrientationLock.enabled) {
70 orientation = Screen.orientation;
71 }
72 }
73 readonly property bool orientationLockEnabled: OrientationLock.enabled
74 onOrientationLockEnabledChanged: {
75 if (orientationLockEnabled) {
76 OrientationLock.savedOrientation = Screen.orientation;
77 } else {
78 orientation = Screen.orientation;
79 }
80 }
82 // This is _only_ used to expose the property to autopilot tests
83 readonly property string testShellMode: shellMode
85 readonly property alias greeter: greeterLoader.item
87 function activateApplication(appId) {
88 if (ApplicationManager.findApplication(appId)) {
89 ApplicationManager.requestFocusApplication(appId);
90 } else {
91 var execFlags = shell.sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
92 ApplicationManager.startApplication(appId, execFlags);
93 }
94 }
96 function startLockedApp(app) {
97 if (greeter.locked) {
98 greeter.lockedApp = app;
99 }
100 shell.activateApplication(app);
101 }
103 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
104 Image {
105 id: asImageTester
106 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
107 height: 0
108 width: 0
109 sourceSize.height: 0
110 sourceSize.width: 0
111 }
113 GSettings {
114 id: backgroundSettings
115 objectName: "backgroundSettings"
116 schema.id: "org.gnome.desktop.background"
117 }
119 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
120 Image {
121 id: gsImageTester
122 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
123 height: 0
124 width: 0
125 sourceSize.height: 0
126 sourceSize.width: 0
127 }
129 GSettings {
130 id: usageModeSettings
131 schema.id: "com.canonical.Unity8"
132 }
134 Binding {
135 target: LauncherModel
136 property: "applicationManager"
137 value: ApplicationManager
138 }
140 Component.onCompleted: {
141 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
142 if (ApplicationManager.count > 0) {
143 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
144 }
145 if (orientationLockEnabled) {
146 orientation = OrientationLock.savedOrientation;
147 }
148 }
150 VolumeControl {
151 id: volumeControl
152 }
154 DashCommunicator {
155 id: dash
156 objectName: "dashCommunicator"
157 }
159 PhysicalKeysMapper {
160 id: physicalKeysMapper
162 onPowerKeyLongPressed: dialogs.showPowerDialog()
163 onVolumeDownTriggered: volumeControl.volumeDown();
164 onVolumeUpTriggered: volumeControl.volumeUp();
165 onScreenshotTriggered: screenGrabber.capture();
166 }
168 ScreenGrabber {
169 id: screenGrabber
170 z: dialogs.z + 10
171 enabled: Powerd.status === Powerd.On
172 }
174 Binding {
175 target: ApplicationManager
176 property: "forceDashActive"
177 value: launcher.shown || launcher.dashSwipe
178 }
180 WindowKeysFilter {
181 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
182 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
183 }
185 Item {
186 id: stages
187 objectName: "stages"
188 width: parent.width
189 height: parent.height
191 Connections {
192 target: ApplicationManager
194 // This signal is also fired when we try to focus the current app
195 // again. We rely on this!
196 onFocusedApplicationIdChanged: {
197 var appId = ApplicationManager.focusedApplicationId;
199 if (tutorial.running && appId != "" && appId != "unity8-dash") {
200 // If this happens on first boot, we may be in edge
201 // tutorial or wizard while receiving a call. But a call
202 // is more important than wizard so just bail out of those.
203 tutorial.finish();
204 wizard.hide();
205 }
207 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
208 // If we are in the middle of a call, make dialer lockedApp and show it.
209 // This can happen if user backs out of dialer back to greeter, then
210 // launches dialer again.
211 greeter.lockedApp = appId;
212 }
213 greeter.notifyAppFocused(appId);
215 panel.indicators.hide();
216 }
218 onApplicationAdded: {
219 launcher.hide();
220 }
221 }
223 Loader {
224 id: applicationsDisplayLoader
225 objectName: "applicationsDisplayLoader"
226 anchors.fill: parent
228 // When we have a locked app, we only want to show that one app.
229 // FIXME: do this in a less traumatic way. We currently only allow
230 // locked apps in phone mode (see FIXME in Lockscreen component in
231 // this same file). When that changes, we need to do something
232 // nicer here. But this code is currently just to prevent a
233 // theoretical attack where user enters lockedApp mode, then makes
234 // the screen larger (maybe connects to monitor) and tries to enter
235 // tablet mode.
236 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
237 property string stageSource: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml": tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
238 source: shellMode != "greeter" ? stageSource : "Stages/ShimStage.qml"
240 property bool interactive: tutorial.spreadEnabled
241 && !greeter.shown
242 && panel.indicators.fullyClosed
243 && launcher.progress == 0
244 && !notifications.useModal
246 onInteractiveChanged: { if (interactive) { focus = true; } }
248 Binding {
249 target: applicationsDisplayLoader.item
250 property: "objectName"
251 value: "stage"
252 }
253 Binding {
254 target: applicationsDisplayLoader.item
255 property: "dragAreaWidth"
256 value: shell.edgeSize
257 }
258 Binding {
259 target: applicationsDisplayLoader.item
260 property: "maximizedAppTopMargin"
261 // Not just using panel.panelHeight as that changes depending on the focused app.
262 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
263 }
264 Binding {
265 target: applicationsDisplayLoader.item
266 property: "interactive"
267 value: applicationsDisplayLoader.interactive
268 }
269 Binding {
270 target: applicationsDisplayLoader.item
271 property: "spreadEnabled"
272 value: tutorial.spreadEnabled && !greeter.hasLockedApp
273 }
274 Binding {
275 target: applicationsDisplayLoader.item
276 property: "inverseProgress"
277 value: greeter.locked ? 0 : launcher.progress
278 }
279 Binding {
280 target: applicationsDisplayLoader.item
281 property: "orientation"
282 value: shell.orientation
283 }
284 Binding {
285 target: applicationsDisplayLoader.item
286 property: "background"
287 value: shell.background
288 }
289 }
291 Tutorial {
292 id: tutorial
293 objectName: "tutorial"
294 anchors.fill: parent
295 active: AccountsService.demoEdges
296 paused: LightDM.Greeter.active
297 launcher: launcher
298 panel: panel
299 edgeSize: shell.edgeSize
301 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
302 // we'll tell the tutorial to avoid using them on the Desktop. The
303 // Desktop doesn't use the same spread design anyway. The tutorial is
304 // all a bit of a placeholder on non-phone form factors right now.
305 // When the design team gives us more guidance, we can do something
306 // more clever here.
307 // TODO: use DeviceConfiguration instead of checking source
308 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
310 onFinished: {
311 AccountsService.demoEdges = false;
312 active = false; // for immediate response / if AS is having problems
313 }
314 }
315 }
317 InputMethod {
318 id: inputMethod
319 objectName: "inputMethod"
320 anchors { fill: parent; topMargin: panel.panelHeight }
321 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
322 }
324 Connections {
325 target: SurfaceManager
326 onSurfaceCreated: {
327 if (surface.type == MirSurfaceItem.InputMethod) {
328 }
329 inputMethod.surface = surface;
330 }
331 }
333 onSurfaceDestroyed: {
334 if (inputMethod.surface == surface) {
335 inputMethod.surface = null;
336 surface.parent = null;
337 }
338 if (!surface.parent) {
339 // there's no one displaying it. delete it right away
340 surface.release();
341 }
342 }
343 }
344 Connections {
345 target: SessionManager
346 onSessionStopping: {
347 if (!session.parentSession && !session.application) {
348 // nothing is using it. delete it right away
349 session.release();
350 }
351 }
352 }
354 Loader {
355 id: greeterLoader
356 anchors.fill: parent
357 anchors.topMargin: panel.panelHeight
358 sourceComponent: shellMode != "shell" ? integratedGreeter :
359 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
360 }
362 Component {
363 id: integratedGreeter
364 Greeter {
365 objectName: "greeter"
367 hides: [launcher, panel.indicators]
368 tabletMode: shell.sideStageEnabled
369 launcherOffset: launcher.progress
370 forcedUnlock: tutorial.running || shellMode == "shell"
371 opacity: shellMode == "shell" ? 0 : 1.0
372 background: shell.background
374 //height: parent.parent.height; width: parent.parent.width
375 //anchors.topMargin: panel.panelHeight
377 // avoid overlapping with Launcher's edge drag area
378 // FIXME: Fix TouchRegistry & friends and remove this workaround
379 // Issue involves launcher's DDA getting disabled on a long
380 // left-edge drag
381 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
383 onSessionStarted: {
384 launcher.hide();
385 }
387 onTease: {
388 if (!tutorial.running) {
389 launcher.tease();
390 }
391 }
393 onEmergencyCall: startLockedApp("dialer-app")
395 Timer {
396 // See powerConnection for why this is useful
397 id: showGreeterDelayed
398 interval: 1
399 onTriggered: {
400 greeter.forceShow();
401 }
402 }
404 Binding {
405 target: ApplicationManager
406 property: "suspended"
407 value: greeter.shown
408 }
409 }
410 }
412 Connections {
413 id: callConnection
414 target: callManager
416 onHasCallsChanged: {
417 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
418 // We just received an incoming call while locked. The
419 // indicator will have already launched dialer-app for us, but
420 // there is a race between "hasCalls" changing and the dialer
421 // starting up. So in case we lose that race, we'll start/
422 // focus the dialer ourselves here too. Even if the indicator
423 // didn't launch the dialer for some reason (or maybe a call
424 // started via some other means), if an active call is
425 // happening, we want to be in the dialer.
426 startLockedApp("dialer-app")
427 }
428 }
429 }
431 Connections {
432 id: powerConnection
433 target: Powerd
435 onStatusChanged: {
436 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
437 !callManager.hasCalls && !tutorial.running && shellMode != "shell") {
438 // We don't want to simply call greeter.showNow() here, because
439 // that will take too long. Qt will delay button event
440 // handling until the greeter is done loading and may think the
441 // user held down the power button the whole time, leading to a
442 // power dialog being shown. Instead, delay showing the
443 // greeter until we've finished handling the event. We could
444 // make the greeter load asynchronously instead, but that
445 // introduces a whole host of timing issues, especially with
446 // its animations. So this is simpler.
447 showGreeterDelayed.start();
448 }
449 }
450 }
452 function showHome() {
453 if (tutorial.running) {
454 return
455 }
457 greeter.notifyAboutToFocusApp("unity8-dash");
459 var animate = !LightDM.Greeter.active && !stages.shown
460 dash.setCurrentScope(0, animate, false)
461 ApplicationManager.requestFocusApplication("unity8-dash")
462 }
464 function showDash() {
465 if (greeter.notifyShowingDashFromDrag()) {
466 launcher.fadeOut();
467 }
469 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
470 ApplicationManager.requestFocusApplication("unity8-dash")
471 launcher.fadeOut();
472 }
473 }
475 Item {
476 id: overlay
477 z: 10
479 anchors.fill: parent
481 Panel {
482 id: panel
483 objectName: "panel"
484 anchors.fill: parent //because this draws indicator menus
485 indicators {
486 hides: [launcher]
487 available: tutorial.panelEnabled
488 && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
489 && !greeter.hasLockedApp
490 contentEnabled: tutorial.panelContentEnabled
491 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
493 minimizedPanelHeight: units.gu(3)
494 expandedPanelHeight: units.gu(7)
496 indicatorsModel: Indicators.IndicatorsModel {
497 // TODO: This should be sourced by device type (e.g. "desktop", "tablet", "phone"...)
498 profile: indicatorProfile
499 Component.onCompleted: load()
500 }
501 }
502 callHint {
503 greeterShown: greeter.shown
504 }
506 property bool topmostApplicationIsFullscreen:
507 ApplicationManager.focusedApplicationId &&
508 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
510 fullscreenMode: (topmostApplicationIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
511 || greeter.hasLockedApp
512 }
514 Launcher {
515 id: launcher
516 objectName: "launcher"
518 readonly property bool dashSwipe: progress > 0
520 anchors.top: parent.top
521 anchors.topMargin: inverted ? 0 : panel.panelHeight
522 anchors.bottom: parent.bottom
523 width: parent.width
524 dragAreaWidth: shell.edgeSize
525 available: tutorial.launcherEnabled
526 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
527 && !greeter.hasLockedApp
528 inverted: usageModeSettings.usageMode === "Staged"
529 shadeBackground: !tutorial.running
531 onShowDashHome: showHome()
532 onDash: showDash()
533 onDashSwipeChanged: {
534 if (dashSwipe) {
535 dash.setCurrentScope(0, false, true)
536 }
537 }
538 onLauncherApplicationSelected: {
539 if (!tutorial.running) {
540 greeter.notifyAboutToFocusApp(appId);
541 shell.activateApplication(appId)
542 }
543 }
544 onShownChanged: {
545 if (shown) {
546 panel.indicators.hide()
547 }
548 }
549 }
551 Wizard {
552 id: wizard
553 objectName: "wizard"
554 anchors.fill: parent
555 background: shell.background
557 function unlockWhenDoneWithWizard() {
558 if (!active) {
559 Connectivity.unlockAllModems();
560 }
561 }
563 Component.onCompleted: unlockWhenDoneWithWizard()
564 onActiveChanged: unlockWhenDoneWithWizard()
565 }
567 Rectangle {
568 id: modalNotificationBackground
570 visible: notifications.useModal && (notifications.state == "narrow")
571 color: "#000000"
572 anchors.fill: parent
573 opacity: 0.9
575 MouseArea {
576 anchors.fill: parent
577 }
578 }
580 Notifications {
581 id: notifications
583 model: NotificationBackend.Model
584 margin: units.gu(1)
586 y: topmostIsFullscreen ? 0 : panel.panelHeight
587 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
589 states: [
590 State {
591 name: "narrow"
592 when: overlay.width <= units.gu(60)
593 AnchorChanges {
594 target: notifications
595 anchors.left: parent.left
596 anchors.right: parent.right
597 }
598 },
599 State {
600 name: "wide"
601 when: overlay.width > units.gu(60)
602 AnchorChanges {
603 target: notifications
604 anchors.left: undefined
605 anchors.right: parent.right
606 }
607 PropertyChanges { target: notifications; width: units.gu(38) }
608 }
609 ]
610 }
611 }
613 Dialogs {
614 id: dialogs
615 anchors.fill: parent
616 z: overlay.z + 10
617 onPowerOffClicked: {
618 shutdownFadeOutRectangle.enabled = true;
619 shutdownFadeOutRectangle.visible = true;
620 shutdownFadeOut.start();
621 }
622 }
624 Connections {
625 target: SessionBroadcast
626 onShowHome: showHome()
627 }
629 Rectangle {
630 id: shutdownFadeOutRectangle
631 z: screenGrabber.z + 10
632 enabled: false
633 visible: false
634 color: "black"
635 anchors.fill: parent
636 opacity: 0.0
637 NumberAnimation on opacity {
638 id: shutdownFadeOut
639 from: 0.0
640 to: 1.0
641 onStopped: {
642 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
643 DBusUnitySessionService.Shutdown();
644 }
645 }
646 }
647 }