on 6c53347 help sign in
unity8/qml/Shell.qml
620 lines 21 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.Launcher 0.1
27import Utils 0.1
28import LightDM 0.1 as LightDM
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
60 readonly property real panelHeight: panel.panelHeight
62 property bool sideStageEnabled: shell.width >= units.gu(100)
63 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
65 property int orientation
66 readonly property int deviceOrientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
67 onDeviceOrientationAngleChanged: {
68 if (!OrientationLock.enabled) {
69 orientation = Screen.orientation;
70 }
71 }
72 readonly property bool orientationLockEnabled: OrientationLock.enabled
73 onOrientationLockEnabledChanged: {
74 if (orientationLockEnabled) {
75 OrientationLock.savedOrientation = Screen.orientation;
76 } else {
77 orientation = Screen.orientation;
78 }
79 }
81 function activateApplication(appId) {
82 if (ApplicationManager.findApplication(appId)) {
83 ApplicationManager.requestFocusApplication(appId);
84 } else {
85 var execFlags = shell.sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
86 ApplicationManager.startApplication(appId, execFlags);
87 }
88 }
90 function startLockedApp(app) {
91 if (greeter.locked) {
92 greeter.lockedApp = app;
93 }
94 shell.activateApplication(app);
95 }
97 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
98 Image {
99 id: asImageTester
100 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
101 height: 0
102 width: 0
103 sourceSize.height: 0
104 sourceSize.width: 0
105 }
107 GSettings {
108 id: backgroundSettings
109 schema.id: "org.gnome.desktop.background"
110 }
112 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
113 Image {
114 id: gsImageTester
115 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
116 height: 0
117 width: 0
118 sourceSize.height: 0
119 sourceSize.width: 0
120 }
122 GSettings {
123 id: usageModeSettings
124 schema.id: "com.canonical.Unity8"
125 }
127 Binding {
128 target: LauncherModel
129 property: "applicationManager"
130 value: ApplicationManager
131 }
133 Component.onCompleted: {
134 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
135 if (ApplicationManager.count > 0) {
136 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
137 }
138 if (orientationLockEnabled) {
139 orientation = OrientationLock.savedOrientation;
140 }
141 }
143 VolumeControl {
144 id: volumeControl
145 }
147 DashCommunicator {
148 id: dash
149 objectName: "dashCommunicator"
150 }
152 PhysicalKeysMapper {
153 id: physicalKeysMapper
155 onPowerKeyLongPressed: dialogs.showPowerDialog()
156 onVolumeDownTriggered: volumeControl.volumeDown();
157 onVolumeUpTriggered: volumeControl.volumeUp();
158 onScreenshotTriggered: screenGrabber.capture();
160 onAltTabNext: applicationsDisplayLoader.item.altTabNext()
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 Item {
181 id: stages
182 objectName: "stages"
183 width: parent.width
184 height: parent.height
185 visible: !ApplicationManager.empty
187 Connections {
188 target: ApplicationManager
190 // This signal is also fired when we try to focus the current app
191 // again. We rely on this!
192 onFocusedApplicationIdChanged: {
193 var appId = ApplicationManager.focusedApplicationId;
195 if (tutorial.running && appId != "unity8-dash") {
196 // If this happens on first boot, we may be in edge
197 // tutorial or wizard while receiving a call. But a call
198 // is more important than wizard so just bail out of those.
199 tutorial.finish();
200 wizard.hide();
201 }
203 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
204 // If we are in the middle of a call, make dialer lockedApp and show it.
205 // This can happen if user backs out of dialer back to greeter, then
206 // launches dialer again.
207 greeter.lockedApp = appId;
208 }
209 greeter.notifyAppFocused(appId);
211 panel.indicators.hide();
212 }
214 onApplicationAdded: {
215 launcher.hide();
216 }
217 }
219 Loader {
220 id: applicationsDisplayLoader
221 objectName: "applicationsDisplayLoader"
222 anchors.fill: parent
224 // When we have a locked app, we only want to show that one app.
225 // FIXME: do this in a less traumatic way. We currently only allow
226 // locked apps in phone mode (see FIXME in Lockscreen component in
227 // this same file). When that changes, we need to do something
228 // nicer here. But this code is currently just to prevent a
229 // theoretical attack where user enters lockedApp mode, then makes
230 // the screen larger (maybe connects to monitor) and tries to enter
231 // tablet mode.
232 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
233 source: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
234 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
236 property bool interactive: tutorial.spreadEnabled
237 && !greeter.shown
238 && panel.indicators.fullyClosed
239 && launcher.progress == 0
240 && !notifications.useModal
242 onInteractiveChanged: { if (interactive) { focus = true; } }
244 Binding {
245 target: applicationsDisplayLoader.item
246 property: "objectName"
247 value: "stage"
248 }
249 Binding {
250 target: applicationsDisplayLoader.item
251 property: "dragAreaWidth"
252 value: shell.edgeSize
253 }
254 Binding {
255 target: applicationsDisplayLoader.item
256 property: "maximizedAppTopMargin"
257 // Not just using panel.panelHeight as that changes depending on the focused app.
258 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
259 }
260 Binding {
261 target: applicationsDisplayLoader.item
262 property: "interactive"
263 value: applicationsDisplayLoader.interactive
264 }
265 Binding {
266 target: applicationsDisplayLoader.item
267 property: "spreadEnabled"
268 value: tutorial.spreadEnabled && !greeter.hasLockedApp
269 }
270 Binding {
271 target: applicationsDisplayLoader.item
272 property: "inverseProgress"
273 value: greeter.locked ? 0 : launcher.progress
274 }
275 Binding {
276 target: applicationsDisplayLoader.item
277 property: "orientation"
278 value: shell.orientation
279 }
280 Binding {
281 target: applicationsDisplayLoader.item
282 property: "background"
283 value: shell.background
284 }
285 Binding {
286 target: applicationsDisplayLoader.item
287 property: "altTabPressed"
288 value: physicalKeysMapper.altTabPressed
289 }
290 }
291 }
293 InputMethod {
294 id: inputMethod
295 objectName: "inputMethod"
296 anchors { fill: parent; topMargin: panel.panelHeight }
297 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
298 }
300 Connections {
301 target: SurfaceManager
302 onSurfaceCreated: {
303 if (surface.type == MirSurfaceItem.InputMethod) {
304 inputMethod.surface = surface;
305 }
306 }
308 onSurfaceDestroyed: {
309 if (inputMethod.surface == surface) {
310 inputMethod.surface = null;
311 surface.parent = null;
312 }
313 if (!surface.parent) {
314 // there's no one displaying it. delete it right away
315 surface.release();
316 }
317 }
318 }
319 Connections {
320 target: SessionManager
321 onSessionStopping: {
322 if (!session.parentSession && !session.application) {
323 // nothing is using it. delete it right away
324 session.release();
325 }
326 }
327 }
329 Greeter {
330 id: greeter
331 objectName: "greeter"
333 hides: [launcher, panel.indicators]
334 tabletMode: shell.sideStageEnabled
335 launcherOffset: launcher.progress
336 forcedUnlock: tutorial.running
337 background: shell.background
339 anchors.fill: parent
340 anchors.topMargin: panel.panelHeight
342 // avoid overlapping with Launcher's edge drag area
343 // FIXME: Fix TouchRegistry & friends and remove this workaround
344 // Issue involves launcher's DDA getting disabled on a long
345 // left-edge drag
346 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
348 onSessionStarted: {
349 launcher.hide();
350 }
352 onTease: {
353 if (!tutorial.running) {
354 launcher.tease();
355 }
356 }
358 onEmergencyCall: startLockedApp("dialer-app")
360 Timer {
361 // See powerConnection for why this is useful
362 id: showGreeterDelayed
363 interval: 1
364 onTriggered: {
365 greeter.forceShow();
366 }
367 }
369 Binding {
370 target: ApplicationManager
371 property: "suspended"
372 value: greeter.shown
373 }
374 }
376 Connections {
377 id: callConnection
378 target: callManager
380 onHasCallsChanged: {
381 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
382 // We just received an incoming call while locked. The
383 // indicator will have already launched dialer-app for us, but
384 // there is a race between "hasCalls" changing and the dialer
385 // starting up. So in case we lose that race, we'll start/
386 // focus the dialer ourselves here too. Even if the indicator
387 // didn't launch the dialer for some reason (or maybe a call
388 // started via some other means), if an active call is
389 // happening, we want to be in the dialer.
390 startLockedApp("dialer-app")
391 }
392 }
393 }
395 Connections {
396 id: powerConnection
397 target: Powerd
399 onStatusChanged: {
400 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
401 !callManager.hasCalls && !tutorial.running) {
402 // We don't want to simply call greeter.showNow() here, because
403 // that will take too long. Qt will delay button event
404 // handling until the greeter is done loading and may think the
405 // user held down the power button the whole time, leading to a
406 // power dialog being shown. Instead, delay showing the
407 // greeter until we've finished handling the event. We could
408 // make the greeter load asynchronously instead, but that
409 // introduces a whole host of timing issues, especially with
410 // its animations. So this is simpler.
411 showGreeterDelayed.start();
412 }
413 }
414 }
416 function showHome() {
417 if (tutorial.running) {
418 return
419 }
421 greeter.notifyAboutToFocusApp("unity8-dash");
423 var animate = !LightDM.Greeter.active && !stages.shown
424 dash.setCurrentScope(0, animate, false)
425 ApplicationManager.requestFocusApplication("unity8-dash")
426 }
428 function showDash() {
429 if (greeter.notifyShowingDashFromDrag()) {
430 launcher.fadeOut();
431 }
433 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
434 ApplicationManager.requestFocusApplication("unity8-dash")
435 launcher.fadeOut();
436 }
437 }
439 Item {
440 id: overlay
441 z: 10
443 anchors.fill: parent
445 Panel {
446 id: panel
447 objectName: "panel"
448 anchors.fill: parent //because this draws indicator menus
449 indicators {
450 hides: [launcher]
451 available: tutorial.panelEnabled
452 && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
453 && !greeter.hasLockedApp
454 contentEnabled: tutorial.panelContentEnabled
455 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
457 minimizedPanelHeight: units.gu(3)
458 expandedPanelHeight: units.gu(7)
460 indicatorsModel: Indicators.IndicatorsModel {
461 // TODO: This should be sourced by device type (e.g. "desktop", "tablet", "phone"...)
462 profile: indicatorProfile
463 Component.onCompleted: load()
464 }
465 }
466 callHint {
467 greeterShown: greeter.shown
468 }
470 property bool topmostApplicationIsFullscreen:
471 ApplicationManager.focusedApplicationId &&
472 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
474 fullscreenMode: (topmostApplicationIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
475 || greeter.hasLockedApp
476 }
478 Launcher {
479 id: launcher
480 objectName: "launcher"
482 readonly property bool dashSwipe: progress > 0
484 anchors.top: parent.top
485 anchors.topMargin: inverted ? 0 : panel.panelHeight
486 anchors.bottom: parent.bottom
487 width: parent.width
488 dragAreaWidth: shell.edgeSize
489 available: tutorial.launcherEnabled
490 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
491 && !greeter.hasLockedApp
492 inverted: usageModeSettings.usageMode === "Staged"
493 shadeBackground: !tutorial.running
495 onShowDashHome: showHome()
496 onDash: showDash()
497 onDashSwipeChanged: {
498 if (dashSwipe) {
499 dash.setCurrentScope(0, false, true)
500 }
501 }
502 onLauncherApplicationSelected: {
503 if (!tutorial.running) {
504 greeter.notifyAboutToFocusApp(appId);
505 shell.activateApplication(appId)
506 }
507 }
508 onShownChanged: {
509 if (shown) {
510 panel.indicators.hide()
511 }
512 }
513 }
515 Wizard {
516 id: wizard
517 anchors.fill: parent
518 background: shell.background
519 }
521 Rectangle {
522 id: modalNotificationBackground
524 visible: notifications.useModal && (notifications.state == "narrow")
525 color: "#000000"
526 anchors.fill: parent
527 opacity: 0.9
529 MouseArea {
530 anchors.fill: parent
531 }
532 }
534 Notifications {
535 id: notifications
537 model: NotificationBackend.Model
538 margin: units.gu(1)
540 y: topmostIsFullscreen ? 0 : panel.panelHeight
541 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
543 states: [
544 State {
545 name: "narrow"
546 when: overlay.width <= units.gu(60)
547 AnchorChanges {
548 target: notifications
549 anchors.left: parent.left
550 anchors.right: parent.right
551 }
552 },
553 State {
554 name: "wide"
555 when: overlay.width > units.gu(60)
556 AnchorChanges {
557 target: notifications
558 anchors.left: undefined
559 anchors.right: parent.right
560 }
561 PropertyChanges { target: notifications; width: units.gu(38) }
562 }
563 ]
564 }
565 }
567 Dialogs {
568 id: dialogs
569 anchors.fill: parent
570 z: overlay.z + 10
571 onPowerOffClicked: {
572 shutdownFadeOutRectangle.enabled = true;
573 shutdownFadeOutRectangle.visible = true;
574 shutdownFadeOut.start();
575 }
576 }
578 Tutorial {
579 id: tutorial
580 objectName: "tutorial"
581 active: AccountsService.demoEdges
582 paused: LightDM.Greeter.active
583 launcher: launcher
584 panel: panel
585 stages: stages
586 overlay: overlay
587 edgeSize: shell.edgeSize
589 onFinished: {
590 AccountsService.demoEdges = false;
591 active = false; // for immediate response / if AS is having problems
592 }
593 }
595 Connections {
596 target: SessionBroadcast
597 onShowHome: showHome()
598 }
600 Rectangle {
601 id: shutdownFadeOutRectangle
602 z: screenGrabber.z + 10
603 enabled: false
604 visible: false
605 color: "black"
606 anchors.fill: parent
607 opacity: 0.0
608 NumberAnimation on opacity {
609 id: shutdownFadeOut
610 from: 0.0
611 to: 1.0
612 onStopped: {
613 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
614 DBusUnitySessionService.Shutdown();
615 }
616 }
617 }
618 }