on 859dfd9 help sign in
unity8/Shell.qml
601 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 if (shell.applicationManager.mainStageFocusedApplication) {
222 mainStage.show();
223 stages.show();
224 }
225 }
226 onSideStageFocusedApplicationChanged: {
227 if (shell.applicationManager.sideStageFocusedApplication) {
228 sideStage.show();
229 stages.show();
230 }
231 }
232 ignoreUnknownSignals: true
233 }
236 Stage {
237 id: mainStage
239 anchors.fill: parent
240 fullyShown: stages.fullyShown
241 shouldUseScreenshots: !fullyShown
242 rightEdgeEnabled: !sideStage.enabled
244 applicationManager: shell.applicationManager
245 rightEdgeDraggingAreaWidth: shell.edgeSize
246 normalApplicationY: shell.panelHeight
248 shown: true
249 function show() {
250 stages.show();
251 }
252 function showWithoutAnimation() {
253 stages.showWithoutAnimation();
254 }
255 function hide() {
256 }
258 // FIXME: workaround the fact that focusing a main stage application
259 // raises its surface on top of all other surfaces including the ones
260 // that belong to side stage applications.
261 onFocusedApplicationChanged: {
262 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
263 shell.applicationManager.focusApplication(sideStage.focusedApplication);
264 }
265 }
266 }
268 SideStage {
269 id: sideStage
271 applicationManager: shell.applicationManager
272 rightEdgeDraggingAreaWidth: shell.edgeSize
273 normalApplicationY: shell.panelHeight
275 onShownChanged: {
276 if (!shown && mainStage.applications.count == 0) {
277 stages.hide();
278 }
279 }
280 // FIXME: when hiding the side stage, refocus the main stage
281 // application so that it goes in front of the side stage
282 // application and hides it
283 onFullyShownChanged: {
284 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
285 shell.applicationManager.focusApplication(mainStage.focusedApplication);
286 }
287 }
289 enabled: shell.width >= units.gu(60)
290 visible: enabled
291 fullyShown: stages.fullyShown && shown
292 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
293 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
295 available: !greeter.shown && !lockscreen.shown && enabled
296 hides: [launcher, panel.indicators]
297 shown: false
298 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
299 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
301 width: units.gu(40)
302 height: stages.height
303 handleExpanded: sideStageRevealer.pressed
304 }
306 Revealer {
307 id: sideStageRevealer
309 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
310 && sideStage.available
311 direction: Qt.RightToLeft
312 openedValue: parent.width - sideStage.width
313 hintDisplacement: units.gu(3)
314 /* The size of the sidestage handle needs to be bigger than the
315 typical size used for edge detection otherwise it is really
316 hard to grab.
317 */
318 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
319 closedValue: parent.width + sideStage.handleSizeCollapsed
320 target: sideStage
321 x: parent.width - width
322 width: sideStage.width + handleSize * 0.7
323 height: sideStage.height
324 orientation: Qt.Horizontal
325 }
326 }
327 }
330 Revealer {
331 id: stagesRevealer
333 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
334 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
335 direction: Qt.RightToLeft
336 openedValue: 0
337 hintDisplacement: units.gu(3)
338 handleSize: shell.edgeSize
339 closedValue: width
340 target: stages
341 width: stages.width
342 height: stages.height
343 orientation: Qt.Horizontal
344 }
346 Lockscreen {
347 id: lockscreen
348 hides: [launcher, panel.indicators, hud]
349 shown: false
350 enabled: true
351 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
352 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
353 y: panel.panelHeight
354 x: required ? 0 : - width
355 width: parent.width
356 height: parent.height - panel.panelHeight
357 background: shell.background
359 onUnlocked: lockscreen.hide()
360 onCancel: greeter.show()
362 Component.onCompleted: {
363 if (LightDM.Users.count == 1) {
364 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
365 }
366 }
367 }
369 Connections {
370 target: LightDM.Greeter
372 onShowPrompt: {
373 if (LightDM.Users.count == 1) {
374 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
375 if (text == "PIN") {
376 lockscreen.alphaNumeric = false
377 } else {
378 lockscreen.alphaNumeric = true
379 }
380 lockscreen.placeholderText = i18n.tr("Please enter %1:").arg(text);
381 lockscreen.show();
382 }
383 }
384 }
386 Greeter {
387 id: greeter
389 available: true
390 hides: [launcher, panel.indicators, hud]
391 shown: true
392 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
393 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
394 y: panel.panelHeight
395 width: parent.width
396 height: parent.height - panel.panelHeight
398 property var previousMainApp: null
399 property var previousSideApp: null
401 onShownChanged: {
402 if (shown) {
403 lockscreen.reset();
404 // If there is only one user, we start authenticating with that one here.
405 // If there are more users, the Greeter will handle that
406 if (LightDM.Users.count == 1) {
407 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
408 }
409 greeter.forceActiveFocus();
410 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
411 // the stage was actually shown
412 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
413 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
414 applicationManager.unfocusCurrentApplication();
415 } else {
416 if (greeter.previousMainApp) {
417 applicationManager.focusApplication(greeter.previousMainApp);
418 greeter.previousMainApp = null;
419 }
420 if (greeter.previousSideApp) {
421 applicationManager.focusApplication(greeter.previousSideApp);
422 greeter.previousSideApp = null;
423 }
424 }
425 }
427 onUnlocked: greeter.hide()
428 onSelected: {
429 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
430 shell.background = bgPath ? bgPath : default_background
431 }
432 }
434 InputFilterArea {
435 anchors.fill: parent
436 blockInput: greeter.shown || lockscreen.shown
437 }
439 Revealer {
440 id: greeterRevealer
442 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
443 target: greeter
444 width: greeter.width
445 height: greeter.height
446 handleSize: shell.edgeSize
447 orientation: Qt.Horizontal
448 visible: greeter.shown
449 enabled: !greeter.locked
450 }
452 Item {
453 id: overlay
455 anchors.fill: parent
457 Panel {
458 id: panel
459 anchors.fill: parent //because this draws indicator menus
460 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
461 indicators {
462 hides: [launcher]
463 }
464 fullscreenMode: shell.fullscreenMode
465 searchVisible: !greeter.shown && !lockscreen.shown
467 InputFilterArea {
468 anchors.fill: parent
469 blockInput: panel.indicators.shown
470 }
471 }
473 Hud {
474 id: hud
476 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
477 height: parent.height
479 available: !greeter.shown && !panel.indicators.shown && !lockscreen.shown
480 shown: false
481 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
482 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
484 Connections {
485 target: shell.applicationManager
486 onMainStageFocusedApplicationChanged: hud.hide()
487 onSideStageFocusedApplicationChanged: hud.hide()
488 }
490 InputFilterArea {
491 anchors.fill: parent
492 blockInput: hud.shown
493 }
494 }
496 Revealer {
497 id: hudRevealer
499 enabled: hud.shown
500 width: hud.width
501 anchors.left: hud.left
502 height: parent.height
503 target: hud.revealerTarget
504 closedValue: height
505 openedValue: 0
506 direction: Qt.RightToLeft
507 orientation: Qt.Vertical
508 handleSize: hud.handleHeight
509 onCloseClicked: target.hide()
510 }
512 Bottombar {
513 theHud: hud
514 anchors.fill: parent
515 enabled: !panel.indicators.shown
516 }
518 InputFilterArea {
519 blockInput: launcher.shown
520 anchors {
521 top: parent.top
522 bottom: parent.bottom
523 left: parent.left
524 }
525 width: launcher.width
526 }
528 Launcher {
529 id: launcher
531 anchors.top: parent.top
532 anchors.bottom: parent.bottom
533 width: parent.width
534 dragAreaWidth: shell.edgeSize
535 available: !greeter.locked
536 teasing: available && greeter.leftTeaserPressed
537 onDashItemSelected: {
538 greeter.hide()
539 // Animate if moving between application and dash
540 if (!stages.shown) {
541 dash.setCurrentScope("home.scope", true, false)
542 } else {
543 dash.setCurrentScope("home.scope", false, false)
544 }
545 stages.hide();
546 }
547 onDash: {
548 dash.setCurrentScope("applications.scope", true, false)
549 stages.hide();
550 }
551 onLauncherApplicationSelected:{
552 greeter.hide()
553 shell.activateApplication(desktopFile)
554 }
555 onShownChanged: {
556 if (shown) {
557 panel.indicators.hide()
558 hud.hide()
559 }
560 }
561 }
562 }
564 focus: true
566 InputFilterArea {
567 anchors {
568 top: parent.top
569 bottom: parent.bottom
570 left: parent.left
571 }
572 width: shell.edgeSize
573 blockInput: true
574 }
576 InputFilterArea {
577 anchors {
578 top: parent.top
579 bottom: parent.bottom
580 right: parent.right
581 }
582 width: shell.edgeSize
583 blockInput: true
584 }
586 Binding {
587 target: i18n
588 property: "domain"
589 value: "unity8"
590 }
592 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
593 MouseArea {
594 anchors.bottom: parent.bottom
595 anchors.left: parent.left
596 anchors.right: parent.right
597 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
599 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
600 }