on 320fda2 help sign in
unity8/Shell.qml
609 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: {
371 if (LightDM.Users.count == 1) {
372 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
373 }
374 }
375 }
377 Connections {
378 target: LightDM.Greeter
380 onShowPrompt: {
381 if (LightDM.Users.count == 1) {
382 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
383 if (text == "PIN") {
384 lockscreen.alphaNumeric = false
385 } else {
386 lockscreen.alphaNumeric = true
387 }
388 lockscreen.placeholderText = i18n.tr("Please enter %1:").arg(text);
389 lockscreen.show();
390 }
391 }
392 }
394 Greeter {
395 id: greeter
397 available: true
398 hides: [launcher, panel.indicators, hud]
399 shown: true
400 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
401 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
402 y: panel.panelHeight
403 width: parent.width
404 height: parent.height - panel.panelHeight
406 property var previousMainApp: null
407 property var previousSideApp: null
409 onShownChanged: {
410 if (shown) {
411 lockscreen.reset();
412 // If there is only one user, we start authenticating with that one here.
413 // If there are more users, the Greeter will handle that
414 if (LightDM.Users.count == 1) {
415 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
416 }
417 greeter.forceActiveFocus();
418 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
419 // the stage was actually shown
420 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
421 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
422 applicationManager.unfocusCurrentApplication();
423 } else {
424 if (greeter.previousMainApp) {
425 applicationManager.focusApplication(greeter.previousMainApp);
426 greeter.previousMainApp = null;
427 }
428 if (greeter.previousSideApp) {
429 applicationManager.focusApplication(greeter.previousSideApp);
430 greeter.previousSideApp = null;
431 }
432 }
433 }
435 onUnlocked: greeter.hide()
436 onSelected: {
437 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
438 shell.background = bgPath ? bgPath : default_background
439 }
440 }
442 InputFilterArea {
443 anchors.fill: parent
444 blockInput: greeter.shown || lockscreen.shown
445 }
447 Revealer {
448 id: greeterRevealer
450 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
451 target: greeter
452 width: greeter.width
453 height: greeter.height
454 handleSize: shell.edgeSize
455 orientation: Qt.Horizontal
456 visible: greeter.shown
457 enabled: !greeter.locked
458 }
460 Item {
461 id: overlay
463 anchors.fill: parent
465 Panel {
466 id: panel
467 anchors.fill: parent //because this draws indicator menus
468 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
469 indicators {
470 hides: [launcher]
471 }
472 fullscreenMode: shell.fullscreenMode
473 searchVisible: !greeter.shown && !lockscreen.shown
475 InputFilterArea {
476 anchors.fill: parent
477 blockInput: panel.indicators.shown
478 }
479 }
481 Hud {
482 id: hud
484 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
485 height: parent.height
487 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown
488 shown: false
489 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
490 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
492 Connections {
493 target: shell.applicationManager
494 onMainStageFocusedApplicationChanged: hud.hide()
495 onSideStageFocusedApplicationChanged: hud.hide()
496 }
498 InputFilterArea {
499 anchors.fill: parent
500 blockInput: hud.shown
501 }
502 }
504 Revealer {
505 id: hudRevealer
507 enabled: hud.shown
508 width: hud.width
509 anchors.left: hud.left
510 height: parent.height
511 target: hud.revealerTarget
512 closedValue: height
513 openedValue: 0
514 direction: Qt.RightToLeft
515 orientation: Qt.Vertical
516 handleSize: hud.handleHeight
517 onCloseClicked: target.hide()
518 }
520 Bottombar {
521 theHud: hud
522 anchors.fill: parent
523 enabled: !panel.indicators.shown
524 }
526 InputFilterArea {
527 blockInput: launcher.shown
528 anchors {
529 top: parent.top
530 bottom: parent.bottom
531 left: parent.left
532 }
533 width: launcher.width
534 }
536 Launcher {
537 id: launcher
539 anchors.top: parent.top
540 anchors.bottom: parent.bottom
541 width: parent.width
542 dragAreaWidth: shell.edgeSize
543 available: !greeter.locked
544 teasing: available && greeter.leftTeaserPressed
545 onDashItemSelected: {
546 greeter.hide()
547 // Animate if moving between application and dash
548 if (!stages.shown) {
549 dash.setCurrentLens("home.lens", true, false)
550 } else {
551 dash.setCurrentLens("home.lens", false, false)
552 }
553 stages.hide();
554 }
555 onDash: {
556 dash.setCurrentLens("applications.lens", true, false)
557 stages.hide();
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 }
570 }
572 focus: true
574 InputFilterArea {
575 anchors {
576 top: parent.top
577 bottom: parent.bottom
578 left: parent.left
579 }
580 width: shell.edgeSize
581 blockInput: true
582 }
584 InputFilterArea {
585 anchors {
586 top: parent.top
587 bottom: parent.bottom
588 right: parent.right
589 }
590 width: shell.edgeSize
591 blockInput: true
592 }
594 Binding {
595 target: i18n
596 property: "domain"
597 value: "unity8"
598 }
600 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
601 MouseArea {
602 anchors.bottom: parent.bottom
603 anchors.left: parent.left
604 anchors.right: parent.right
605 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
607 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
608 }