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