2* Copyright (C) 2016 Canonical Ltd.
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.
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.
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/>.
18import Lomiri.Components 1.3
19import WindowManager 1.0
29 property int screenIndex: -1
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
38 readonly property bool primary: {
39 // If this is the only screen then it's the primary one
40 if (Screens.count === 1)
44 return foldOpen ? (screenIndex === 1) : (screenIndex === 0);
46 if ((deviceConfiguration.category == "phone" || deviceConfiguration.category == "tablet")
47 && Screens.count > 1 && screenIndex === 1)
50 return (Screens.count > 1 && screenIndex === 0)
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()
58 function applyGridUnit() {
59 if (!foldable || !primary)
61 var gu = foldOpen ? deviceConfiguration.innerGridUnit
62 : deviceConfiguration.coverGridUnit;
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");
76 xhr.open("GET", "file://" + deviceConfiguration.foldableSysfsPath);
81 Component.onCompleted: if (foldable) pollFold()
85 running: screenWindow.foldable
87 onTriggered: pollFold()
91 id: deviceConfiguration
96 width: screenWindow.width
97 height: screenWindow.height
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.
105 return blankComponent;
106 if (deviceConfiguration.category == "phone" || deviceConfiguration.category == "tablet")
107 return disabledScreenComponent;
109 return shellComponent;
116 implicitWidth: screenWindow.width
117 implicitHeight: screenWindow.height
118 screen: screenWindow.screen
120 coverActive: screenWindow.foldable && !screenWindow.foldOpen
122 deviceConfiguration {
123 overrideName: (!screenWindow.foldable && Screens.count > 1) ? "desktop" : false
136 id: disabledScreenComponent
137 DisabledScreenNotice {
138 screen: screenWindow.screen
139 oskEnabled: Screens.count > 1