on ea4e082 help sign in
unity8/Shell.qml
579 lines 21 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
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) {
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
130 anchors.fill: parent
131 visible: !(panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth)
132 && (stages.fullyHidden
133 || (stages.fullyShown && mainStage.usingScreenshots)
134 || !stages.fullyShown && (mainStage.usingScreenshots || (sideStage.shown && sideStage.usingScreenshots)))
136 Image {
137 id: backgroundImage
138 source: shell.background
139 sourceSize.width: parent.width
140 sourceSize.height: parent.height
141 anchors.fill: parent
142 }
144 Rectangle {
145 anchors.fill: parent
146 color: "black"
147 opacity: dash.disappearingAnimationProgress
148 }
150 Dash {
151 id: dash
153 available: !greeter.shown
154 hides: [stages, launcher, panel.indicators]
155 shown: disappearingAnimationProgress !== 1.0
156 enabled: disappearingAnimationProgress === 0.0
157 // FIXME: unfocus all applications when going back to the dash
158 onEnabledChanged: {
159 if (enabled) {
160 shell.applicationManager.unfocusCurrentApplication()
161 }
162 }
164 anchors {
165 fill: parent
166 topMargin: panel.panelHeight
167 }
169 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
170 opacity: 1.0 - disappearingAnimationProgress
171 property real disappearingAnimationProgress: ((greeter.shown) ? greeterRevealer.animatedProgress : stagesRevealer.animatedProgress)
172 // FIXME: only necessary because stagesRevealer.animatedProgress and
173 // greeterRevealer.animatedProgress are not animated
174 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
175 }
177 Notifications {
178 id: notifications
180 model: Model
181 anchors {
182 fill: parent
183 leftMargin: units.gu(1)
184 rightMargin: units.gu(1)
185 topMargin: panel.panelHeight + units.gu(1)
186 }
187 }
188 }
191 Item {
193 width: parent.width
194 height: parent.height
195 x: launcher.progress
196 Behavior on x {SmoothedAnimation{velocity: 600}}
199 Showable {
200 id: stages
202 property bool fullyShown: shown && stages[stagesRevealer.boundProperty] == stagesRevealer.openedValue
203 && parent.x == 0
204 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
205 available: !greeter.shown
206 hides: [launcher, panel.indicators]
207 shown: false
208 opacity: 1.0
209 showAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.openedValue; easing.type: Easing.OutCubic }
210 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: stagesRevealer.closedValue; easing.type: Easing.OutCubic }
212 width: parent.width
213 height: parent.height
215 // close the stages when no focused application remains
216 Connections {
217 target: shell.applicationManager
218 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
219 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
220 ignoreUnknownSignals: true
221 }
223 function closeIfNoApplications() {
224 if (!shell.applicationManager.mainStageFocusedApplication
225 && !shell.applicationManager.sideStageFocusedApplication
226 && shell.applicationManager.mainStageApplications.count == 0
227 && shell.applicationManager.sideStageApplications.count == 0) {
228 stages.hide();
229 }
230 }
232 // show the stages when an application gets the focus
233 Connections {
234 target: shell.applicationManager
235 onMainStageFocusedApplicationChanged: {
236 handleFocusedApplicationChange(mainStage, shell.applicationManager.mainStageFocusedApplication);
237 }
238 onSideStageFocusedApplicationChanged: {
239 handleFocusedApplicationChange(sideStage, shell.applicationManager.sideStageFocusedApplication);
240 }
241 ignoreUnknownSignals: true
243 function handleFocusedApplicationChange(stage, application) {
244 if (stages.shown) {
245 if (application) {
246 stage.show();
247 stages.show();
248 }
249 } else {
250 // focus changed while shell in foreground, ensure app remains unfocused
251 if (application) {
252 shell.applicationManager.unfocusCurrentApplication();
253 }
254 }
255 }
256 }
259 Stage {
260 id: mainStage
262 anchors.fill: parent
263 fullyShown: stages.fullyShown
264 shouldUseScreenshots: !fullyShown
265 rightEdgeEnabled: !sideStage.enabled
267 applicationManager: shell.applicationManager
268 rightEdgeDraggingAreaWidth: shell.edgeSize
269 normalApplicationY: shell.panelHeight
271 shown: true
272 function show() {
273 stages.show();
274 }
275 function showWithoutAnimation() {
276 stages.showWithoutAnimation();
277 }
278 function hide() {
279 }
281 // FIXME: workaround the fact that focusing a main stage application
282 // raises its surface on top of all other surfaces including the ones
283 // that belong to side stage applications.
284 onFocusedApplicationChanged: {
285 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
286 shell.applicationManager.focusApplication(sideStage.focusedApplication);
287 }
288 }
289 }
291 SideStage {
292 id: sideStage
294 applicationManager: shell.applicationManager
295 rightEdgeDraggingAreaWidth: shell.edgeSize
296 normalApplicationY: shell.panelHeight
298 onShownChanged: {
299 if (!shown && mainStage.applications.count == 0) {
300 stages.hide();
301 }
302 }
303 // FIXME: when hiding the side stage, refocus the main stage
304 // application so that it goes in front of the side stage
305 // application and hides it
306 onFullyShownChanged: {
307 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
308 shell.applicationManager.focusApplication(mainStage.focusedApplication);
309 }
310 }
312 enabled: shell.width >= units.gu(60)
313 visible: enabled
314 fullyShown: stages.fullyShown && shown
315 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
316 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
318 available: !greeter.shown && enabled
319 hides: [launcher, panel.indicators]
320 shown: false
321 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
322 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
324 width: units.gu(40)
325 height: stages.height
326 handleExpanded: sideStageRevealer.pressed
327 }
329 Revealer {
330 id: sideStageRevealer
332 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
333 && sideStage.available
334 direction: Qt.RightToLeft
335 openedValue: parent.width - sideStage.width
336 hintDisplacement: units.gu(3)
337 /* The size of the sidestage handle needs to be bigger than the
338 typical size used for edge detection otherwise it is really
339 hard to grab.
340 */
341 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
342 closedValue: parent.width + sideStage.handleSizeCollapsed
343 target: sideStage
344 x: parent.width - width
345 width: sideStage.width + handleSize * 0.7
346 height: sideStage.height
347 orientation: Qt.Horizontal
348 }
349 }
350 }
353 Revealer {
354 id: stagesRevealer
356 property real animatedProgress: MathLocal.clamp((-dragPosition - launcher.progress) / closedValue, 0, 1)
357 enabled: mainStage.applications.count > 0 || sideStage.applications.count > 0
358 direction: Qt.RightToLeft
359 openedValue: 0
360 hintDisplacement: units.gu(3)
361 handleSize: shell.edgeSize
362 closedValue: width
363 target: stages
364 width: stages.width
365 height: stages.height
366 orientation: Qt.Horizontal
367 }
369 Greeter {
370 id: greeter
372 available: true
373 hides: [launcher, panel.indicators, hud]
374 shown: true
375 showAnimation: StandardAnimation { property: "x"; to: greeterRevealer.openedValue }
376 hideAnimation: StandardAnimation { property: "x"; to: greeterRevealer.closedValue }
378 y: panel.panelHeight
379 width: parent.width
380 height: parent.height - panel.panelHeight
382 property var previousMainApp: null
383 property var previousSideApp: null
385 onShownChanged: {
386 if (shown) {
387 greeter.forceActiveFocus();
388 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
389 // the stage was actually shown
390 if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
391 if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
392 applicationManager.unfocusCurrentApplication();
393 } else {
394 if (greeter.previousMainApp) {
395 applicationManager.focusApplication(greeter.previousMainApp);
396 greeter.previousMainApp = null;
397 }
398 if (greeter.previousSideApp) {
399 applicationManager.focusApplication(greeter.previousSideApp);
400 greeter.previousSideApp = null;
401 }
402 }
403 }
405 onUnlocked: greeter.hide()
406 onSelected: {
407 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
408 shell.background = bgPath ? bgPath : default_background
409 }
410 }
412 InputFilterArea {
413 anchors.fill: parent
414 blockInput: greeter.shown
415 }
417 Revealer {
418 id: greeterRevealer
420 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
421 target: greeter
422 width: greeter.width
423 height: greeter.height
424 handleSize: shell.edgeSize
425 orientation: Qt.Horizontal
426 visible: greeter.shown
427 enabled: !greeter.locked
428 }
430 Item {
431 id: overlay
433 anchors.fill: parent
435 Panel {
436 id: panel
437 anchors.fill: parent //because this draws indicator menus
438 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
439 indicators {
440 hides: [launcher]
441 }
442 fullscreenMode: shell.fullscreenMode
443 searchVisible: !greeter.shown
445 InputFilterArea {
446 anchors.fill: parent
447 blockInput: panel.indicators.shown
448 }
449 }
451 Hud {
452 id: hud
454 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
455 height: parent.height
457 available: !greeter.shown && !panel.indicators.shown
458 shown: false
459 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
460 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
462 Connections {
463 target: shell.applicationManager
464 onMainStageFocusedApplicationChanged: hud.hide()
465 onSideStageFocusedApplicationChanged: hud.hide()
466 }
468 InputFilterArea {
469 anchors.fill: parent
470 blockInput: hud.shown
471 }
472 }
474 Revealer {
475 id: hudRevealer
477 enabled: hud.shown
478 width: hud.width
479 anchors.left: hud.left
480 height: parent.height
481 target: hud.revealerTarget
482 closedValue: height
483 openedValue: 0
484 direction: Qt.RightToLeft
485 orientation: Qt.Vertical
486 handleSize: hud.handleHeight
487 onCloseClicked: target.hide()
488 }
490 Bottombar {
491 theHud: hud
492 anchors.fill: parent
493 enabled: !panel.indicators.shown
494 }
496 InputFilterArea {
497 blockInput: launcher.shown
498 anchors {
499 top: parent.top
500 bottom: parent.bottom
501 left: parent.left
502 }
503 width: launcher.width
504 }
506 Launcher {
507 id: launcher
509 anchors.top: parent.top
510 anchors.bottom: parent.bottom
511 width: parent.width
512 dragAreaWidth: shell.edgeSize
513 available: !greeter.locked
514 teasing: available && greeter.leftTeaserPressed
515 onDashItemSelected: {
516 greeter.hide()
517 // Animate if moving between application and dash
518 if (!stages.shown) {
519 dash.setCurrentLens("home.lens", true, false)
520 } else {
521 dash.setCurrentLens("home.lens", false, false)
522 }
523 stages.hide();
524 }
525 onDash: {
526 dash.setCurrentLens("applications.lens", true, false)
527 stages.hide();
528 }
529 onLauncherApplicationSelected:{
530 greeter.hide()
531 shell.activateApplication(desktopFile)
532 }
533 onShownChanged: {
534 if (shown) {
535 panel.indicators.hide()
536 hud.hide()
537 }
538 }
539 }
540 }
542 focus: true
544 InputFilterArea {
545 anchors {
546 top: parent.top
547 bottom: parent.bottom
548 left: parent.left
549 }
550 width: shell.edgeSize
551 blockInput: true
552 }
554 InputFilterArea {
555 anchors {
556 top: parent.top
557 bottom: parent.bottom
558 right: parent.right
559 }
560 width: shell.edgeSize
561 blockInput: true
562 }
564 Binding {
565 target: i18n
566 property: "domain"
567 value: "unity8"
568 }
570 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
571 MouseArea {
572 anchors.bottom: parent.bottom
573 anchors.left: parent.left
574 anchors.right: parent.right
575 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
577 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
578 }