Unity 8
Shell.qml
1 /*
2  * Copyright (C) 2013-2015 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  */
16 
17 import QtQuick 2.4
18 import QtQuick.Window 2.2
19 import AccountsService 0.1
20 import Unity.Application 0.1
21 import Ubuntu.Components 1.3
22 import Ubuntu.Components.Popups 1.3
23 import Ubuntu.Gestures 0.1
24 import Ubuntu.Telephony 0.1 as Telephony
25 import Unity.Connectivity 0.1
26 import Unity.Launcher 0.1
27 import GlobalShortcut 1.0 // has to be before Utils, because of WindowKeysFilter
28 import Utils 0.1
29 import Powerd 0.1
30 import SessionBroadcast 0.1
31 import "Greeter"
32 import "Launcher"
33 import "Panel"
34 import "Components"
35 import "Notifications"
36 import "Stages"
37 import "Tutorial"
38 import "Wizard"
39 import Unity.Notifications 1.0 as NotificationBackend
40 import Unity.Session 0.1
41 import Unity.DashCommunicator 0.1
42 import Unity.Indicators 0.1 as Indicators
43 import Cursor 1.0
44 
45 
46 Item {
47  id: shell
48 
49  // to be set from outside
50  property int orientationAngle: 0
51  property int orientation
52  property Orientations orientations
53  property real nativeWidth
54  property real nativeHeight
55  property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
56  property bool beingResized
57  property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
58  property string mode: "full-greeter"
59  property bool cursorVisible: false
60  function updateFocusedAppOrientation() {
61  applicationsDisplayLoader.item.updateFocusedAppOrientation();
62  }
63  function updateFocusedAppOrientationAnimated() {
64  applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
65  }
66  property bool hasMouse: false
67 
68  // to be read from outside
69  readonly property int mainAppWindowOrientationAngle:
70  applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
71 
72  readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
73  && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
74  && (!greeter || !greeter.animating)
75 
76  readonly property bool showingGreeter: greeter && greeter.shown
77 
78  property bool startingUp: true
79  Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
80 
81  property int supportedOrientations: {
82  if (startingUp) {
83  // Ensure we don't rotate during start up
84  return Qt.PrimaryOrientation;
85  } else if (greeter && greeter.shown) {
86  return Qt.PrimaryOrientation;
87  } else if (mainApp) {
88  return shell.orientations.map(mainApp.supportedOrientations);
89  } else {
90  // we just don't care
91  return Qt.PortraitOrientation
92  | Qt.LandscapeOrientation
93  | Qt.InvertedPortraitOrientation
94  | Qt.InvertedLandscapeOrientation;
95  }
96  }
97 
98  // For autopilot consumption
99  readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
100 
101  // internal props from here onwards
102  readonly property var mainApp:
103  applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
104 
105  // Disable everything while greeter is waiting, so that the user can't swipe
106  // the greeter or launcher until we know whether the session is locked.
107  enabled: greeter && !greeter.waiting
108 
109  property real edgeSize: units.gu(2)
110 
111  WallpaperResolver {
112  id: wallpaperResolver
113  width: shell.width
114  }
115 
116  readonly property alias greeter: greeterLoader.item
117 
118  function activateApplication(appId) {
119  if (ApplicationManager.findApplication(appId)) {
120  ApplicationManager.requestFocusApplication(appId);
121  } else {
122  var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
123  : ApplicationManager.NoFlag;
124  ApplicationManager.startApplication(appId, execFlags);
125  }
126  }
127 
128  function startLockedApp(app) {
129  if (greeter.locked) {
130  greeter.lockedApp = app;
131  }
132  shell.activateApplication(app);
133  }
134 
135  Binding {
136  target: LauncherModel
137  property: "applicationManager"
138  value: ApplicationManager
139  }
140 
141  Component.onCompleted: {
142  theme.name = "Ubuntu.Components.Themes.SuruGradient"
143  if (ApplicationManager.count > 0) {
144  ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
145  }
146  finishStartUpTimer.start();
147  }
148 
149  LightDM{id: lightDM} // Provide backend access
150  VolumeControl {
151  id: volumeControl
152  indicators: panel.indicators
153  }
154 
155  DashCommunicator {
156  id: dash
157  objectName: "dashCommunicator"
158  }
159 
160  PhysicalKeysMapper {
161  id: physicalKeysMapper
162  objectName: "physicalKeysMapper"
163 
164  onPowerKeyLongPressed: dialogs.showPowerDialog();
165  onVolumeDownTriggered: volumeControl.volumeDown();
166  onVolumeUpTriggered: volumeControl.volumeUp();
167  onScreenshotTriggered: screenGrabber.capture();
168  }
169 
170  GlobalShortcut {
171  // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
172  }
173 
174  WindowKeysFilter {
175  Keys.onPressed: physicalKeysMapper.onKeyPressed(event, currentEventTimestamp);
176  Keys.onReleased: physicalKeysMapper.onKeyReleased(event, currentEventTimestamp);
177  }
178 
179  HomeKeyWatcher {
180  onActivated: { launcher.fadeOut(); shell.showHome(); }
181  }
182 
183  Item {
184  id: stages
185  objectName: "stages"
186  width: parent.width
187  height: parent.height
188 
189  Connections {
190  target: ApplicationManager
191 
192  // This signal is also fired when we try to focus the current app
193  // again. We rely on this!
194  onFocusedApplicationIdChanged: {
195  var appId = ApplicationManager.focusedApplicationId;
196 
197  if (tutorial.running && appId != "" && appId != "unity8-dash") {
198  // If this happens on first boot, we may be in edge
199  // tutorial or wizard while receiving a call. But a call
200  // is more important than wizard so just bail out of those.
201  tutorial.finish();
202  wizard.hide();
203  }
204 
205  if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
206  // If we are in the middle of a call, make dialer lockedApp and show it.
207  // This can happen if user backs out of dialer back to greeter, then
208  // launches dialer again.
209  greeter.lockedApp = appId;
210  }
211  greeter.notifyAppFocused(appId);
212 
213  panel.indicators.hide();
214  }
215 
216  onApplicationAdded: {
217  launcher.hide();
218  }
219  }
220 
221  Loader {
222  id: applicationsDisplayLoader
223  objectName: "applicationsDisplayLoader"
224  anchors.fill: parent
225 
226  // When we have a locked app, we only want to show that one app.
227  // FIXME: do this in a less traumatic way. We currently only allow
228  // locked apps in phone mode (see FIXME in Lockscreen component in
229  // this same file). When that changes, we need to do something
230  // nicer here. But this code is currently just to prevent a
231  // theoretical attack where user enters lockedApp mode, then makes
232  // the screen larger (maybe connects to monitor) and tries to enter
233  // tablet mode.
234 
235  property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
236  ? "phone"
237  : shell.usageScenario
238  source: {
239  if(shell.mode === "greeter") {
240  return "Stages/ShimStage.qml"
241  } else if (applicationsDisplayLoader.usageScenario === "phone") {
242  return "Stages/PhoneStage.qml";
243  } else if (applicationsDisplayLoader.usageScenario === "tablet") {
244  return "Stages/TabletStage.qml";
245  } else {
246  return "Stages/DesktopStage.qml";
247  }
248  }
249 
250  property bool interactive: tutorial.spreadEnabled
251  && (!greeter || !greeter.shown)
252  && panel.indicators.fullyClosed
253  && launcher.progress == 0
254  && !notifications.useModal
255 
256  onInteractiveChanged: { if (interactive) { focus = true; } }
257 
258  Binding {
259  target: applicationsDisplayLoader.item
260  property: "objectName"
261  value: "stage"
262  }
263  Binding {
264  target: applicationsDisplayLoader.item
265  property: "dragAreaWidth"
266  value: shell.edgeSize
267  }
268  Binding {
269  target: applicationsDisplayLoader.item
270  property: "maximizedAppTopMargin"
271  // Not just using panel.panelHeight as that changes depending on the focused app.
272  value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
273  }
274  Binding {
275  target: applicationsDisplayLoader.item
276  property: "interactive"
277  value: applicationsDisplayLoader.interactive
278  }
279  Binding {
280  target: applicationsDisplayLoader.item
281  property: "spreadEnabled"
282  value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
283  }
284  Binding {
285  target: applicationsDisplayLoader.item
286  property: "inverseProgress"
287  value: greeter && greeter.locked ? 0 : launcher.progress
288  }
289  Binding {
290  target: applicationsDisplayLoader.item
291  property: "shellOrientationAngle"
292  value: shell.orientationAngle
293  }
294  Binding {
295  target: applicationsDisplayLoader.item
296  property: "shellOrientation"
297  value: shell.orientation
298  }
299  Binding {
300  target: applicationsDisplayLoader.item
301  property: "orientations"
302  value: shell.orientations
303  }
304  Binding {
305  target: applicationsDisplayLoader.item
306  property: "background"
307  value: wallpaperResolver.background
308  }
309  Binding {
310  target: applicationsDisplayLoader.item
311  property: "nativeWidth"
312  value: shell.nativeWidth
313  }
314  Binding {
315  target: applicationsDisplayLoader.item
316  property: "nativeHeight"
317  value: shell.nativeHeight
318  }
319  Binding {
320  target: applicationsDisplayLoader.item
321  property: "beingResized"
322  value: shell.beingResized
323  }
324  Binding {
325  target: applicationsDisplayLoader.item
326  property: "keepDashRunning"
327  value: launcher.shown || launcher.dashSwipe
328  }
329  Binding {
330  target: applicationsDisplayLoader.item
331  property: "suspended"
332  value: greeter.shown
333  }
334  Binding {
335  target: applicationsDisplayLoader.item
336  property: "altTabPressed"
337  value: physicalKeysMapper.altTabPressed
338  }
339  }
340 
341  Tutorial {
342  id: tutorial
343  objectName: "tutorial"
344  anchors.fill: parent
345 
346  // EdgeDragAreas don't work with mice. So to avoid trapping the user,
347  // we skip the tutorial on the Desktop to avoid using them. The
348  // Desktop doesn't use the same spread design anyway. The tutorial is
349  // all a bit of a placeholder on non-phone form factors right now.
350  // When the design team gives us more guidance, we can do something
351  // more clever here.
352  active: usageScenario != "desktop" && AccountsService.demoEdges
353 
354  paused: lightDM.greeter.active
355  launcher: launcher
356  panel: panel
357  edgeSize: shell.edgeSize
358 
359  onFinished: {
360  AccountsService.demoEdges = false;
361  active = false; // for immediate response / if AS is having problems
362  }
363  }
364  }
365 
366  InputMethod {
367  id: inputMethod
368  objectName: "inputMethod"
369  anchors { fill: parent; topMargin: panel.panelHeight }
370  z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
371  }
372 
373  Connections {
374  target: SessionManager
375  onSessionStopping: {
376  if (!session.parentSession && !session.application) {
377  // nothing is using it. delete it right away
378  session.release();
379  }
380  }
381  }
382 
383  Loader {
384  id: greeterLoader
385  anchors.fill: parent
386  anchors.topMargin: panel.panelHeight
387  sourceComponent: shell.mode != "shell" ? integratedGreeter :
388  Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
389  onLoaded: {
390  item.objectName = "greeter"
391  }
392  }
393 
394  Component {
395  id: integratedGreeter
396  Greeter {
397 
398  hides: [launcher, panel.indicators]
399  tabletMode: shell.usageScenario != "phone"
400  launcherOffset: launcher.progress
401  forcedUnlock: tutorial.running
402  background: wallpaperResolver.background
403 
404  // avoid overlapping with Launcher's edge drag area
405  // FIXME: Fix TouchRegistry & friends and remove this workaround
406  // Issue involves launcher's DDA getting disabled on a long
407  // left-edge drag
408  dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
409 
410  onSessionStarted: {
411  launcher.hide();
412  }
413 
414  onTease: {
415  if (!tutorial.running) {
416  launcher.tease();
417  }
418  }
419 
420  onEmergencyCall: startLockedApp("dialer-app")
421  }
422  }
423 
424  Timer {
425  // See powerConnection for why this is useful
426  id: showGreeterDelayed
427  interval: 1
428  onTriggered: {
429  greeter.forceShow();
430  }
431  }
432 
433  Connections {
434  id: callConnection
435  target: callManager
436 
437  onHasCallsChanged: {
438  if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
439  // We just received an incoming call while locked. The
440  // indicator will have already launched dialer-app for us, but
441  // there is a race between "hasCalls" changing and the dialer
442  // starting up. So in case we lose that race, we'll start/
443  // focus the dialer ourselves here too. Even if the indicator
444  // didn't launch the dialer for some reason (or maybe a call
445  // started via some other means), if an active call is
446  // happening, we want to be in the dialer.
447  startLockedApp("dialer-app")
448  }
449  }
450  }
451 
452  Connections {
453  id: powerConnection
454  target: Powerd
455 
456  onStatusChanged: {
457  if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
458  !callManager.hasCalls && !tutorial.running) {
459  // We don't want to simply call greeter.showNow() here, because
460  // that will take too long. Qt will delay button event
461  // handling until the greeter is done loading and may think the
462  // user held down the power button the whole time, leading to a
463  // power dialog being shown. Instead, delay showing the
464  // greeter until we've finished handling the event. We could
465  // make the greeter load asynchronously instead, but that
466  // introduces a whole host of timing issues, especially with
467  // its animations. So this is simpler.
468  showGreeterDelayed.start();
469  }
470  }
471  }
472 
473  function showHome() {
474  if (tutorial.running) {
475  return
476  }
477 
478  greeter.notifyAboutToFocusApp("unity8-dash");
479 
480  var animate = !lightDM.greeter.active && !stages.shown
481  dash.setCurrentScope(0, animate, false)
482  ApplicationManager.requestFocusApplication("unity8-dash")
483  }
484 
485  function showDash() {
486  if (greeter.notifyShowingDashFromDrag()) {
487  launcher.fadeOut();
488  }
489 
490  if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
491  ApplicationManager.requestFocusApplication("unity8-dash")
492  launcher.fadeOut();
493  }
494  }
495 
496  Item {
497  id: overlay
498  z: 10
499 
500  anchors.fill: parent
501 
502  Panel {
503  id: panel
504  objectName: "panel"
505  anchors.fill: parent //because this draws indicator menus
506  indicators {
507  hides: [launcher]
508  available: tutorial.panelEnabled
509  && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
510  && (!greeter || !greeter.hasLockedApp)
511  contentEnabled: tutorial.panelContentEnabled
512  width: parent.width > units.gu(60) ? units.gu(40) : parent.width
513 
514  minimizedPanelHeight: units.gu(3)
515  expandedPanelHeight: units.gu(7)
516 
517  indicatorsModel: Indicators.IndicatorsModel {
518  // tablet and phone both use the same profile
519  profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
520  Component.onCompleted: load();
521  }
522  }
523 
524  callHint {
525  greeterShown: greeter.shown
526  }
527 
528  property bool topmostApplicationIsFullscreen:
529  ApplicationManager.focusedApplicationId &&
530  ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
531 
532  fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
533  || greeter.hasLockedApp
534  locked: greeter && greeter.active
535  }
536 
537  Launcher {
538  id: launcher
539  objectName: "launcher"
540 
541  readonly property bool dashSwipe: progress > 0
542 
543  anchors.top: parent.top
544  anchors.topMargin: inverted ? 0 : panel.panelHeight
545  anchors.bottom: parent.bottom
546  width: parent.width
547  dragAreaWidth: shell.edgeSize
548  available: tutorial.launcherEnabled
549  && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
550  && !greeter.hasLockedApp
551  inverted: shell.usageScenario !== "desktop"
552  shadeBackground: !tutorial.running
553 
554  onShowDashHome: showHome()
555  onDash: showDash()
556  onDashSwipeChanged: {
557  if (dashSwipe) {
558  dash.setCurrentScope(0, false, true)
559  }
560  }
561  onLauncherApplicationSelected: {
562  if (!tutorial.running) {
563  greeter.notifyAboutToFocusApp(appId);
564  shell.activateApplication(appId)
565  }
566  }
567  onShownChanged: {
568  if (shown) {
569  panel.indicators.hide()
570  }
571  }
572  }
573 
574  Wizard {
575  id: wizard
576  objectName: "wizard"
577  anchors.fill: parent
578  background: wallpaperResolver.background
579 
580  function unlockWhenDoneWithWizard() {
581  if (!active) {
582  Connectivity.unlockAllModems();
583  }
584  }
585 
586  Component.onCompleted: unlockWhenDoneWithWizard()
587  onActiveChanged: unlockWhenDoneWithWizard()
588  }
589 
590  Rectangle {
591  id: modalNotificationBackground
592 
593  visible: notifications.useModal
594  color: "#000000"
595  anchors.fill: parent
596  opacity: 0.9
597 
598  MouseArea {
599  anchors.fill: parent
600  }
601  }
602 
603  Notifications {
604  id: notifications
605 
606  model: NotificationBackend.Model
607  margin: units.gu(1)
608  hasMouse: shell.hasMouse
609  background: wallpaperResolver.background
610 
611  y: topmostIsFullscreen ? 0 : panel.panelHeight
612  height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
613 
614  states: [
615  State {
616  name: "narrow"
617  when: overlay.width <= units.gu(60)
618  AnchorChanges {
619  target: notifications
620  anchors.left: parent.left
621  anchors.right: parent.right
622  }
623  },
624  State {
625  name: "wide"
626  when: overlay.width > units.gu(60)
627  AnchorChanges {
628  target: notifications
629  anchors.left: undefined
630  anchors.right: parent.right
631  }
632  PropertyChanges { target: notifications; width: units.gu(38) }
633  }
634  ]
635  }
636  }
637 
638  Dialogs {
639  id: dialogs
640  objectName: "dialogs"
641  anchors.fill: parent
642  z: overlay.z + 10
643  usageScenario: shell.usageScenario
644  onPowerOffClicked: {
645  shutdownFadeOutRectangle.enabled = true;
646  shutdownFadeOutRectangle.visible = true;
647  shutdownFadeOut.start();
648  }
649  }
650 
651  Connections {
652  target: SessionBroadcast
653  onShowHome: showHome()
654  }
655 
656  ScreenGrabber {
657  id: screenGrabber
658  rotationAngle: -shell.orientationAngle
659  z: dialogs.z + 10
660  }
661 
662  Cursor {
663  id: cursor
664  visible: shell.hasMouse
665  z: screenGrabber.z + 1
666  }
667 
668  Rectangle {
669  id: shutdownFadeOutRectangle
670  z: cursor.z + 1
671  enabled: false
672  visible: false
673  color: "black"
674  anchors.fill: parent
675  opacity: 0.0
676  NumberAnimation on opacity {
677  id: shutdownFadeOut
678  from: 0.0
679  to: 1.0
680  onStopped: {
681  if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
682  DBusUnitySessionService.shutdown();
683  }
684  }
685  }
686  }
687 }