on 127756e help sign in
unity8/Shell.qml
603 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
189 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
190 available: !greeter.shown
191 hides: [launcher, panel.indicators]
192 shown: false
193 opacity: 1.0
194 showAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.openedValue; easing.type: Easing.OutCubic }
195 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.closedValue; easing.type: Easing.OutCubic }
197 width: parent.width
198 height: parent.height
200 // close the stages when no focused application remains
201 Connections {
202 target: shell.applicationManager
203 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
204 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
205 ignoreUnknownSignals: true
206 }
208 function closeIfNoApplications() {
209 if (!shell.applicationManager.mainStageFocusedApplication
210 && !shell.applicationManager.sideStageFocusedApplication
211 && shell.applicationManager.mainStageApplications.count == 0
212 && shell.applicationManager.sideStageApplications.count == 0) {
213 stages.hide();
214 }
215 }
217 // show the stages when an application gets the focus
218 Connections {
219 target: shell.applicationManager
220 onMainStageFocusedApplicationChanged: {
221 handleFocusedApplicationChange(mainStage, shell.applicationManager.mainStageFocusedApplication);
222 }
223 onSideStageFocusedApplicationChanged: {
224 handleFocusedApplicationChange(sideStage, shell.applicationManager.sideStageFocusedApplication);
225 }
226 ignoreUnknownSignals: true
228 function handleFocusedApplicationChange(stage, application) {
229 if (stages.shown) {
230 if (application) {
231 stage.show();
232 stages.show();
233 }
234 } else {
235 // focus changed while shell in foreground, ensure app remains unfocused
236 if (application) {
237 shell.applicationManager.unfocusCurrentApplication();
238 }
239 }
240 }
241 }
244 Stage {
245 id: mainStage
247 anchors.fill: parent
248 fullyShown: stages.fullyShown
249 shouldUseScreenshots: !fullyShown
250 rightEdgeEnabled: !sideStage.enabled
252 applicationManager: shell.applicationManager
253 rightEdgeDraggingAreaWidth: shell.edgeSize
254 normalApplicationY: shell.panelHeight
256 shown: true
257 function show() {
258 stages.show();
259 }
260 function showWithoutAnimation() {
261 stages.showWithoutAnimation();
262 }
263 function hide() {
264 }
266 // FIXME: workaround the fact that focusing a main stage application
267 // raises its surface on top of all other surfaces including the ones
268 // that belong to side stage applications.
269 onFocusedApplicationChanged: {
270 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
271 shell.applicationManager.focusApplication(sideStage.focusedApplication);
272 }
273 }
274 }
276 SideStage {
277 id: sideStage
279 applicationManager: shell.applicationManager
280 rightEdgeDraggingAreaWidth: shell.edgeSize
281 normalApplicationY: shell.panelHeight
283 onShownChanged: {
284 if (!shown && mainStage.applications.count == 0) {
285 stages.hide();
286 }
287 }
288 // FIXME: when hiding the side stage, refocus the main stage
289 // application so that it goes in front of the side stage
290 // application and hides it
291 onFullyShownChanged: {
292 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
293 shell.applicationManager.focusApplication(mainStage.focusedApplication);
294 }
295 }
297 enabled: shell.width >= units.gu(60)
298 visible: enabled
299 fullyShown: stages.fullyShown && shown
300 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
301 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
303 available: !greeter.shown && !lockscreen.shown && enabled
304 hides: [launcher, panel.indicators]
305 shown: false
306 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
307 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
309 width: units.gu(40)
310 height: stages.height
311 handleExpanded: sideStageRevealer.pressed
312 }
314 Revealer {
315 id: sideStageRevealer
317 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
318 && sideStage.available
319 direction: Qt.RightToLeft
320 openedValue: parent.width - sideStage.width
321 hintDisplacement: units.gu(3)
322 /* The size of the sidestage handle needs to be bigger than the
323 typical size used for edge detection otherwise it is really
324 hard to grab.
325 */
326 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
327 closedValue: parent.width + sideStage.handleSizeCollapsed
328 target: sideStage
329 x: parent.width - width
330 width: sideStage.width + handleSize * 0.7
331 height: sideStage.height
332 orientation: Qt.Horizontal
333 }
334 }
335 }
338 Revealer {
339 id: stagesRevealer
341 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
342 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
343 direction: Qt.RightToLeft
344 openedValue: 0
345 hintDisplacement: units.gu(3)
346 handleSize: shell.edgeSize
347 closedValue: width
348 target: stages
349 width: stages.width
350 height: stages.height
351 orientation: Qt.Horizontal
352 }
354 Lockscreen {
355 id: lockscreen
356 hides: [launcher, panel.indicators, hud]
357 shown: false
358 enabled: true
359 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
360 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
361 y: panel.panelHeight
362 x: required ? 0 : - width
363 width: parent.width
364 height: parent.height - panel.panelHeight
365 background: shell.background
367 onUnlocked: lockscreen.hide()
368 onCancel: greeter.show()
370 Component.onCompleted: LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
371 }
373 Connections {
374 target: LightDM.Greeter
376 onShowPrompt: {
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 }
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.setCurrentLens("home.lens", true, false)
544 } else {
545 dash.setCurrentLens("home.lens", false, false)
546 }
547 stages.hide();
548 }
549 onDash: {
550 dash.setCurrentLens("applications.lens", 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 }
564 }
566 focus: true
568 InputFilterArea {
569 anchors {
570 top: parent.top
571 bottom: parent.bottom
572 left: parent.left
573 }
574 width: shell.edgeSize
575 blockInput: true
576 }
578 InputFilterArea {
579 anchors {
580 top: parent.top
581 bottom: parent.bottom
582 right: parent.right
583 }
584 width: shell.edgeSize
585 blockInput: true
586 }
588 Binding {
589 target: i18n
590 property: "domain"
591 value: "unity8"
592 }
594 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
595 MouseArea {
596 anchors.bottom: parent.bottom
597 anchors.left: parent.left
598 anchors.right: parent.right
599 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
601 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
602 }