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