on a60d486 help sign in
unity8/qml/Shell.qml
641 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 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 function activateApplication(appId) {
86 if (ApplicationManager.findApplication(appId)) {
87 ApplicationManager.requestFocusApplication(appId);
88 } else {
89 var execFlags = shell.sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
90 ApplicationManager.startApplication(appId, execFlags);
91 }
92 }
94 function startLockedApp(app) {
95 if (greeter.locked) {
96 greeter.lockedApp = app;
97 }
98 shell.activateApplication(app);
99 }
101 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
102 Image {
103 id: asImageTester
104 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
105 height: 0
106 width: 0
107 sourceSize.height: 0
108 sourceSize.width: 0
109 }
111 GSettings {
112 id: backgroundSettings
113 schema.id: "org.gnome.desktop.background"
114 }
116 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
117 Image {
118 id: gsImageTester
119 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
120 height: 0
121 width: 0
122 sourceSize.height: 0
123 sourceSize.width: 0
124 }
126 GSettings {
127 id: usageModeSettings
128 schema.id: "com.canonical.Unity8"
129 }
131 Binding {
132 target: LauncherModel
133 property: "applicationManager"
134 value: ApplicationManager
135 }
137 Component.onCompleted: {
138 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
139 if (ApplicationManager.count > 0) {
140 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
141 }
142 if (orientationLockEnabled) {
143 orientation = OrientationLock.savedOrientation;
144 }
145 }
147 VolumeControl {
148 id: volumeControl
149 }
151 DashCommunicator {
152 id: dash
153 objectName: "dashCommunicator"
154 }
156 PhysicalKeysMapper {
157 id: physicalKeysMapper
159 onPowerKeyLongPressed: dialogs.showPowerDialog()
160 onVolumeDownTriggered: volumeControl.volumeDown();
161 onVolumeUpTriggered: volumeControl.volumeUp();
162 onScreenshotTriggered: screenGrabber.capture();
163 onAltTabNext: applicationsDisplayLoader.item.altTabNext()
164 onAltTabPrevious: applicationsDisplayLoader.item.altTabPrevious();
165 }
167 ScreenGrabber {
168 id: screenGrabber
169 z: dialogs.z + 10
170 enabled: Powerd.status === Powerd.On
171 }
173 Binding {
174 target: ApplicationManager
175 property: "forceDashActive"
176 value: launcher.shown || launcher.dashSwipe
177 }
179 WindowKeysFilter {
180 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
181 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
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 Binding {
289 target: applicationsDisplayLoader.item
290 property: "altTabPressed"
291 value: physicalKeysMapper.altTabPressed
292 }
293 }
295 Tutorial {
296 id: tutorial
297 objectName: "tutorial"
298 anchors.fill: parent
299 active: AccountsService.demoEdges
300 paused: LightDM.Greeter.active
301 launcher: launcher
302 panel: panel
303 edgeSize: shell.edgeSize
305 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
306 // we'll tell the tutorial to avoid using them on the Desktop. The
307 // Desktop doesn't use the same spread design anyway. The tutorial is
308 // all a bit of a placeholder on non-phone form factors right now.
309 // When the design team gives us more guidance, we can do something
310 // more clever here.
311 // TODO: use DeviceConfiguration instead of checking source
312 useEdgeDragArea: applicationsDisplayLoader.source != Qt.resolvedUrl("Stages/DesktopStage.qml")
314 onFinished: {
315 AccountsService.demoEdges = false;
316 active = false; // for immediate response / if AS is having problems
317 }
318 }
319 }
321 InputMethod {
322 id: inputMethod
323 objectName: "inputMethod"
324 anchors { fill: parent; topMargin: panel.panelHeight }
325 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
326 }
328 Connections {
329 target: SurfaceManager
330 onSurfaceCreated: {
331 if (surface.type == MirSurfaceItem.InputMethod) {
332 inputMethod.surface = surface;
333 }
334 }
336 onSurfaceDestroyed: {
337 if (inputMethod.surface == surface) {
338 inputMethod.surface = null;
339 surface.parent = null;
340 }
341 if (!surface.parent) {
342 // there's no one displaying it. delete it right away
343 surface.release();
344 }
345 }
346 }
347 Connections {
348 target: SessionManager
349 onSessionStopping: {
350 if (!session.parentSession && !session.application) {
351 // nothing is using it. delete it right away
352 session.release();
353 }
354 }
355 }
357 Greeter {
358 id: greeter
359 objectName: "greeter"
361 hides: [launcher, panel.indicators]
362 tabletMode: shell.sideStageEnabled
363 launcherOffset: launcher.progress
364 forcedUnlock: tutorial.running
365 background: shell.background
367 anchors.fill: parent
368 anchors.topMargin: panel.panelHeight
370 // avoid overlapping with Launcher's edge drag area
371 // FIXME: Fix TouchRegistry & friends and remove this workaround
372 // Issue involves launcher's DDA getting disabled on a long
373 // left-edge drag
374 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
376 onSessionStarted: {
377 launcher.hide();
378 }
380 onTease: {
381 if (!tutorial.running) {
382 launcher.tease();
383 }
384 }
386 onEmergencyCall: startLockedApp("dialer-app")
388 Timer {
389 // See powerConnection for why this is useful
390 id: showGreeterDelayed
391 interval: 1
392 onTriggered: {
393 greeter.forceShow();
394 }
395 }
397 Binding {
398 target: ApplicationManager
399 property: "suspended"
400 value: greeter.shown
401 }
402 }
404 Connections {
405 id: callConnection
406 target: callManager
408 onHasCallsChanged: {
409 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
410 // We just received an incoming call while locked. The
411 // indicator will have already launched dialer-app for us, but
412 // there is a race between "hasCalls" changing and the dialer
413 // starting up. So in case we lose that race, we'll start/
414 // focus the dialer ourselves here too. Even if the indicator
415 // didn't launch the dialer for some reason (or maybe a call
416 // started via some other means), if an active call is
417 // happening, we want to be in the dialer.
418 startLockedApp("dialer-app")
419 }
420 }
421 }
423 Connections {
424 id: powerConnection
425 target: Powerd
427 onStatusChanged: {
428 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
429 !callManager.hasCalls && !tutorial.running) {
430 // We don't want to simply call greeter.showNow() here, because
431 // that will take too long. Qt will delay button event
432 // handling until the greeter is done loading and may think the
433 // user held down the power button the whole time, leading to a
434 // power dialog being shown. Instead, delay showing the
435 // greeter until we've finished handling the event. We could
436 // make the greeter load asynchronously instead, but that
437 // introduces a whole host of timing issues, especially with
438 // its animations. So this is simpler.
439 showGreeterDelayed.start();
440 }
441 }
442 }
444 function showHome() {
445 if (tutorial.running) {
446 return
447 }
449 greeter.notifyAboutToFocusApp("unity8-dash");
451 var animate = !LightDM.Greeter.active && !stages.shown
452 dash.setCurrentScope(0, animate, false)
453 ApplicationManager.requestFocusApplication("unity8-dash")
454 }
456 function showDash() {
457 if (greeter.notifyShowingDashFromDrag()) {
458 launcher.fadeOut();
459 }
461 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
462 ApplicationManager.requestFocusApplication("unity8-dash")
463 launcher.fadeOut();
464 }
465 }
467 Item {
468 id: overlay
469 z: 10
471 anchors.fill: parent
473 Panel {
474 id: panel
475 objectName: "panel"
476 anchors.fill: parent //because this draws indicator menus
477 indicators {
478 hides: [launcher]
479 available: tutorial.panelEnabled
480 && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
481 && !greeter.hasLockedApp
482 contentEnabled: tutorial.panelContentEnabled
483 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
485 minimizedPanelHeight: units.gu(3)
486 expandedPanelHeight: units.gu(7)
488 indicatorsModel: Indicators.IndicatorsModel {
489 // TODO: This should be sourced by device type (e.g. "desktop", "tablet", "phone"...)
490 profile: indicatorProfile
491 Component.onCompleted: load()
492 }
493 }
494 callHint {
495 greeterShown: greeter.shown
496 }
498 property bool topmostApplicationIsFullscreen:
499 ApplicationManager.focusedApplicationId &&
500 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
502 fullscreenMode: (topmostApplicationIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
503 || greeter.hasLockedApp
504 }
506 Launcher {
507 id: launcher
508 objectName: "launcher"
510 readonly property bool dashSwipe: progress > 0
512 anchors.top: parent.top
513 anchors.topMargin: inverted ? 0 : panel.panelHeight
514 anchors.bottom: parent.bottom
515 width: parent.width
516 dragAreaWidth: shell.edgeSize
517 available: tutorial.launcherEnabled
518 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
519 && !greeter.hasLockedApp
520 inverted: usageModeSettings.usageMode === "Staged"
521 shadeBackground: !tutorial.running
523 onShowDashHome: showHome()
524 onDash: showDash()
525 onDashSwipeChanged: {
526 if (dashSwipe) {
527 dash.setCurrentScope(0, false, true)
528 }
529 }
530 onLauncherApplicationSelected: {
531 if (!tutorial.running) {
532 greeter.notifyAboutToFocusApp(appId);
533 shell.activateApplication(appId)
534 }
535 }
536 onShownChanged: {
537 if (shown) {
538 panel.indicators.hide()
539 }
540 }
541 }
543 Wizard {
544 id: wizard
545 objectName: "wizard"
546 anchors.fill: parent
547 background: shell.background
549 function unlockWhenDoneWithWizard() {
550 if (!active) {
551 Connectivity.unlockAllModems();
552 }
553 }
555 Component.onCompleted: unlockWhenDoneWithWizard()
556 onActiveChanged: unlockWhenDoneWithWizard()
557 }
559 Rectangle {
560 id: modalNotificationBackground
562 visible: notifications.useModal && (notifications.state == "narrow")
563 color: "#000000"
564 anchors.fill: parent
565 opacity: 0.9
567 MouseArea {
568 anchors.fill: parent
569 }
570 }
572 Notifications {
573 id: notifications
575 model: NotificationBackend.Model
576 margin: units.gu(1)
578 y: topmostIsFullscreen ? 0 : panel.panelHeight
579 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
581 states: [
582 State {
583 name: "narrow"
584 when: overlay.width <= units.gu(60)
585 AnchorChanges {
586 target: notifications
587 anchors.left: parent.left
588 anchors.right: parent.right
589 }
590 },
591 State {
592 name: "wide"
593 when: overlay.width > units.gu(60)
594 AnchorChanges {
595 target: notifications
596 anchors.left: undefined
597 anchors.right: parent.right
598 }
599 PropertyChanges { target: notifications; width: units.gu(38) }
600 }
601 ]
602 }
603 }
605 Dialogs {
606 id: dialogs
607 anchors.fill: parent
608 z: overlay.z + 10
609 onPowerOffClicked: {
610 shutdownFadeOutRectangle.enabled = true;
611 shutdownFadeOutRectangle.visible = true;
612 shutdownFadeOut.start();
613 }
614 }
616 Connections {
617 target: SessionBroadcast
618 onShowHome: showHome()
619 }
621 Rectangle {
622 id: shutdownFadeOutRectangle
623 z: screenGrabber.z + 10
624 enabled: false
625 visible: false
626 color: "black"
627 anchors.fill: parent
628 opacity: 0.0
629 NumberAnimation on opacity {
630 id: shutdownFadeOut
631 from: 0.0
632 to: 1.0
633 onStopped: {
634 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
635 DBusUnitySessionService.Shutdown();
636 }
637 }
638 }
639 }