on 7635691 help sign in
unity8/Shell.qml
604 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"
31FocusScope {
32 id: shell
34 // this is only here to select the width / height of the window if not running fullscreen
35 property bool tablet: false
36 width: tablet ? units.gu(160) : units.gu(40)
37 height: tablet ? units.gu(100) : units.gu(71)
39 property real edgeSize: units.gu(2)
40 property url default_background: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
41 property url background: default_background
42 readonly property real panelHeight: panel.panelHeight
44 property bool dashShown: dash.shown
45 property bool stageScreenshotsReady: {
46 if (sideStage.shown) {
47 if (mainStage.applications.count > 0) {
48 return mainStage.usingScreenshots && sideStage.usingScreenshots;
49 } else {
50 return sideStage.usingScreenshots;
51 }
52 } else {
53 return mainStage.usingScreenshots;
54 }
55 }
57 property ListModel searchHistory: SearchHistoryModel {}
59 property var applicationManager: ApplicationManagerWrapper {}
61 Component.onCompleted: {
62 applicationManager.sideStageEnabled = Qt.binding(function() { return sideStage.enabled })
64 // FIXME: if application focused before shell starts, shell draws on top of it only.
65 // We should detect already running applications on shell start and bring them to the front.
66 applicationManager.unfocusCurrentApplication();
67 }
69 readonly property bool fullscreenMode: {
70 if (greeter.shown || lockscreen.shown) {
71 return false;
72 } else if (mainStage.usingScreenshots) { // Window Manager animating so want to re-evaluate fullscreen mode
73 return mainStage.switchingFromFullscreenToFullscreen;
74 } else if (applicationManager.mainStageFocusedApplication) {
75 return applicationManager.mainStageFocusedApplication.fullscreen;
76 } else {
77 return false;
78 }
79 }
81 Connections {
82 target: applicationManager
83 ignoreUnknownSignals: true
84 onFocusRequested: {
85 // TODO: this should be protected to only unlock for certain applications / certain usecases
86 // potentially only in connection with a notification
87 greeter.hide();
88 shell.activateApplication(desktopFile);
89 }
90 }
92 function activateApplication(desktopFile, argument) {
93 if (applicationManager) {
94 // For newly started applications, as it takes them time to draw their first frame
95 // we add a delay before we hide the animation screenshots to compensate.
96 var addDelay = !applicationManager.getApplicationFromDesktopFile(desktopFile);
98 var application;
99 application = applicationManager.activateApplication(desktopFile, argument);
100 if (application == null) {
101 return;
102 }
103 if (application.stage == ApplicationInfo.MainStage || !sideStage.enabled) {
104 mainStage.activateApplication(desktopFile, addDelay);
105 } else {
106 sideStage.activateApplication(desktopFile, addDelay);
107 }
108 stages.show();
109 }
110 }
112 VolumeControl {
113 id: volumeControl
114 }
116 Keys.onVolumeUpPressed: volumeControl.volumeUp()
117 Keys.onVolumeDownPressed: volumeControl.volumeDown()
119 Keys.onReleased: {
120 if (event.key == Qt.Key_PowerOff) {
121 greeter.show()
122 }
123 }
125 Item {
126 id: underlay
127 anchors.fill: parent
128 visible: !(panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth)
129 && (stages.fullyHidden
130 || (stages.fullyShown && mainStage.usingScreenshots)
131 || !stages.fullyShown && (mainStage.usingScreenshots || (sideStage.shown && sideStage.usingScreenshots)))
133 Image {
134 id: backgroundImage
135 source: shell.background
136 sourceSize.width: parent.width
137 sourceSize.height: parent.height
138 anchors.fill: parent
139 }
141 Rectangle {
142 anchors.fill: parent
143 color: "black"
144 opacity: dash.disappearingAnimationProgress
145 }
147 Dash {
148 id: dash
150 available: !greeter.shown && !lockscreen.shown
151 hides: [stages, launcher, panel.indicators]
152 shown: disappearingAnimationProgress !== 1.0
153 enabled: disappearingAnimationProgress === 0.0
154 // FIXME: unfocus all applications when going back to the dash
155 onEnabledChanged: {
156 if (enabled) {
157 shell.applicationManager.unfocusCurrentApplication()
158 }
159 }
161 anchors {
162 fill: parent
163 topMargin: panel.panelHeight
164 }
166 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
167 opacity: 1.0 - disappearingAnimationProgress
168 property real disappearingAnimationProgress: ((greeter.shown) ? greeterRevealer.animatedProgress : stagesRevealer.animatedProgress)
169 // FIXME: only necessary because stagesRevealer.animatedProgress and
170 // greeterRevealer.animatedProgress are not animated
171 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
172 }
173 }
176 Item {
178 width: parent.width
179 height: parent.height
180 x: launcher.progress
181 Behavior on x {SmoothedAnimation{velocity: 600}}
184 Showable {
185 id: stages
187 property bool fullyShown: shown && stages[stagesRevealer.boundProperty] == stagesRevealer.openedValue
188 && parent.x == 0
190 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
191 available: !greeter.shown
192 hides: [launcher, panel.indicators]
193 shown: false
194 opacity: 1.0
195 showAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.openedValue; easing.type: Easing.OutCubic }
196 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.closedValue; easing.type: Easing.OutCubic }
198 width: parent.width
199 height: parent.height
201 // close the stages when no focused application remains
202 Connections {
203 target: shell.applicationManager
204 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
205 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
206 ignoreUnknownSignals: true
207 }
209 function closeIfNoApplications() {
210 if (!shell.applicationManager.mainStageFocusedApplication
211 && !shell.applicationManager.sideStageFocusedApplication
212 && shell.applicationManager.mainStageApplications.count == 0
213 && shell.applicationManager.sideStageApplications.count == 0) {
214 stages.hide();
215 }
216 }
218 // show the stages when an application gets the focus
219 Connections {
220 target: shell.applicationManager
221 onMainStageFocusedApplicationChanged: {
222 if (shell.applicationManager.mainStageFocusedApplication) {
223 mainStage.show();
224 stages.show();
225 }
226 }
227 onSideStageFocusedApplicationChanged: {
228 if (shell.applicationManager.sideStageFocusedApplication) {
229 sideStage.show();
230 stages.show();
231 }
232 }
233 ignoreUnknownSignals: true
234 }
237 Stage {
238 id: mainStage
240 anchors.fill: parent
241 fullyShown: stages.fullyShown
242 shouldUseScreenshots: !fullyShown
243 rightEdgeEnabled: !sideStage.enabled
245 applicationManager: shell.applicationManager
246 rightEdgeDraggingAreaWidth: shell.edgeSize
247 normalApplicationY: shell.panelHeight
249 shown: true
250 function show() {
251 stages.show();
252 }
253 function showWithoutAnimation() {
254 stages.showWithoutAnimation();
255 }
256 function hide() {
257 }
259 // FIXME: workaround the fact that focusing a main stage application
260 // raises its surface on top of all other surfaces including the ones
261 // that belong to side stage applications.
262 onFocusedApplicationChanged: {
263 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
264 shell.applicationManager.focusApplication(sideStage.focusedApplication);
265 }
266 }
267 }
269 SideStage {
270 id: sideStage
272 applicationManager: shell.applicationManager
273 rightEdgeDraggingAreaWidth: shell.edgeSize
274 normalApplicationY: shell.panelHeight
276 onShownChanged: {
277 if (!shown && mainStage.applications.count == 0) {
278 stages.hide();
279 }
280 }
281 // FIXME: when hiding the side stage, refocus the main stage
282 // application so that it goes in front of the side stage
283 // application and hides it
284 onFullyShownChanged: {
285 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
286 shell.applicationManager.focusApplication(mainStage.focusedApplication);
287 }
288 }
290 enabled: shell.width >= units.gu(60)
291 visible: enabled
292 fullyShown: stages.fullyShown && shown
293 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
294 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
296 available: !greeter.shown && !lockscreen.shown && enabled
297 hides: [launcher, panel.indicators]
298 shown: false
299 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
300 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
302 width: units.gu(40)
303 height: stages.height
304 handleExpanded: sideStageRevealer.pressed
305 }
307 Revealer {
308 id: sideStageRevealer
310 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
311 && sideStage.available
312 direction: Qt.RightToLeft
313 openedValue: parent.width - sideStage.width
314 hintDisplacement: units.gu(3)
315 /* The size of the sidestage handle needs to be bigger than the
316 typical size used for edge detection otherwise it is really
317 hard to grab.
318 */
319 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
320 closedValue: parent.width + sideStage.handleSizeCollapsed
321 target: sideStage
322 x: parent.width - width
323 width: sideStage.width + handleSize * 0.7
324 height: sideStage.height
325 orientation: Qt.Horizontal
326 }
327 }
328 }
331 Revealer {
332 id: stagesRevealer
334 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
335 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
336 direction: Qt.RightToLeft
337 openedValue: 0
338 hintDisplacement: units.gu(3)
339 handleSize: shell.edgeSize
340 closedValue: width
341 target: stages
342 width: stages.width
343 height: stages.height
344 orientation: Qt.Horizontal
345 }
347 Lockscreen {
348 id: lockscreen
349 hides: [launcher, panel.indicators, hud]
350 shown: false
351 enabled: true
352 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
353 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
354 y: panel.panelHeight
355 x: required ? 0 : - width
356 width: parent.width
357 height: parent.height - panel.panelHeight
358 background: shell.background
360 onUnlocked: lockscreen.hide()
361 onCancel: greeter.show()
363 Component.onCompleted: {
364 if (LightDM.Users.count == 1) {
365 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
366 }
367 }
368 }
370 Connections {
371 target: LightDM.Greeter
373 onShowPrompt: {
374 if (LightDM.Users.count == 1) {
375 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
376 if (text == "PIN") {
377 lockscreen.alphaNumeric = false
378 } else {
379 lockscreen.alphaNumeric = true
380 }
381 lockscreen.placeholderText = i18n.tr("Please enter %1:").arg(text);
382 lockscreen.show();
383 }
384 }
385 }
387 Greeter {
388 id: greeter
390 available: true
391 hides: [launcher, panel.indicators, hud]
392 shown: true
393 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
394 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
395 y: panel.panelHeight
396 width: parent.width
397 height: parent.height - panel.panelHeight
399 property var previousMainApp: null
400 property var previousSideApp: null
402 onShownChanged: {
403 if (shown) {
404 lockscreen.reset();
405 // If there is only one user, we start authenticating with that one here.
406 // If there are more users, the Greeter will handle that
407 if (LightDM.Users.count == 1) {
408 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
409 }
410 greeter.forceActiveFocus();
411 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
412 // the stage was actually shown
413 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
414 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
415 applicationManager.unfocusCurrentApplication();
416 } else {
417 if (greeter.previousMainApp) {
418 applicationManager.focusApplication(greeter.previousMainApp);
419 greeter.previousMainApp = null;
420 }
421 if (greeter.previousSideApp) {
422 applicationManager.focusApplication(greeter.previousSideApp);
423 greeter.previousSideApp = null;
424 }
425 }
426 }
428 onUnlocked: greeter.hide()
429 onSelected: {
430 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
431 shell.background = bgPath ? bgPath : default_background
432 }
433 }
435 InputFilterArea {
436 anchors.fill: parent
437 blockInput: greeter.shown || lockscreen.shown
438 }
440 Revealer {
441 id: greeterRevealer
443 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
444 target: greeter
445 width: greeter.width
446 height: greeter.height
447 handleSize: shell.edgeSize
448 orientation: Qt.Horizontal
449 visible: greeter.shown
450 enabled: !greeter.locked
451 }
453 Item {
454 id: overlay
456 anchors.fill: parent
458 Panel {
459 id: panel
460 anchors.fill: parent //because this draws indicator menus
461 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
462 indicators {
463 hides: [launcher]
464 }
465 fullscreenMode: shell.fullscreenMode
466 searchVisible: !greeter.shown && !lockscreen.shown
468 InputFilterArea {
469 anchors.fill: parent
470 blockInput: panel.indicators.shown
471 }
472 }
474 Hud {
475 id: hud
477 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
478 height: parent.height
480 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown
481 shown: false
482 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
483 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
485 Connections {
486 target: shell.applicationManager
487 onMainStageFocusedApplicationChanged: hud.hide()
488 onSideStageFocusedApplicationChanged: hud.hide()
489 }
491 InputFilterArea {
492 anchors.fill: parent
493 blockInput: hud.shown
494 }
495 }
497 Revealer {
498 id: hudRevealer
500 enabled: hud.shown
501 width: hud.width
502 anchors.left: hud.left
503 height: parent.height
504 target: hud.revealerTarget
505 closedValue: height
506 openedValue: 0
507 direction: Qt.RightToLeft
508 orientation: Qt.Vertical
509 handleSize: hud.handleHeight
510 onCloseClicked: target.hide()
511 }
513 Bottombar {
514 theHud: hud
515 anchors.fill: parent
516 enabled: !panel.indicators.shown
517 applicationIsOnForeground: applicationManager.mainStageFocusedApplication
518 || applicationManager.sideStageFocusedApplication
519 }
521 InputFilterArea {
522 blockInput: launcher.shown
523 anchors {
524 top: parent.top
525 bottom: parent.bottom
526 left: parent.left
527 }
528 width: launcher.width
529 }
531 Launcher {
532 id: launcher
534 anchors.top: parent.top
535 anchors.bottom: parent.bottom
536 width: parent.width
537 dragAreaWidth: shell.edgeSize
538 available: !greeter.locked
539 teasing: available && greeter.leftTeaserPressed
540 onDashItemSelected: {
541 greeter.hide()
542 // Animate if moving between application and dash
543 if (!stages.shown) {
544 dash.setCurrentLens("home.lens", true, false)
545 } else {
546 dash.setCurrentLens("home.lens", false, false)
547 }
548 stages.hide();
549 }
550 onDash: {
551 dash.setCurrentLens("applications.lens", true, false)
552 stages.hide();
553 }
554 onLauncherApplicationSelected:{
555 greeter.hide()
556 shell.activateApplication(desktopFile)
557 }
558 onShownChanged: {
559 if (shown) {
560 panel.indicators.hide()
561 hud.hide()
562 }
563 }
564 }
565 }
567 focus: true
569 InputFilterArea {
570 anchors {
571 top: parent.top
572 bottom: parent.bottom
573 left: parent.left
574 }
575 width: shell.edgeSize
576 blockInput: true
577 }
579 InputFilterArea {
580 anchors {
581 top: parent.top
582 bottom: parent.bottom
583 right: parent.right
584 }
585 width: shell.edgeSize
586 blockInput: true
587 }
589 Binding {
590 target: i18n
591 property: "domain"
592 value: "unity8"
593 }
595 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
596 MouseArea {
597 anchors.bottom: parent.bottom
598 anchors.left: parent.left
599 anchors.right: parent.right
600 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
602 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
603 }