on 8cbde4b help sign in
unity8/Shell.qml
615 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 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 }
176 Notifications {
177 id: notifications
179 model: NotificationBackend.Model
180 anchors {
181 fill: parent
182 leftMargin: units.gu(1)
183 rightMargin: units.gu(1)
184 topMargin: panel.panelHeight + units.gu(1)
185 }
186 }
187 }
190 Item {
192 width: parent.width
193 height: parent.height
194 x: launcher.progress
195 Behavior on x {SmoothedAnimation{velocity: 600}}
198 Showable {
199 id: stages
201 property bool fullyShown: shown && stages[stagesRevealer.boundProperty] == stagesRevealer.openedValue
202 && parent.x == 0
203 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
204 available: !greeter.shown
205 hides: [launcher, panel.indicators]
206 shown: false
207 opacity: 1.0
208 showAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.openedValue; easing.type: Easing.OutCubic }
209 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.closedValue; easing.type: Easing.OutCubic }
211 width: parent.width
212 height: parent.height
214 // close the stages when no focused application remains
215 Connections {
216 target: shell.applicationManager
217 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
218 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
219 ignoreUnknownSignals: true
220 }
222 function closeIfNoApplications() {
223 if (!shell.applicationManager.mainStageFocusedApplication
224 && !shell.applicationManager.sideStageFocusedApplication
225 && shell.applicationManager.mainStageApplications.count == 0
226 && shell.applicationManager.sideStageApplications.count == 0) {
227 stages.hide();
228 }
229 }
231 // show the stages when an application gets the focus
232 Connections {
233 target: shell.applicationManager
234 onMainStageFocusedApplicationChanged: {
235 if (shell.applicationManager.mainStageFocusedApplication) {
236 mainStage.show();
237 stages.show();
238 }
239 }
240 onSideStageFocusedApplicationChanged: {
241 if (shell.applicationManager.sideStageFocusedApplication) {
242 sideStage.show();
243 stages.show();
244 }
245 }
246 ignoreUnknownSignals: true
247 }
250 Stage {
251 id: mainStage
253 anchors.fill: parent
254 fullyShown: stages.fullyShown
255 shouldUseScreenshots: !fullyShown
256 rightEdgeEnabled: !sideStage.enabled
258 applicationManager: shell.applicationManager
259 rightEdgeDraggingAreaWidth: shell.edgeSize
260 normalApplicationY: shell.panelHeight
262 shown: true
263 function show() {
264 stages.show();
265 }
266 function showWithoutAnimation() {
267 stages.showWithoutAnimation();
268 }
269 function hide() {
270 }
272 // FIXME: workaround the fact that focusing a main stage application
273 // raises its surface on top of all other surfaces including the ones
274 // that belong to side stage applications.
275 onFocusedApplicationChanged: {
276 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
277 shell.applicationManager.focusApplication(sideStage.focusedApplication);
278 }
279 }
280 }
282 SideStage {
283 id: sideStage
285 applicationManager: shell.applicationManager
286 rightEdgeDraggingAreaWidth: shell.edgeSize
287 normalApplicationY: shell.panelHeight
289 onShownChanged: {
290 if (!shown && mainStage.applications.count == 0) {
291 stages.hide();
292 }
293 }
294 // FIXME: when hiding the side stage, refocus the main stage
295 // application so that it goes in front of the side stage
296 // application and hides it
297 onFullyShownChanged: {
298 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
299 shell.applicationManager.focusApplication(mainStage.focusedApplication);
300 }
301 }
303 enabled: shell.width >= units.gu(60)
304 visible: enabled
305 fullyShown: stages.fullyShown && shown
306 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
307 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
309 available: !greeter.shown && !lockscreen.shown && enabled
310 hides: [launcher, panel.indicators]
311 shown: false
312 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
313 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
315 width: units.gu(40)
316 height: stages.height
317 handleExpanded: sideStageRevealer.pressed
318 }
320 Revealer {
321 id: sideStageRevealer
323 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
324 && sideStage.available
325 direction: Qt.RightToLeft
326 openedValue: parent.width - sideStage.width
327 hintDisplacement: units.gu(3)
328 /* The size of the sidestage handle needs to be bigger than the
329 typical size used for edge detection otherwise it is really
330 hard to grab.
331 */
332 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
333 closedValue: parent.width + sideStage.handleSizeCollapsed
334 target: sideStage
335 x: parent.width - width
336 width: sideStage.width + handleSize * 0.7
337 height: sideStage.height
338 orientation: Qt.Horizontal
339 }
340 }
341 }
344 Revealer {
345 id: stagesRevealer
347 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
348 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
349 direction: Qt.RightToLeft
350 openedValue: 0
351 hintDisplacement: units.gu(3)
352 handleSize: shell.edgeSize
353 closedValue: width
354 target: stages
355 width: stages.width
356 height: stages.height
357 orientation: Qt.Horizontal
358 }
360 Lockscreen {
361 id: lockscreen
362 hides: [launcher, panel.indicators, hud]
363 shown: false
364 enabled: true
365 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
366 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
367 y: panel.panelHeight
368 x: required ? 0 : - width
369 width: parent.width
370 height: parent.height - panel.panelHeight
371 background: shell.background
373 onUnlocked: lockscreen.hide()
374 onCancel: greeter.show()
376 Component.onCompleted: {
377 if (LightDM.Users.count == 1) {
378 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
379 }
380 }
381 }
383 Connections {
384 target: LightDM.Greeter
386 onShowPrompt: {
387 if (LightDM.Users.count == 1) {
388 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
389 if (text == "PIN") {
390 lockscreen.alphaNumeric = false
391 } else {
392 lockscreen.alphaNumeric = true
393 }
394 lockscreen.placeholderText = i18n.tr("Please enter %1:").arg(text);
395 lockscreen.show();
396 }
397 }
398 }
400 Greeter {
401 id: greeter
403 available: true
404 hides: [launcher, panel.indicators, hud]
405 shown: true
406 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
407 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
408 y: panel.panelHeight
409 width: parent.width
410 height: parent.height - panel.panelHeight
412 property var previousMainApp: null
413 property var previousSideApp: null
415 onShownChanged: {
416 if (shown) {
417 lockscreen.reset();
418 // If there is only one user, we start authenticating with that one here.
419 // If there are more users, the Greeter will handle that
420 if (LightDM.Users.count == 1) {
421 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
422 }
423 greeter.forceActiveFocus();
424 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
425 // the stage was actually shown
426 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
427 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
428 applicationManager.unfocusCurrentApplication();
429 } else {
430 if (greeter.previousMainApp) {
431 applicationManager.focusApplication(greeter.previousMainApp);
432 greeter.previousMainApp = null;
433 }
434 if (greeter.previousSideApp) {
435 applicationManager.focusApplication(greeter.previousSideApp);
436 greeter.previousSideApp = null;
437 }
438 }
439 }
441 onUnlocked: greeter.hide()
442 onSelected: {
443 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
444 shell.background = bgPath ? bgPath : default_background
445 }
446 }
448 InputFilterArea {
449 anchors.fill: parent
450 blockInput: greeter.shown || lockscreen.shown
451 }
453 Revealer {
454 id: greeterRevealer
456 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
457 target: greeter
458 width: greeter.width
459 height: greeter.height
460 handleSize: shell.edgeSize
461 orientation: Qt.Horizontal
462 visible: greeter.shown
463 enabled: !greeter.locked
464 }
466 Item {
467 id: overlay
469 anchors.fill: parent
471 Panel {
472 id: panel
473 anchors.fill: parent //because this draws indicator menus
474 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
475 indicators {
476 hides: [launcher]
477 }
478 fullscreenMode: shell.fullscreenMode
479 searchVisible: !greeter.shown && !lockscreen.shown
481 InputFilterArea {
482 anchors.fill: parent
483 blockInput: panel.indicators.shown
484 }
485 }
487 Hud {
488 id: hud
490 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
491 height: parent.height
493 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown
494 shown: false
495 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
496 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
498 Connections {
499 target: shell.applicationManager
500 onMainStageFocusedApplicationChanged: hud.hide()
501 onSideStageFocusedApplicationChanged: hud.hide()
502 }
504 InputFilterArea {
505 anchors.fill: parent
506 blockInput: hud.shown
507 }
508 }
510 Revealer {
511 id: hudRevealer
513 enabled: hud.shown
514 width: hud.width
515 anchors.left: hud.left
516 height: parent.height
517 target: hud.revealerTarget
518 closedValue: height
519 openedValue: 0
520 direction: Qt.RightToLeft
521 orientation: Qt.Vertical
522 handleSize: hud.handleHeight
523 onCloseClicked: target.hide()
524 }
526 Bottombar {
527 theHud: hud
528 anchors.fill: parent
529 enabled: !panel.indicators.shown
530 }
532 InputFilterArea {
533 blockInput: launcher.shown
534 anchors {
535 top: parent.top
536 bottom: parent.bottom
537 left: parent.left
538 }
539 width: launcher.width
540 }
542 Launcher {
543 id: launcher
545 anchors.top: parent.top
546 anchors.bottom: parent.bottom
547 width: parent.width
548 dragAreaWidth: shell.edgeSize
549 available: !greeter.locked
550 teasing: available && greeter.leftTeaserPressed
551 onDashItemSelected: {
552 greeter.hide()
553 // Animate if moving between application and dash
554 if (!stages.shown) {
555 dash.setCurrentScope("home.scope", true, false)
556 } else {
557 dash.setCurrentScope("home.scope", false, false)
558 }
559 stages.hide();
560 }
561 onDash: {
562 dash.setCurrentScope("applications.scope", true, false)
563 stages.hide();
564 }
565 onLauncherApplicationSelected:{
566 greeter.hide()
567 shell.activateApplication(desktopFile)
568 }
569 onShownChanged: {
570 if (shown) {
571 panel.indicators.hide()
572 hud.hide()
573 }
574 }
575 }
576 }
578 focus: true
580 InputFilterArea {
581 anchors {
582 top: parent.top
583 bottom: parent.bottom
584 left: parent.left
585 }
586 width: shell.edgeSize
587 blockInput: true
588 }
590 InputFilterArea {
591 anchors {
592 top: parent.top
593 bottom: parent.bottom
594 right: parent.right
595 }
596 width: shell.edgeSize
597 blockInput: true
598 }
600 Binding {
601 target: i18n
602 property: "domain"
603 value: "unity8"
604 }
606 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
607 MouseArea {
608 anchors.bottom: parent.bottom
609 anchors.left: parent.left
610 anchors.right: parent.right
611 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
613 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
614 }