on a40c1fe help sign in
unity8/Shell.qml
507 lines 18 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 Ubuntu.Gestures 0.1
21import SessionManager 0.1
22import "Dash"
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 as NotificationBackend
33BasicShell {
34 id: shell
36 readonly property real panelHeight: panel.panelHeight
38 property bool dashShown: dash.shown
39 property bool stageScreenshotsReady: {
40 if (sideStage.shown) {
41 if (mainStage.applications.count > 0) {
42 return mainStage.usingScreenshots && sideStage.usingScreenshots;
43 } else {
44 return sideStage.usingScreenshots;
45 }
46 } else {
47 return mainStage.usingScreenshots;
48 }
49 }
51 property ListModel searchHistory: SearchHistoryModel {}
53 property var applicationManager: ApplicationManagerWrapper {}
55 Component.onCompleted: {
56 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
58 applicationManager.sideStageEnabled = Qt.binding(function() { return sideStage.enabled })
60 // FIXME: if application focused before shell starts, shell draws on top of it only.
61 // We should detect already running applications on shell start and bring them to the front.
62 applicationManager.unfocusCurrentApplication();
63 }
65 readonly property bool fullscreenMode: {
66 if (mainStage.usingScreenshots) { // Window Manager animating so want to re-evaluate fullscreen mode
67 return mainStage.switchingFromFullscreenToFullscreen;
68 } else if (applicationManager.mainStageFocusedApplication) {
69 return applicationManager.mainStageFocusedApplication.fullscreen;
70 } else {
71 return false;
72 }
73 }
75 Connections {
76 target: applicationManager
77 ignoreUnknownSignals: true
78 onFocusRequested: {
79 shell.activateApplication(desktopFile);
80 }
81 }
83 function activateApplication(desktopFile, argument) {
84 if (applicationManager) {
85 // For newly started applications, as it takes them time to draw their first frame
86 // we add a delay before we hide the animation screenshots to compensate.
87 var addDelay = !applicationManager.getApplicationFromDesktopFile(desktopFile);
89 var application;
90 application = applicationManager.activateApplication(desktopFile, argument);
91 if (application == null) {
92 return;
93 }
94 if (application.stage == ApplicationInfo.MainStage || !sideStage.enabled) {
95 mainStage.activateApplication(desktopFile, addDelay);
96 } else {
97 sideStage.activateApplication(desktopFile, addDelay);
98 }
99 stages.show();
100 }
101 }
103 Keys.onReleased: {
104 if (event.key == Qt.Key_PowerOff) {
105 SessionManager.lock()
106 }
107 }
109 Item {
110 id: underlay
111 objectName: "underlay"
112 anchors.fill: parent
114 // Whether the underlay is fully covered by opaque UI elements.
115 property bool fullyCovered: panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth
117 // Whether the user should see the topmost application surface (if there's one at all).
118 property bool applicationSurfaceShouldBeSeen:
119 (mainStage.applications && mainStage.applications.count > 0)
120 && (!stages.fullyHidden && !mainStage.usingScreenshots)
122 // NB! Application surfaces are stacked behing the shell one. So they can only be seen by the user
123 // through the translucent parts of the shell surface.
124 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
126 Image {
127 id: backgroundImage
128 source: shell.background
129 sourceSize.width: parent.width
130 sourceSize.height: parent.height
131 anchors.fill: parent
132 }
134 Rectangle {
135 anchors.fill: parent
136 color: "black"
137 opacity: dash.disappearingAnimationProgress
138 }
140 Dash {
141 id: dash
142 objectName: "dash"
144 hides: [stages, launcher, panel.indicators]
145 shown: disappearingAnimationProgress !== 1.0
146 enabled: disappearingAnimationProgress === 0.0
147 // FIXME: unfocus all applications when going back to the dash
148 onEnabledChanged: {
149 if (enabled) {
150 shell.applicationManager.unfocusCurrentApplication()
151 }
152 }
154 anchors {
155 fill: parent
156 topMargin: panel.panelHeight
157 }
159 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
160 opacity: 1.0 - disappearingAnimationProgress
161 property real disappearingAnimationProgress: stagesOuterContainer.showProgress
163 // FIXME: only necessary because stagesOuterContainer.showProgress
164 // is not animated
165 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
166 }
167 }
170 Item {
171 id: stagesOuterContainer
173 width: parent.width
174 height: parent.height
175 x: launcher.progress
176 Behavior on x {SmoothedAnimation{velocity: 600}}
178 property real showProgress:
179 MathLocal.clamp(1 - (x + stages.x) / shell.width, 0, 1)
181 Showable {
182 id: stages
183 objectName: "stages"
185 x: width
187 property bool fullyShown: shown && x == 0 && parent.x == 0
188 property bool fullyHidden: !shown && x == width
189 hides: [launcher, panel.indicators]
190 shown: false
191 opacity: 1.0
192 showAnimation: StandardAnimation { property: "x"; duration: 350; to: 0; easing.type: Easing.OutCubic }
193 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: width; easing.type: Easing.OutCubic }
195 width: parent.width
196 height: parent.height
198 // close the stages when no focused application remains
199 Connections {
200 target: shell.applicationManager
201 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
202 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
203 ignoreUnknownSignals: true
204 }
206 function closeIfNoApplications() {
207 if (!shell.applicationManager.mainStageFocusedApplication
208 && !shell.applicationManager.sideStageFocusedApplication
209 && shell.applicationManager.mainStageApplications.count == 0
210 && shell.applicationManager.sideStageApplications.count == 0) {
211 stages.hide();
212 }
213 }
215 // show the stages when an application gets the focus
216 Connections {
217 target: shell.applicationManager
218 onMainStageFocusedApplicationChanged: {
219 if (shell.applicationManager.mainStageFocusedApplication) {
220 mainStage.show();
221 stages.show();
222 }
223 }
224 onSideStageFocusedApplicationChanged: {
225 if (shell.applicationManager.sideStageFocusedApplication) {
226 sideStage.show();
227 stages.show();
228 }
229 }
230 ignoreUnknownSignals: true
231 }
234 Stage {
235 id: mainStage
237 anchors.fill: parent
238 fullyShown: stages.fullyShown
239 fullyHidden: stages.fullyHidden
240 shouldUseScreenshots: !fullyShown
241 rightEdgeEnabled: !sideStage.enabled
243 applicationManager: shell.applicationManager
244 rightEdgeDraggingAreaWidth: shell.edgeSize
245 normalApplicationY: shell.panelHeight
247 shown: true
248 function show() {
249 stages.show();
250 }
251 function hide() {
252 }
254 // FIXME: workaround the fact that focusing a main stage application
255 // raises its surface on top of all other surfaces including the ones
256 // that belong to side stage applications.
257 onFocusedApplicationChanged: {
258 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
259 shell.applicationManager.focusApplication(sideStage.focusedApplication);
260 }
261 }
262 }
264 SideStage {
265 id: sideStage
267 applicationManager: shell.applicationManager
268 rightEdgeDraggingAreaWidth: shell.edgeSize
269 normalApplicationY: shell.panelHeight
271 onShownChanged: {
272 if (!shown && mainStage.applications.count == 0) {
273 stages.hide();
274 }
275 }
276 // FIXME: when hiding the side stage, refocus the main stage
277 // application so that it goes in front of the side stage
278 // application and hides it
279 onFullyShownChanged: {
280 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
281 shell.applicationManager.focusApplication(mainStage.focusedApplication);
282 }
283 }
285 enabled: shell.width >= units.gu(60)
286 visible: enabled
287 fullyShown: stages.fullyShown && shown
288 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
289 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
291 available: enabled
292 hides: [launcher, panel.indicators]
293 shown: false
294 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
295 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
297 width: units.gu(40)
298 height: stages.height
299 handleExpanded: sideStageRevealer.pressed
300 }
302 Revealer {
303 id: sideStageRevealer
305 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
306 && sideStage.available
307 direction: Qt.RightToLeft
308 openedValue: parent.width - sideStage.width
309 hintDisplacement: units.gu(3)
310 /* The size of the sidestage handle needs to be bigger than the
311 typical size used for edge detection otherwise it is really
312 hard to grab.
313 */
314 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
315 closedValue: parent.width + sideStage.handleSizeCollapsed
316 target: sideStage
317 x: parent.width - width
318 width: sideStage.width + handleSize * 0.7
319 height: sideStage.height
320 orientation: Qt.Horizontal
321 }
323 DragHandle {
324 id: stagesDragHandle
326 anchors.top: parent.top
327 anchors.bottom: parent.bottom
328 anchors.right: parent.left
330 width: shell.edgeSize
331 direction: Direction.Leftwards
332 property bool haveApps: mainStage.applications.count > 0 || sideStage.applications.count > 0
334 maxTotalDragDistance: haveApps ? parent.width : parent.width * 0.7
335 // Make autocompletion impossible when !haveApps
336 edgeDragEvaluator.minDragDistance: haveApps ? maxTotalDragDistance * 0.1 : Number.MAX_VALUE
337 }
338 }
339 }
341 Item {
342 id: overlay
344 anchors.fill: parent
346 Panel {
347 id: panel
348 anchors.fill: parent //because this draws indicator menus
349 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
350 indicators {
351 hides: [launcher]
352 }
353 fullscreenMode: shell.fullscreenMode
355 InputFilterArea {
356 anchors.fill: parent
357 blockInput: panel.indicators.shown
358 }
359 }
361 Hud {
362 id: hud
364 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
365 height: parent.height
367 available: !panel.indicators.shown
368 shown: false
369 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
370 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
372 Connections {
373 target: shell.applicationManager
374 onMainStageFocusedApplicationChanged: hud.hide()
375 onSideStageFocusedApplicationChanged: hud.hide()
376 }
378 InputFilterArea {
379 anchors.fill: parent
380 blockInput: hud.shown
381 }
382 }
384 Revealer {
385 id: hudRevealer
387 enabled: hud.shown
388 width: hud.width
389 anchors.left: hud.left
390 height: parent.height
391 target: hud.revealerTarget
392 closedValue: height
393 openedValue: 0
394 direction: Qt.RightToLeft
395 orientation: Qt.Vertical
396 handleSize: hud.handleHeight
397 onCloseClicked: target.hide()
398 }
400 Bottombar {
401 theHud: hud
402 anchors.fill: parent
403 enabled: !panel.indicators.shown
404 applicationIsOnForeground: applicationManager.mainStageFocusedApplication
405 || applicationManager.sideStageFocusedApplication
406 }
408 InputFilterArea {
409 blockInput: launcher.shown
410 anchors {
411 top: parent.top
412 bottom: parent.bottom
413 left: parent.left
414 }
415 width: launcher.width
416 }
418 Launcher {
419 id: launcher
421 anchors.top: parent.top
422 anchors.bottom: parent.bottom
423 width: parent.width
424 dragAreaWidth: shell.edgeSize
425 onDashItemSelected: {
426 // Animate if moving between application and dash
427 if (!stages.shown) {
428 dash.setCurrentScope("home.scope", true, false)
429 } else {
430 dash.setCurrentScope("home.scope", false, false)
431 }
432 stages.hide();
433 }
434 onDash: {
435 if (stages.shown) {
436 dash.setCurrentScope("applications.scope", true, false)
437 stages.hide();
438 launcher.hide();
439 }
440 }
441 onLauncherApplicationSelected:{
442 shell.activateApplication(desktopFile)
443 }
444 onShownChanged: {
445 if (shown) {
446 panel.indicators.hide()
447 hud.hide()
448 }
449 }
450 }
452 Notifications {
453 id: notifications
455 model: NotificationBackend.Model
456 anchors {
457 top: parent.top
458 right: parent.right
459 bottom: parent.bottom
460 leftMargin: units.gu(1)
461 rightMargin: units.gu(1)
462 topMargin: panel.panelHeight + units.gu(1)
463 }
464 states: [
465 State {
466 name: "narrow"
467 when: overlay.width <= units.gu(60)
468 AnchorChanges { target: notifications; anchors.left: parent.left }
469 },
470 State {
471 name: "wide"
472 when: overlay.width > units.gu(60)
473 AnchorChanges { target: notifications; anchors.left: undefined }
474 PropertyChanges { target: notifications; width: units.gu(38) }
475 }
476 ]
477 }
478 }
480 focus: true
482 InputFilterArea {
483 anchors {
484 top: parent.top
485 bottom: parent.bottom
486 left: parent.left
487 }
488 width: shell.edgeSize
489 blockInput: true
490 }
492 Binding {
493 target: i18n
494 property: "domain"
495 value: "unity8"
496 }
498 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
499 MouseArea {
500 anchors.bottom: parent.bottom
501 anchors.left: parent.left
502 anchors.right: parent.right
503 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
505 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
506 }