on cf44c47 help sign in
unity8/Shell.qml
550 lines 20 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 Powerd 0.1
22import SessionManager 0.1
23import "Dash"
24import "Launcher"
25import "Panel"
26import "Hud"
27import "Components"
28import "Components/Math.js" as MathLocal
29import "Bottombar"
30import "SideStage"
31import "Notifications"
32import Unity.Notifications 1.0 as NotificationBackend
34BasicShell {
35 id: shell
37 readonly property real panelHeight: panel.panelHeight
39 property bool dashShown: dash.shown
40 property bool stageScreenshotsReady: {
41 if (sideStage.shown) {
42 if (mainStage.applications.count > 0) {
43 return mainStage.usingScreenshots && sideStage.usingScreenshots;
44 } else {
45 return sideStage.usingScreenshots;
46 }
47 } else {
48 return mainStage.usingScreenshots;
49 }
50 }
52 property ListModel searchHistory: SearchHistoryModel {}
54 property var applicationManager: ApplicationManagerWrapper {}
56 Component.onCompleted: {
57 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
59 applicationManager.sideStageEnabled = Qt.binding(function() { return sideStage.enabled })
61 // FIXME: if application focused before shell starts, shell draws on top of it only.
62 // We should detect already running applications on shell start and bring them to the front.
63 applicationManager.unfocusCurrentApplication();
64 }
66 readonly property bool fullscreenMode: {
67 if (mainStage.usingScreenshots) { // Window Manager animating so want to re-evaluate fullscreen mode
68 return mainStage.switchingFromFullscreenToFullscreen;
69 } else if (applicationManager.mainStageFocusedApplication) {
70 return applicationManager.mainStageFocusedApplication.fullscreen;
71 } else {
72 return false;
73 }
74 }
76 Connections {
77 target: applicationManager
78 ignoreUnknownSignals: true
79 onFocusRequested: {
80 shell.activateApplication(desktopFile);
81 }
82 }
84 function activateApplication(desktopFile, argument) {
85 if (applicationManager) {
86 // For newly started applications, as it takes them time to draw their first frame
87 // we add a delay before we hide the animation screenshots to compensate.
88 var addDelay = !applicationManager.getApplicationFromDesktopFile(desktopFile);
90 var application;
91 application = applicationManager.activateApplication(desktopFile, argument);
92 if (application == null) {
93 return;
94 }
95 if (application.stage == ApplicationInfo.MainStage || !sideStage.enabled) {
96 mainStage.activateApplication(desktopFile, addDelay);
97 } else {
98 sideStage.activateApplication(desktopFile, addDelay);
99 }
100 stages.show();
101 }
102 }
104 Item {
105 id: underlay
106 objectName: "underlay"
107 anchors.fill: parent
109 // Whether the underlay is fully covered by opaque UI elements.
110 property bool fullyCovered: panel.indicators.fullyOpened && shell.width <= panel.indicatorsMenuWidth
112 // Whether the user should see the topmost application surface (if there's one at all).
113 property bool applicationSurfaceShouldBeSeen:
114 (mainStage.applications && mainStage.applications.count > 0)
115 && (!stages.fullyHidden && !mainStage.usingScreenshots)
117 // NB! Application surfaces are stacked behing the shell one. So they can only be seen by the user
118 // through the translucent parts of the shell surface.
119 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
121 CrossFadeImage {
122 id: backgroundImage
123 objectName: "backgroundImage"
125 anchors.fill: parent
126 source: shell.background
127 }
129 Rectangle {
130 anchors.fill: parent
131 color: "black"
132 opacity: dash.disappearingAnimationProgress
133 }
135 Dash {
136 id: dash
137 objectName: "dash"
139 hides: [stages, launcher, panel.indicators]
140 shown: disappearingAnimationProgress !== 1.0
141 enabled: disappearingAnimationProgress === 0.0
142 // FIXME: unfocus all applications when going back to the dash
143 onEnabledChanged: {
144 if (enabled) {
145 shell.applicationManager.unfocusCurrentApplication()
146 }
147 }
149 anchors {
150 fill: parent
151 topMargin: panel.panelHeight
152 }
154 contentScale: 1.0 - 0.2 * disappearingAnimationProgress
155 opacity: 1.0 - disappearingAnimationProgress
156 property real disappearingAnimationProgress: stagesOuterContainer.showProgress
158 // FIXME: only necessary because stagesOuterContainer.showProgress
159 // is not animated
160 Behavior on disappearingAnimationProgress { SmoothedAnimation { velocity: 5 }}
161 }
162 }
164 Item {
165 id: stagesOuterContainer
167 width: parent.width
168 height: parent.height
169 x: launcher.progress
170 Behavior on x {SmoothedAnimation{velocity: 600}}
172 property real showProgress:
173 MathLocal.clamp(1 - (x + stages.x) / shell.width, 0, 1)
175 Showable {
176 id: stages
177 objectName: "stages"
179 x: width
181 property bool fullyShown: shown && x == 0 && parent.x == 0
182 property bool fullyHidden: !shown && x == width
183 hides: [launcher, panel.indicators]
184 shown: false
185 opacity: 1.0
186 showAnimation: StandardAnimation { property: "x"; duration: 350; to: 0; easing.type: Easing.OutCubic }
187 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: width; easing.type: Easing.OutCubic }
189 width: parent.width
190 height: parent.height
192 // close the stages when no focused application remains
193 Connections {
194 target: shell.applicationManager
195 onMainStageFocusedApplicationChanged: stages.closeIfNoApplications()
196 onSideStageFocusedApplicationChanged: stages.closeIfNoApplications()
197 ignoreUnknownSignals: true
198 }
200 function closeIfNoApplications() {
201 if (!shell.applicationManager.mainStageFocusedApplication
202 && !shell.applicationManager.sideStageFocusedApplication
203 && shell.applicationManager.mainStageApplications.count == 0
204 && shell.applicationManager.sideStageApplications.count == 0) {
205 stages.hide();
206 }
207 }
209 // show the stages when an application gets the focus
210 Connections {
211 target: shell.applicationManager
212 onMainStageFocusedApplicationChanged: {
213 if (shell.applicationManager.mainStageFocusedApplication) {
214 mainStage.show();
215 stages.show();
216 }
217 }
218 onSideStageFocusedApplicationChanged: {
219 if (shell.applicationManager.sideStageFocusedApplication) {
220 sideStage.show();
221 stages.show();
222 }
223 }
224 ignoreUnknownSignals: true
225 }
227 Stage {
228 id: mainStage
230 anchors.fill: parent
231 fullyShown: stages.fullyShown
232 fullyHidden: stages.fullyHidden
233 shouldUseScreenshots: !fullyShown
234 rightEdgeEnabled: !sideStage.enabled
236 applicationManager: shell.applicationManager
237 rightEdgeDraggingAreaWidth: shell.edgeSize
238 normalApplicationY: shell.panelHeight
240 shown: true
241 function show() {
242 stages.show();
243 }
244 function hide() {
245 }
247 // FIXME: workaround the fact that focusing a main stage application
248 // raises its surface on top of all other surfaces including the ones
249 // that belong to side stage applications.
250 onFocusedApplicationChanged: {
251 if (focusedApplication && sideStage.focusedApplication && sideStage.fullyShown) {
252 shell.applicationManager.focusApplication(sideStage.focusedApplication);
253 }
254 }
255 }
257 SideStage {
258 id: sideStage
260 applicationManager: shell.applicationManager
261 rightEdgeDraggingAreaWidth: shell.edgeSize
262 normalApplicationY: shell.panelHeight
264 onShownChanged: {
265 if (!shown && mainStage.applications.count == 0) {
266 stages.hide();
267 }
268 }
269 // FIXME: when hiding the side stage, refocus the main stage
270 // application so that it goes in front of the side stage
271 // application and hides it
272 onFullyShownChanged: {
273 if (!fullyShown && stages.fullyShown && sideStage.focusedApplication != null) {
274 shell.applicationManager.focusApplication(mainStage.focusedApplication);
275 }
276 }
278 enabled: shell.width >= units.gu(60)
279 visible: enabled
280 fullyShown: stages.fullyShown && shown
281 && sideStage[sideStageRevealer.boundProperty] == sideStageRevealer.openedValue
282 shouldUseScreenshots: !fullyShown || mainStage.usingScreenshots || sideStageRevealer.pressed
284 available: enabled
285 hides: [launcher, panel.indicators]
286 shown: false
287 showAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.openedValue; easing.type: Easing.OutQuint }
288 hideAnimation: StandardAnimation { property: "x"; duration: 350; to: sideStageRevealer.closedValue; easing.type: Easing.OutQuint }
290 width: units.gu(40)
291 height: stages.height
292 handleExpanded: sideStageRevealer.pressed
293 }
295 Revealer {
296 id: sideStageRevealer
298 enabled: mainStage.applications.count > 0 && sideStage.applications.count > 0
299 && sideStage.available
300 direction: Qt.RightToLeft
301 openedValue: parent.width - sideStage.width
302 hintDisplacement: units.gu(3)
303 /* The size of the sidestage handle needs to be bigger than the
304 typical size used for edge detection otherwise it is really
305 hard to grab.
306 */
307 handleSize: sideStage.shown ? units.gu(4) : shell.edgeSize
308 closedValue: parent.width + sideStage.handleSizeCollapsed
309 target: sideStage
310 x: parent.width - width
311 width: sideStage.width + handleSize * 0.7
312 height: sideStage.height
313 orientation: Qt.Horizontal
314 }
316 DragHandle {
317 id: stagesDragHandle
319 anchors.top: parent.top
320 anchors.bottom: parent.bottom
321 anchors.right: parent.left
323 width: shell.edgeSize
324 direction: Direction.Leftwards
325 property bool haveApps: mainStage.applications.count > 0 || sideStage.applications.count > 0
327 maxTotalDragDistance: haveApps ? parent.width : parent.width * 0.7
328 // Make autocompletion impossible when !haveApps
329 edgeDragEvaluator.minDragDistance: haveApps ? maxTotalDragDistance * 0.1 : Number.MAX_VALUE
330 }
331 }
332 }
334 Connections {
335 id: powerConnection
336 target: Powerd
338 property var previousMainApp: null
339 property var previousSideApp: null
341 function setFocused(focused) {
342 if (!focused) {
343 // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
344 // the stage was actually shown
345 if (mainStage.fullyShown) powerConnection.previousMainApp = applicationManager.mainStageFocusedApplication;
346 if (sideStage.fullyShown) powerConnection.previousSideApp = applicationManager.sideStageFocusedApplication;
347 applicationManager.unfocusCurrentApplication();
348 } else {
349 if (powerConnection.previousMainApp) {
350 applicationManager.focusApplication(powerConnection.previousMainApp);
351 powerConnection.previousMainApp = null;
352 }
353 if (powerConnection.previousSideApp) {
354 applicationManager.focusApplication(powerConnection.previousSideApp);
355 powerConnection.previousSideApp = null;
356 }
357 }
358 }
360 onPowerStateChange: {
361 if (state == 0) { // suspend
362 powerConnection.setFocused(false);
363 SessionManager.lock();
364 } else if (state == 1) { // active
365 powerConnection.setFocused(true);
366 }
367 }
368 }
370 Item {
371 id: overlay
373 anchors.fill: parent
375 Panel {
376 id: panel
377 anchors.fill: parent //because this draws indicator menus
378 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
379 indicators {
380 hides: [launcher]
381 }
382 fullscreenMode: shell.fullscreenMode
384 InputFilterArea {
385 anchors.fill: parent
386 blockInput: panel.indicators.shown
387 }
388 }
390 Hud {
391 id: hud
393 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
394 height: parent.height
396 available: !panel.indicators.shown
397 shown: false
398 showAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: 0; easing.type: Easing.Linear }
399 hideAnimation: StandardAnimation { property: "y"; duration: hud.showableAnimationDuration; to: hudRevealer.closedValue; easing.type: Easing.Linear }
401 Connections {
402 target: shell.applicationManager
403 onMainStageFocusedApplicationChanged: hud.hide()
404 onSideStageFocusedApplicationChanged: hud.hide()
405 }
407 InputFilterArea {
408 anchors.fill: parent
409 blockInput: hud.shown
410 }
411 }
413 Revealer {
414 id: hudRevealer
416 enabled: hud.shown
417 width: hud.width
418 anchors.left: hud.left
419 height: parent.height
420 target: hud.revealerTarget
421 closedValue: height
422 openedValue: 0
423 direction: Qt.RightToLeft
424 orientation: Qt.Vertical
425 handleSize: hud.handleHeight
426 onCloseClicked: target.hide()
427 }
429 Bottombar {
430 theHud: hud
431 anchors.fill: parent
432 enabled: !panel.indicators.shown
433 applicationIsOnForeground: applicationManager.mainStageFocusedApplication
434 || applicationManager.sideStageFocusedApplication
435 }
437 InputFilterArea {
438 blockInput: launcher.shown
439 anchors {
440 top: parent.top
441 bottom: parent.bottom
442 left: parent.left
443 }
444 width: launcher.width
445 }
447 Launcher {
448 id: launcher
450 anchors.top: parent.top
451 anchors.bottom: parent.bottom
452 width: parent.width
453 dragAreaWidth: shell.edgeSize
454 onDashItemSelected: {
455 // Animate if moving between application and dash
456 if (!stages.shown) {
457 dash.setCurrentScope("home.scope", true, false)
458 } else {
459 dash.setCurrentScope("home.scope", false, false)
460 }
461 stages.hide();
462 }
463 onDash: {
464 if (stages.shown) {
465 dash.setCurrentScope("applications.scope", true, false)
466 stages.hide();
467 launcher.hide();
468 }
469 }
470 onLauncherApplicationSelected:{
471 shell.activateApplication(desktopFile)
472 }
473 onShownChanged: {
474 if (shown) {
475 panel.indicators.hide()
476 hud.hide()
477 }
478 }
479 }
481 Notifications {
482 id: notifications
484 model: NotificationBackend.Model
485 anchors {
486 top: parent.top
487 right: parent.right
488 bottom: parent.bottom
489 leftMargin: units.gu(1)
490 rightMargin: units.gu(1)
491 topMargin: panel.panelHeight + units.gu(1)
492 }
493 states: [
494 State {
495 name: "narrow"
496 when: overlay.width <= units.gu(60)
497 AnchorChanges { target: notifications; anchors.left: parent.left }
498 },
499 State {
500 name: "wide"
501 when: overlay.width > units.gu(60)
502 AnchorChanges { target: notifications; anchors.left: undefined }
503 PropertyChanges { target: notifications; width: units.gu(38) }
504 }
505 ]
506 }
507 }
509 focus: true
511 InputFilterArea {
512 anchors {
513 top: parent.top
514 bottom: parent.bottom
515 left: parent.left
516 }
517 width: shell.edgeSize
518 blockInput: true
519 }
521 Binding {
522 target: i18n
523 property: "domain"
524 value: "unity8"
525 }
527 //FIXME: This should be handled in the input stack, keyboard shouldnt propagate
528 MouseArea {
529 anchors.bottom: parent.bottom
530 anchors.left: parent.left
531 anchors.right: parent.right
532 height: shell.applicationManager ? shell.applicationManager.keyboardHeight : 0
534 enabled: shell.applicationManager && shell.applicationManager.keyboardVisible
535 }
537 Label {
538 anchors.centerIn: parent
539 visible: applicationManager.fake
540 text: "EARLY ALPHA\nNOT READY FOR USE"
541 color: "lightgrey"
542 opacity: 0.2
543 font.weight: Font.Black
544 horizontalAlignment: Text.AlignHCenter
545 verticalAlignment: Text.AlignVCenter
546 fontSizeMode: Text.Fit
547 rotation: -45
548 scale: Math.min(parent.width, parent.height) / width
549 }