Lomiri
Loading...
Searching...
No Matches
ShellScreen.qml
1/*
2* Copyright (C) 2016 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
17import QtQuick 2.15
18import Lomiri.Components 1.3
19import WindowManager 1.0
20import Cursor 1.1
21import "Components"
22
23ScreenWindow {
24 id: screenWindow
25
26 color: "black"
27 title: "Lomiri Shell"
28
29 property int screenIndex: -1
30
31 // Foldables (DeviceConfiguration.foldable, with a hall-sensor sysfs path)
32 // run the shell on a single panel at a time, picked by the fold state. The
33 // large inner panel comes up as screen 1, the cover as screen 0.
34 readonly property bool foldable: deviceConfiguration.foldable
35 && deviceConfiguration.foldableSysfsPath !== ""
36 property bool foldOpen: true
37
38 readonly property bool primary: {
39 // If this is the only screen then it's the primary one
40 if (Screens.count === 1)
41 return true;
42
43 if (foldable)
44 return foldOpen ? (screenIndex === 1) : (screenIndex === 0);
45
46 if ((deviceConfiguration.category == "phone" || deviceConfiguration.category == "tablet")
47 && Screens.count > 1 && screenIndex === 1)
48 return true;
49
50 return (Screens.count > 1 && screenIndex === 0)
51 }
52
53 // The inner and cover panels differ in size and density, so each gets its
54 // own grid unit (from the device config) when it is the active one.
55 onPrimaryChanged: applyGridUnit()
56 onFoldOpenChanged: applyGridUnit()
57
58 function applyGridUnit() {
59 if (!foldable || !primary)
60 return;
61 var gu = foldOpen ? deviceConfiguration.innerGridUnit
62 : deviceConfiguration.coverGridUnit;
63 if (gu > 0)
64 units.gridUnit = gu;
65 }
66
67 function pollFold() {
68 var xhr = new XMLHttpRequest();
69 xhr.onreadystatechange = function() {
70 if (xhr.readyState === XMLHttpRequest.DONE && xhr.responseText.length > 0) {
71 screenWindow.foldOpen = (xhr.responseText.charAt(0) === "1");
72 applyGridUnit();
73 }
74 };
75 try {
76 xhr.open("GET", "file://" + deviceConfiguration.foldableSysfsPath);
77 xhr.send();
78 } catch (e) {}
79 }
80
81 Component.onCompleted: if (foldable) pollFold()
82
83 Timer {
84 interval: 350
85 running: screenWindow.foldable
86 repeat: true
87 onTriggered: pollFold()
88 }
89
90 DeviceConfiguration {
91 id: deviceConfiguration
92 }
93
94 Loader {
95 id: loader
96 width: screenWindow.width
97 height: screenWindow.height
98
99 sourceComponent: {
100 if (Screens.count > 1 && !primary) {
101 // On a foldable the inactive side is blanked: no second,
102 // mis-scaled shell and no virtual trackpad. Other multi-screen
103 // setups keep the convergence disabled-screen notice.
104 if (foldable)
105 return blankComponent;
106 if (deviceConfiguration.category == "phone" || deviceConfiguration.category == "tablet")
107 return disabledScreenComponent;
108 }
109 return shellComponent;
110 }
111 }
112
113 Component {
114 id: shellComponent
115 OrientedShell {
116 implicitWidth: screenWindow.width
117 implicitHeight: screenWindow.height
118 screen: screenWindow.screen
119 visible: true
120 coverActive: screenWindow.foldable && !screenWindow.foldOpen
121
122 deviceConfiguration {
123 overrideName: (!screenWindow.foldable && Screens.count > 1) ? "desktop" : false
124 }
125 }
126 }
127
128 Component {
129 id: blankComponent
130 Rectangle {
131 color: "black"
132 }
133 }
134
135 Component {
136 id: disabledScreenComponent
137 DisabledScreenNotice {
138 screen: screenWindow.screen
139 oskEnabled: Screens.count > 1
140 }
141 }
142}