on 976d829 help sign in
unity8/Shell.qml
796 lines 28 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 AccountsService 0.1
19import GSettings 1.0
20import Unity.Application 0.1
21import Ubuntu.Components 0.1
22import Ubuntu.Gestures 0.1
23import Unity.Launcher 0.1
24import LightDM 0.1 as LightDM
25import Powerd 0.1
26import SessionBroadcast 0.1
27import "Dash"
28import "Greeter"
29import "Launcher"
30import "Panel"
31import "Hud"
32import "Components"
33import "Bottombar"
34import "SideStage"
35import "Notifications"
36import Unity.Notifications 1.0 as NotificationBackend
38FocusScope {
39 id: shell
41 // this is only here to select the width / height of the window if not running fullscreen
42 property bool tablet: false
43 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
44 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
46 property real edgeSize: units.gu(2)
47 property url defaultBackground: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
48 property url background
49 readonly property real panelHeight: panel.panelHeight
51 property bool dashShown: dash.shown
52 property bool stageScreenshotsReady: {
53 if (sideStage.shown) {
54 if (mainStage.applications.count > 0) {
55 return mainStage.usingScreenshots && sideStage.usingScreenshots;
56 } else {
57 return sideStage.usingScreenshots;
58 }
59 } else {
60 return mainStage.usingScreenshots;
61 }
62 }
64 property var applicationManager: ApplicationManagerWrapper {}
66 Binding {
67 target: LauncherModel
68 property: "applicationManager"
69 value: ApplicationManager
70 }
72 Component.onCompleted: {
73 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
75 applicationManager.sideStageEnabled = Qt.binding(function() { return sideStage.enabled })
77 // FIXME: if application focused before shell starts, shell draws on top of it only.
78 // We should detect already running applications on shell start and bring them to the front.
79 applicationManager.unfocusCurrentApplication();
80 }
82 readonly property bool applicationFocused: !!applicationManager.mainStageFocusedApplication
83 || !!applicationManager.sideStageFocusedApplication
84 // Used for autopilot testing.
85 readonly property string currentFocusedAppId: ApplicationManager.focusedApplicationId
87 readonly property bool fullscreenMode: {
88 if (greeter.shown || lockscreen.shown) {
89 return false;
90 } else if (mainStage.usingScreenshots) { // Window Manager animating so want to re-evaluate fullscreen mode
91 return mainStage.switchingFromFullscreenToFullscreen;
92 } else if (applicationManager.mainStageFocusedApplication) {
93 return applicationManager.mainStageFocusedApplication.fullscreen;
94 } else {
95 return false;
96 }
97 }
99 function activateApplication(appId, argument) {
100 if (applicationManager) {
101 // For newly started applications, as it takes them time to draw their first frame
102 // we add a delay before we hide the animation screenshots to compensate.
103 var addDelay = !applicationManager.getApplicationFromDesktopFile(appId);
105 var application;
106 application = applicationManager.activateApplication(appId, argument);
107 if (application == null) {
108 return;
109 }
110 if (application.stage == ApplicationInfo.MainStage || !sideStage.enabled) {
111 mainStage.activateApplication(appId, addDelay);
112 } else {
113 sideStage.activateApplication(appId, addDelay);
114 }
115 stages.show();
116 }
117 }
119 GSettings {
120 id: backgroundSettings
121 schema.id: "org.gnome.desktop.background"
122 }
123 property url gSettingsPicture: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : shell.defaultBackground
124 onGSettingsPictureChanged: {
125 shell.background = gSettingsPicture
126 }
128 // This is a dummy image that is needed to determine if the picture url
129 // in backgroundSettings points to a valid picture file.
130 // We can't do this with the real background image because setting a
131 // new source in onStatusChanged triggers a binding loop detection
132 // inside Image, which causes it not to render even though a valid source
133 // would be set. We don't mind about this image staying black and just
134 // use it for verification to populate the source for the real
135 // background image.
136 Image {
137 source: shell.background
138 height: 0
139 width: 0
140 sourceSize.height: 0
141 sourceSize.width: 0
142 onStatusChanged: {
143 if (status == Image.Error && source != shell.defaultBackground) {
144 shell.background = defaultBackground
145 }
146 }
147 }
149 VolumeControl {
150 id: volumeControl
151 }
153 Keys.onVolumeUpPressed: volumeControl.volumeUp()
154 Keys.onVolumeDownPressed: volumeControl.volumeDown()
156 Item {
157 id: underlay
158 objectName: "underlay"
159 anchors.fill: parent
161 // Whether the underlay is fully covered by opaque UI elements.
162 property bool fullyCovered: panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth
164 readonly property bool applicationRunning: ((mainStage.applications && mainStage.applications.count > 0)
165 || (sideStage.applications && sideStage.applications.count > 0))
167 // Whether the user should see the topmost application surface (if there's one at all).
168 readonly property bool applicationSurfaceShouldBeSeen: applicationRunning && !stages.fullyHidden
169 && !mainStage.usingScreenshots // but want sideStage animating over app surface
173 // NB! Application surfaces are stacked behing the shell one. So they can only be seen by the user
174 // through the translucent parts of the shell surface.
175 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
177 CrossFadeImage {
178 id: backgroundImage
179 objectName: "backgroundImage"
181 anchors.fill: parent
182 source: shell.background
183 fillMode: Image.PreserveAspectCrop
184 }
186 Rectangle {
187 anchors.fill: parent
188 color: "black"
189 opacity: dash.disappearingAnimationProgress
190 }
192 Dash {
193 id: dash
194 objectName: "dash"
196 available: !greeter.shown && !lockscreen.shown
197 hides: [stages, launcher, panel.indicators]
198 shown: disappearingAnimationProgress !== 1.0
199 enabled: disappearingAnimationProgress === 0.0 && edgeDemo.dashEnabled
200 // FIXME: unfocus all applications when going back to the dash
201 onEnabledChanged: {
202 if (enabled) {
203 shell.applicationManager.unfocusCurrentApplication()
204 }
205 }
207 anchors {
208 fill: parent
209 topMargin: panel.panelHeight
210 }
212 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
213 opacity: 1.0 - disappearingAnimationProgress
214 property real disappearingAnimationProgress: {
215 if (greeter.shown) {
216 return greeter.showProgress;
217 } else {
218 return stagesOuterContainer.showProgress;
219 }
220 }
222 // FIXME: only necessary because stagesOuterContainer.showProgress and
223 // greeterRevealer.animatedProgress are not animated
224 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
225 }
226 }
228 Item {
229 id: stagesOuterContainer
231 width: parent.width
232 height: parent.height
233 x: launcher.progress
234 Behavior on x {SmoothedAnimation{velocity: 600}}
236 property real showProgress:
237 MathUtils.clamp(1 - (x + stages.x) / shell.width, 0, 1)
239 Showable {
240 id: stages
241 objectName: "stages"
243 x: width
245 property bool fullyShown: shown && x == 0 && parent.x == 0
246 property bool fullyHidden: !shown && x == width
247 available: !greeter.shown
248 hides: [panel.indicators]
249 shown: false
250 opacity: 1.0
251 showAnimation: StandardAnimation { property: "x"; duration: 350; to: 0; easing.type: Easing.OutCubic }
252 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: width; easing.type: Easing.OutCubic }
254 width: parent.width
255 height: parent.height
257 // close the stages when no focused application remains
258 Connections {
259 target: shell.applicationManager
260 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
261 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
262 ignoreUnknownSignals: true
263 }
265 function closeIfNoApplications() {
266 if (!shell.applicationManager.mainStageFocusedApplication
267 && !shell.applicationManager.sideStageFocusedApplication
268 && shell.applicationManager.mainStageApplications.count == 0
269 && shell.applicationManager.sideStageApplications.count == 0) {
270 stages.hide();
271 }
272 }
274 // show the stages when an application gets the focus
275 Connections {
276 target: shell.applicationManager
277 onMainStageFocusedApplicationChanged: {
278 if (shell.applicationManager.mainStageFocusedApplication) {
279 mainStage.show();
280 stages.show();
281 }
282 }
283 onSideStageFocusedApplicationChanged: {
284 if (shell.applicationManager.sideStageFocusedApplication) {
285 sideStage.show();
286 stages.show();
287 }
288 }
289 ignoreUnknownSignals: true
290 }
292 Stage {
293 id: mainStage
295 anchors.fill: parent
296 fullyShown: stages.fullyShown
297 fullyHidden: stages.fullyHidden
298 shouldUseScreenshots: !fullyShown
299 rightEdgeEnabled: !sideStage.enabled
301 applicationManager: shell.applicationManager
302 rightEdgeDraggingAreaWidth: shell.edgeSize
303 normalApplicationY: shell.panelHeight
305 shown: true
306 function show() {
307 stages.show();
308 }
309 function hide() {
310 }
312 // FIXME: workaround the fact that focusing a main stage application
313 // raises its surface on top of all other surfaces including the ones
314 // that belong to side stage applications.
315 onFocusedApplicationChanged: {
316 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
317 shell.applicationManager.focusApplication(sideStage.focusedApplication);
318 }
319 }
320 }
322 SideStage {
323 id: sideStage
325 applicationManager: shell.applicationManager
326 rightEdgeDraggingAreaWidth: shell.edgeSize
327 normalApplicationY: shell.panelHeight
329 onShownChanged: {
330 if (!shown && mainStage.applications.count == 0) {
331 stages.hide();
332 }
333 }
334 // FIXME: when hiding the side stage, refocus the main stage
335 // application so that it goes in front of the side stage
336 // application and hides it
337 onFullyShownChanged: {
338 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
339 shell.applicationManager.focusApplication(mainStage.focusedApplication);
340 }
341 }
343 enabled: shell.width >= units.gu(60)
344 visible: enabled
345 fullyShown: stages.fullyShown && shown
346 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
347 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
349 available: !greeter.shown && !lockscreen.shown && enabled
350 hides: [launcher, panel.indicators]
351 shown: false
352 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
353 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
355 width: units.gu(40)
356 height: stages.height
357 handleExpanded: sideStageRevealer.pressed
358 }
360 Revealer {
361 id: sideStageRevealer
363 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
364 && sideStage.available
365 direction: Qt.RightToLeft
366 openedValue: parent.width - sideStage.width
367 hintDisplacement: units.gu(3)
368 /* The size of the sidestage handle needs to be bigger than the
369 typical size used for edge detection otherwise it is really
370 hard to grab.
371 */
372 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
373 closedValue: parent.width + sideStage.handleSizeCollapsed
374 target: sideStage
375 x: parent.width - width
376 width: sideStage.width + handleSize * 0.7
377 height: sideStage.height
378 orientation: Qt.Horizontal
379 }
381 DragHandle {
382 id: stagesDragHandle
384 anchors.top: parent.top
385 anchors.bottom: parent.bottom
386 anchors.right: parent.left
388 width: shell.edgeSize
389 direction: Direction.Leftwards
390 enabled: greeter.showProgress == 0 && edgeDemo.dashEnabled
391 property bool haveApps: mainStage.applications.count > 0 || sideStage.applications.count > 0
393 maxTotalDragDistance: haveApps ? parent.width : parent.width * 0.7
394 // Make autocompletion impossible when !haveApps
395 edgeDragEvaluator.minDragDistance: haveApps ? maxTotalDragDistance * 0.1 : Number.MAX_VALUE
396 }
397 }
398 }
400 Lockscreen {
401 id: lockscreen
402 objectName: "lockscreen"
404 readonly property int backgroundTopMargin: -panel.panelHeight
406 hides: [launcher, panel.indicators, hud]
407 shown: false
408 enabled: true
409 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
410 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
411 y: panel.panelHeight
412 x: required ? 0 : - width
413 width: parent.width
414 height: parent.height - panel.panelHeight
415 background: shell.background
417 onEntered: LightDM.Greeter.respond(passphrase);
418 onCancel: greeter.show()
420 Component.onCompleted: {
421 if (LightDM.Users.count == 1) {
422 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
423 greeter.selected(0)
424 }
425 }
426 }
428 Connections {
429 target: LightDM.Greeter
431 onShowPrompt: {
432 if (LightDM.Users.count == 1) {
433 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
434 if (text == "PIN") {
435 lockscreen.alphaNumeric = false
436 } else {
437 lockscreen.alphaNumeric = true
438 }
439 lockscreen.placeholderText = i18n.tr("Please enter %1").arg(text);
440 lockscreen.show();
441 }
442 }
444 onAuthenticationComplete: {
445 if (LightDM.Greeter.promptless) {
446 return;
447 }
448 if (LightDM.Greeter.authenticated) {
449 lockscreen.hide();
450 } else {
451 lockscreen.clear(true);
452 }
453 }
454 }
456 Greeter {
457 id: greeter
458 objectName: "greeter"
460 available: true
461 hides: [launcher, panel.indicators, hud]
462 shown: true
464 defaultBackground: shell.background
466 y: panel.panelHeight
467 width: parent.width
468 height: parent.height - panel.panelHeight
470 dragHandleWidth: shell.edgeSize
472 property var previousMainApp: null
473 property var previousSideApp: null
475 function removeApplicationFocus() {
476 greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
477 greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
478 applicationManager.unfocusCurrentApplication();
479 }
481 function restoreApplicationFocus() {
482 if (greeter.previousMainApp) {
483 applicationManager.focusApplication(greeter.previousMainApp);
484 greeter.previousMainApp = null;
485 }
486 if (greeter.previousSideApp) {
487 applicationManager.focusApplication(greeter.previousSideApp);
488 greeter.previousSideApp = null;
489 }
490 }
492 onShownChanged: {
493 if (shown) {
494 lockscreen.reset();
495 // If there is only one user, we start authenticating with that one here.
496 // If there are more users, the Greeter will handle that
497 if (LightDM.Users.count == 1) {
498 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
499 greeter.selected(0);
500 }
501 greeter.forceActiveFocus();
502 removeApplicationFocus();
503 } else {
504 restoreApplicationFocus();
505 }
506 }
508 onUnlocked: greeter.hide()
509 onSelected: {
510 // Update launcher items for new user
511 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
512 AccountsService.user = user;
513 LauncherModel.setUser(user);
514 }
516 onLeftTeaserPressedChanged: {
517 if (leftTeaserPressed) {
518 launcher.tease();
519 }
520 }
522 Connections {
523 target: applicationManager
524 ignoreUnknownSignals: true
525 // If any app is focused when greeter is open, it's due to a user action
526 // like a snap decision (say, an incoming call).
527 // TODO: these should be protected to only unlock for certain applications / certain usecases
528 // potentially only in connection with a notification.
529 onMainStageFocusedApplicationChanged: {
530 if (greeter.shown && applicationManager.mainStageFocusedApplication) {
531 greeter.previousMainApp = null // make way for new focused app
532 greeter.previousSideApp = null
533 greeter.hide()
534 }
535 }
536 onSideStageFocusedApplicationChanged: {
537 if (greeter.shown && applicationManager.sideStageFocusedApplication) {
538 greeter.previousMainApp = null // make way for new focused app
539 greeter.previousSideApp = null
540 greeter.hide()
541 }
542 }
543 }
544 }
546 InputFilterArea {
547 anchors.fill: parent
548 blockInput: !applicationFocused || greeter.shown || lockscreen.shown || launcher.shown
549 || panel.indicators.shown || hud.shown
550 }
552 Connections {
553 id: powerConnection
554 target: Powerd
556 onDisplayPowerStateChange: {
557 // We ignore any display-off signals when the proximity sensor
558 // is active. This usually indicates something like a phone call.
559 if (status == Powerd.Off && (flags & Powerd.UseProximity) == 0) {
560 greeter.showNow();
561 }
563 // No reason to chew demo CPU when user isn't watching
564 if (status == Powerd.Off) {
565 edgeDemo.paused = true;
566 } else if (status == Powerd.On) {
567 edgeDemo.paused = false;
568 }
569 }
570 }
572 function showHome() {
573 var animate = !greeter.shown && !stages.shown
574 greeter.hide()
575 dash.setCurrentScope("home.scope", animate, false)
576 stages.hide()
577 }
579 Item {
580 id: overlay
582 anchors.fill: parent
584 Panel {
585 id: panel
586 anchors.fill: parent //because this draws indicator menus
587 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
588 indicators {
589 hides: [launcher]
590 available: edgeDemo.panelEnabled
591 contentEnabled: edgeDemo.panelContentEnabled
592 }
593 fullscreenMode: shell.fullscreenMode
594 searchVisible: !greeter.shown && !lockscreen.shown && dash.shown
596 InputFilterArea {
597 anchors {
598 top: parent.top
599 left: parent.left
600 right: parent.right
601 }
602 height: (panel.fullscreenMode) ? shell.edgeSize : panel.panelHeight
603 blockInput: true
604 }
605 }
607 Hud {
608 id: hud
610 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
611 height: parent.height
613 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown && edgeDemo.dashEnabled
614 shown: false
615 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
616 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
618 Connections {
619 target: shell.applicationManager
620 onMainStageFocusedApplicationChanged: hud.hide()
621 onSideStageFocusedApplicationChanged: hud.hide()
622 }
623 }
625 Revealer {
626 id: hudRevealer
628 enabled: hud.shown
629 width: hud.width
630 anchors.left: hud.left
631 height: parent.height
632 target: hud.revealerTarget
633 closedValue: height
634 openedValue: 0
635 direction: Qt.RightToLeft
636 orientation: Qt.Vertical
637 handleSize: hud.handleHeight
638 onCloseClicked: target.hide()
639 }
641 Bottombar {
642 id: bottombar
643 theHud: hud
644 anchors.fill: parent
645 enabled: hud.available
646 applicationIsOnForeground: applicationFocused
647 }
649 InputFilterArea {
650 blockInput: launcher.shown
651 anchors {
652 top: parent.top
653 bottom: parent.bottom
654 left: parent.left
655 }
656 width: launcher.width
657 }
659 Launcher {
660 id: launcher
662 readonly property bool dashSwipe: progress > 0
664 anchors.top: parent.top
665 anchors.bottom: parent.bottom
666 width: parent.width
667 dragAreaWidth: shell.edgeSize
668 available: (!greeter.shown || greeter.narrowMode) && edgeDemo.launcherEnabled
670 onDashItemSelected: showHome()
671 onDash: {
672 if (stages.shown) {
673 stages.hide();
674 launcher.hide();
675 }
676 }
677 onDashSwipeChanged: if (dashSwipe && stages.shown) dash.setCurrentScope("applications.scope", false, true)
678 onLauncherApplicationSelected:{
679 greeter.hide()
680 shell.activateApplication(appId)
681 }
682 onShownChanged: {
683 if (shown) {
684 panel.indicators.hide()
685 hud.hide()
686 bottombar.hide()
687 }
688 }
689 }
691 Notifications {
692 id: notifications
694 model: NotificationBackend.Model
695 anchors {
696 top: parent.top
697 right: parent.right
698 bottom: parent.bottom
699 leftMargin: units.gu(1)
700 rightMargin: units.gu(1)
701 topMargin: panel.panelHeight + units.gu(1)
702 }
703 states: [
704 State {
705 name: "narrow"
706 when: overlay.width <= units.gu(60)
707 AnchorChanges { target: notifications; anchors.left: parent.left }
708 },
709 State {
710 name: "wide"
711 when: overlay.width > units.gu(60)
712 AnchorChanges { target: notifications; anchors.left: undefined }
713 PropertyChanges { target: notifications; width: units.gu(38) }
714 }
715 ]
717 InputFilterArea {
718 anchors { left: parent.left; right: parent.right }
719 height: parent.contentHeight
720 blockInput: height > 0
721 }
722 }
723 }
725 focus: true
726 onFocusChanged: if (!focus) forceActiveFocus();
728 InputFilterArea {
729 anchors {
730 top: parent.top
731 bottom: parent.bottom
732 left: parent.left
733 }
734 width: shell.edgeSize
735 blockInput: true
736 }
738 InputFilterArea {
739 anchors {
740 top: parent.top
741 bottom: parent.bottom
742 right: parent.right
743 }
744 width: shell.edgeSize
745 blockInput: true
746 }
748 Binding {
749 target: i18n
750 property: "domain"
751 value: "unity8"
752 }
754 OSKController {
755 anchors.topMargin: panel.panelHeight
756 anchors.fill: parent // as needs to know the geometry of the shell
757 }
759 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
760 MouseArea {
761 anchors.bottom: parent.bottom
762 anchors.left: parent.left
763 anchors.right: parent.right
764 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
766 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
767 }
769 Label {
770 anchors.centerIn: parent
771 visible: applicationManager.fake
772 text: "EARLY ALPHA\nNOT READY FOR USE"
773 color: "lightgrey"
774 opacity: 0.2
775 font.weight: Font.Black
776 horizontalAlignment: Text.AlignHCenter
777 verticalAlignment: Text.AlignVCenter
778 fontSizeMode: Text.Fit
779 rotation: -45
780 scale: Math.min(parent.width, parent.height) / width
781 }
783 EdgeDemo {
784 id: edgeDemo
785 greeter: greeter
786 launcher: launcher
787 dash: dash
788 indicators: panel.indicators
789 underlay: underlay
790 }
792 Connections {
793 target: SessionBroadcast
794 onShowHome: showHome()
795 }