on da63a1d help sign in
unity8/Shell.qml
630 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 Ubuntu.Application 0.1
19import Ubuntu.Components 0.1
20import LightDM 0.1 as LightDM
21import "Dash"
22import "Greeter"
23import "Launcher"
24import "Panel"
25import "Hud"
26import "Components"
27import "Components/Math.js" as MathLocal
28import "Bottombar"
29import "SideStage"
30import "Notifications"
31import Unity.Notifications 1.0 as NotificationBackend
33FocusScope {
34 id: shell
36 // this is only here to select the width / height of the window if not running fullscreen
37 property bool tablet: false
38 width: tablet ? units.gu(160) : units.gu(40)
39 height: tablet ? units.gu(100) : units.gu(71)
41 property real edgeSize: units.gu(2)
42 property url default_background: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
43 property url background: default_background
44 readonly property real panelHeight: panel.panelHeight
46 property bool dashShown: dash.shown
47 property bool stageScreenshotsReady: {
48 if (sideStage.shown) {
49 if (mainStage.applications.count > 0) {
50 return mainStage.usingScreenshots && sideStage.usingScreenshots;
51 } else {
52 return sideStage.usingScreenshots;
53 }
54 } else {
55 return mainStage.usingScreenshots;
56 }
57 }
59 property ListModel searchHistory: SearchHistoryModel {}
61 property var applicationManager: ApplicationManagerWrapper {}
63 Component.onCompleted: {
64 applicationManager.sideStageEnabled = Qt.binding(function() { return sideStage.enabled })
66 // FIXME: if application focused before shell starts, shell draws on top of it only.
67 // We should detect already running applications on shell start and bring them to the front.
68 applicationManager.unfocusCurrentApplication();
69 }
71 readonly property bool fullscreenMode: {
72 if (greeter.shown || lockscreen.shown) {
73 return false;
74 } else if (mainStage.usingScreenshots) { // Window Manager animating so want to re-evaluate fullscreen mode
75 return mainStage.switchingFromFullscreenToFullscreen;
76 } else if (applicationManager.mainStageFocusedApplication) {
77 return applicationManager.mainStageFocusedApplication.fullscreen;
78 } else {
79 return false;
80 }
81 }
83 Connections {
84 target: applicationManager
85 ignoreUnknownSignals: true
86 onFocusRequested: {
87 // TODO: this should be protected to only unlock for certain applications / certain usecases
88 // potentially only in connection with a notification
89 greeter.hide();
90 shell.activateApplication(desktopFile);
91 }
92 }
94 function activateApplication(desktopFile, argument) {
95 if (applicationManager) {
96 // For newly started applications, as it takes them time to draw their first frame
97 // we add a delay before we hide the animation screenshots to compensate.
98 var addDelay = !applicationManager.getApplicationFromDesktopFile(desktopFile);
100 var application;
101 application = applicationManager.activateApplication(desktopFile, argument);
102 if (application == null) {
103 return;
104 }
105 if (application.stage == ApplicationInfo.MainStage || !sideStage.enabled) {
106 mainStage.activateApplication(desktopFile, addDelay);
107 } else {
108 sideStage.activateApplication(desktopFile, addDelay);
109 }
110 stages.show();
111 }
112 }
114 VolumeControl {
115 id: volumeControl
116 }
118 Keys.onVolumeUpPressed: volumeControl.volumeUp()
119 Keys.onVolumeDownPressed: volumeControl.volumeDown()
121 Keys.onReleased: {
122 if (event.key == Qt.Key_PowerOff) {
123 greeter.show()
124 }
125 }
127 Item {
128 id: underlay
129 anchors.fill: parent
130 visible: !(panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth)
131 && (stages.fullyHidden
132 || (stages.fullyShown && mainStage.usingScreenshots)
133 || !stages.fullyShown && (mainStage.usingScreenshots || (sideStage.shown && sideStage.usingScreenshots)))
135 Image {
136 id: backgroundImage
137 source: shell.background
138 sourceSize.width: parent.width
139 sourceSize.height: parent.height
140 anchors.fill: parent
141 }
143 Rectangle {
144 anchors.fill: parent
145 color: "black"
146 opacity: dash.disappearingAnimationProgress
147 }
149 Dash {
150 id: dash
152 available: !greeter.shown && !lockscreen.shown
153 hides: [stages, launcher, panel.indicators]
154 shown: disappearingAnimationProgress !== 1.0
155 enabled: disappearingAnimationProgress === 0.0
156 // FIXME: unfocus all applications when going back to the dash
157 onEnabledChanged: {
158 if (enabled) {
159 shell.applicationManager.unfocusCurrentApplication()
160 }
161 }
163 anchors {
164 fill: parent
165 topMargin: panel.panelHeight
166 }
168 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
169 opacity: 1.0 - disappearingAnimationProgress
170 property real disappearingAnimationProgress: ((greeter.shown) ? greeterRevealer.animatedProgress : stagesRevealer.animatedProgress)
171 // FIXME: only necessary because stagesRevealer.animatedProgress and
172 // greeterRevealer.animatedProgress are not animated
173 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
174 }
175 }
178 Item {
180 width: parent.width
181 height: parent.height
182 x: launcher.progress
183 Behavior on x {SmoothedAnimation{velocity: 600}}
186 Showable {
187 id: stages
189 property bool fullyShown: shown && stages[stagesRevealer.boundProperty] == stagesRevealer.openedValue
190 && parent.x == 0
191 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
192 available: !greeter.shown
193 hides: [launcher, panel.indicators]
194 shown: false
195 opacity: 1.0
196 showAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.openedValue; easing.type: Easing.OutCubic }
197 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.closedValue; easing.type: Easing.OutCubic }
199 width: parent.width
200 height: parent.height
202 // close the stages when no focused application remains
203 Connections {
204 target: shell.applicationManager
205 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
206 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
207 ignoreUnknownSignals: true
208 }
210 function closeIfNoApplications() {
211 if (!shell.applicationManager.mainStageFocusedApplication
212 && !shell.applicationManager.sideStageFocusedApplication
213 && shell.applicationManager.mainStageApplications.count == 0
214 && shell.applicationManager.sideStageApplications.count == 0) {
215 stages.hide();
216 }
217 }
219 // show the stages when an application gets the focus
220 Connections {
221 target: shell.applicationManager
222 onMainStageFocusedApplicationChanged: {
223 if (shell.applicationManager.mainStageFocusedApplication) {
224 mainStage.show();
225 stages.show();
226 }
227 }
228 onSideStageFocusedApplicationChanged: {
229 if (shell.applicationManager.sideStageFocusedApplication) {
230 sideStage.show();
231 stages.show();
232 }
233 }
234 ignoreUnknownSignals: true
235 }
238 Stage {
239 id: mainStage
241 anchors.fill: parent
242 fullyShown: stages.fullyShown
243 shouldUseScreenshots: !fullyShown
244 rightEdgeEnabled: !sideStage.enabled
246 applicationManager: shell.applicationManager
247 rightEdgeDraggingAreaWidth: shell.edgeSize
248 normalApplicationY: shell.panelHeight
250 shown: true
251 function show() {
252 stages.show();
253 }
254 function showWithoutAnimation() {
255 stages.showWithoutAnimation();
256 }
257 function hide() {
258 }
260 // FIXME: workaround the fact that focusing a main stage application
261 // raises its surface on top of all other surfaces including the ones
262 // that belong to side stage applications.
263 onFocusedApplicationChanged: {
264 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
265 shell.applicationManager.focusApplication(sideStage.focusedApplication);
266 }
267 }
268 }
270 SideStage {
271 id: sideStage
273 applicationManager: shell.applicationManager
274 rightEdgeDraggingAreaWidth: shell.edgeSize
275 normalApplicationY: shell.panelHeight
277 onShownChanged: {
278 if (!shown && mainStage.applications.count == 0) {
279 stages.hide();
280 }
281 }
282 // FIXME: when hiding the side stage, refocus the main stage
283 // application so that it goes in front of the side stage
284 // application and hides it
285 onFullyShownChanged: {
286 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
287 shell.applicationManager.focusApplication(mainStage.focusedApplication);
288 }
289 }
291 enabled: shell.width >= units.gu(60)
292 visible: enabled
293 fullyShown: stages.fullyShown && shown
294 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
295 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
297 available: !greeter.shown && !lockscreen.shown && enabled
298 hides: [launcher, panel.indicators]
299 shown: false
300 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
301 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
303 width: units.gu(40)
304 height: stages.height
305 handleExpanded: sideStageRevealer.pressed
306 }
308 Revealer {
309 id: sideStageRevealer
311 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
312 && sideStage.available
313 direction: Qt.RightToLeft
314 openedValue: parent.width - sideStage.width
315 hintDisplacement: units.gu(3)
316 /* The size of the sidestage handle needs to be bigger than the
317 typical size used for edge detection otherwise it is really
318 hard to grab.
319 */
320 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
321 closedValue: parent.width + sideStage.handleSizeCollapsed
322 target: sideStage
323 x: parent.width - width
324 width: sideStage.width + handleSize * 0.7
325 height: sideStage.height
326 orientation: Qt.Horizontal
327 }
328 }
329 }
332 Revealer {
333 id: stagesRevealer
335 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
336 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
337 direction: Qt.RightToLeft
338 openedValue: 0
339 hintDisplacement: units.gu(3)
340 handleSize: shell.edgeSize
341 closedValue: width
342 target: stages
343 width: stages.width
344 height: stages.height
345 orientation: Qt.Horizontal
346 }
348 Lockscreen {
349 id: lockscreen
350 hides: [launcher, panel.indicators, hud]
351 shown: false
352 enabled: true
353 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
354 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
355 y: panel.panelHeight
356 x: required ? 0 : - width
357 width: parent.width
358 height: parent.height - panel.panelHeight
359 background: shell.background
361 onUnlocked: lockscreen.hide()
362 onCancel: greeter.show()
364 Component.onCompleted: {
365 if (LightDM.Users.count == 1) {
366 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
367 }
368 }
369 }
371 Connections {
372 target: LightDM.Greeter
374 onShowPrompt: {
375 if (LightDM.Users.count == 1) {
376 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
377 if (text == "PIN") {
378 lockscreen.alphaNumeric = false
379 } else {
380 lockscreen.alphaNumeric = true
381 }
382 lockscreen.placeholderText = i18n.tr("Please enter %1:").arg(text);
383 lockscreen.show();
384 }
385 }
386 }
388 Greeter {
389 id: greeter
391 available: true
392 hides: [launcher, panel.indicators, hud]
393 shown: true
394 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
395 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
396 y: panel.panelHeight
397 width: parent.width
398 height: parent.height - panel.panelHeight
400 property var previousMainApp: null
401 property var previousSideApp: null
403 onShownChanged: {
404 if (shown) {
405 lockscreen.reset();
406 // If there is only one user, we start authenticating with that one here.
407 // If there are more users, the Greeter will handle that
408 if (LightDM.Users.count == 1) {
409 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
410 }
411 greeter.forceActiveFocus();
412 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
413 // the stage was actually shown
414 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
415 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
416 applicationManager.unfocusCurrentApplication();
417 } else {
418 if (greeter.previousMainApp) {
419 applicationManager.focusApplication(greeter.previousMainApp);
420 greeter.previousMainApp = null;
421 }
422 if (greeter.previousSideApp) {
423 applicationManager.focusApplication(greeter.previousSideApp);
424 greeter.previousSideApp = null;
425 }
426 }
427 }
429 onUnlocked: greeter.hide()
430 onSelected: {
431 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
432 shell.background = bgPath ? bgPath : default_background
433 }
434 }
436 InputFilterArea {
437 anchors.fill: parent
438 blockInput: greeter.shown || lockscreen.shown
439 }
441 Revealer {
442 id: greeterRevealer
444 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
445 target: greeter
446 width: greeter.width
447 height: greeter.height
448 handleSize: shell.edgeSize
449 orientation: Qt.Horizontal
450 visible: greeter.shown
451 enabled: !greeter.locked
452 }
454 Item {
455 id: overlay
457 anchors.fill: parent
459 Panel {
460 id: panel
461 anchors.fill: parent //because this draws indicator menus
462 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
463 indicators {
464 hides: [launcher]
465 }
466 fullscreenMode: shell.fullscreenMode
467 searchVisible: !greeter.shown && !lockscreen.shown
469 InputFilterArea {
470 anchors.fill: parent
471 blockInput: panel.indicators.shown
472 }
473 }
475 Hud {
476 id: hud
478 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
479 height: parent.height
481 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown
482 shown: false
483 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
484 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
486 Connections {
487 target: shell.applicationManager
488 onMainStageFocusedApplicationChanged: hud.hide()
489 onSideStageFocusedApplicationChanged: hud.hide()
490 }
492 InputFilterArea {
493 anchors.fill: parent
494 blockInput: hud.shown
495 }
496 }
498 Revealer {
499 id: hudRevealer
501 enabled: hud.shown
502 width: hud.width
503 anchors.left: hud.left
504 height: parent.height
505 target: hud.revealerTarget
506 closedValue: height
507 openedValue: 0
508 direction: Qt.RightToLeft
509 orientation: Qt.Vertical
510 handleSize: hud.handleHeight
511 onCloseClicked: target.hide()
512 }
514 Bottombar {
515 theHud: hud
516 anchors.fill: parent
517 enabled: !panel.indicators.shown
518 }
520 InputFilterArea {
521 blockInput: launcher.shown
522 anchors {
523 top: parent.top
524 bottom: parent.bottom
525 left: parent.left
526 }
527 width: launcher.width
528 }
530 Launcher {
531 id: launcher
533 anchors.top: parent.top
534 anchors.bottom: parent.bottom
535 width: parent.width
536 dragAreaWidth: shell.edgeSize
537 available: !greeter.locked
538 teasing: available && greeter.leftTeaserPressed
539 onDashItemSelected: {
540 greeter.hide()
541 // Animate if moving between application and dash
542 if (!stages.shown) {
543 dash.setCurrentScope("home.scope", true, false)
544 } else {
545 dash.setCurrentScope("home.scope", false, false)
546 }
547 stages.hide();
548 }
549 onDash: {
550 dash.setCurrentScope("applications.scope", true, false)
551 stages.hide();
552 }
553 onLauncherApplicationSelected:{
554 greeter.hide()
555 shell.activateApplication(desktopFile)
556 }
557 onShownChanged: {
558 if (shown) {
559 panel.indicators.hide()
560 hud.hide()
561 }
562 }
563 }
565 Notifications {
566 id: notifications
568 model: NotificationBackend.Model
569 anchors {
570 top: parent.top
571 right: parent.right
572 bottom: parent.bottom
573 leftMargin: units.gu(1)
574 rightMargin: units.gu(1)
575 topMargin: panel.panelHeight + units.gu(1)
576 }
577 states: [
578 State {
579 name: "narrow"
580 when: overlay.width <= units.gu(60)
581 AnchorChanges { target: notifications; anchors.left: parent.left }
582 },
583 State {
584 name: "wide"
585 when: overlay.width > units.gu(60)
586 AnchorChanges { target: notifications; anchors.left: undefined }
587 PropertyChanges { target: notifications; width: units.gu(38) }
588 }
589 ]
590 }
591 }
593 focus: true
595 InputFilterArea {
596 anchors {
597 top: parent.top
598 bottom: parent.bottom
599 left: parent.left
600 }
601 width: shell.edgeSize
602 blockInput: true
603 }
605 InputFilterArea {
606 anchors {
607 top: parent.top
608 bottom: parent.bottom
609 right: parent.right
610 }
611 width: shell.edgeSize
612 blockInput: true
613 }
615 Binding {
616 target: i18n
617 property: "domain"
618 value: "unity8"
619 }
621 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
622 MouseArea {
623 anchors.bottom: parent.bottom
624 anchors.left: parent.left
625 anchors.right: parent.right
626 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
628 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
629 }