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