2 * Copyright (C) 2015 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/>.
19import QtQuick.Window 2.2 as QtQuickWindow
20import Lomiri.InputInfo 0.1
21import Lomiri.Session 0.1
22import WindowManager 1.0
27// Workaround https://bugs.launchpad.net/lomiri/+source/lomiri/+bug/1473471
28import Lomiri.Components 1.3
33 implicitWidth: units.gu(40)
34 implicitHeight: units.gu(71)
36 property alias deviceConfiguration: _deviceConfiguration
37 property alias orientations: d.orientations
38 property bool lightIndicators: false
40 // The active cover panel of a foldable is mounted at an angle to the
41 // orientation sensor frame, so its native orientation is offset from
42 // what its pixel geometry implies (deviceConfiguration.coverOrientationAngle).
43 property bool coverActive: false
45 property var screen: null
48 function onFormFactorChanged() { calculateUsageMode(); }
51 onWidthChanged: calculateUsageMode();
52 property var overrideDeviceName: Screens.count > 1 ? "desktop" : false
55 id: _deviceConfiguration
57 // Override for convergence to set scale etc for second monitor
58 overrideName: root.overrideDeviceName
64 property Orientations orientations: Orientations {
66 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
67 native_: root.coverActive
68 ? root.rotateOrientation(root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation,
69 -deviceConfiguration.coverOrientationAngle)
70 : (root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation)
72 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
73 ? native_ : deviceConfiguration.primaryOrientation
75 landscape: deviceConfiguration.landscapeOrientation
76 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
77 portrait: deviceConfiguration.portraitOrientation
78 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
84 schema.id: "com.lomiri.Shell"
89 objectName: "oskSettings"
90 schema.id: "com.lomiri.keyboard.maliit"
93 property int physicalOrientation: QtQuickWindow.Screen.orientation
94 property bool orientationLocked: OrientationLock.enabled
95 property var orientationLock: OrientationLock
99 deviceFilter: InputInfo.Mouse
100 property int oldCount: 0
105 deviceFilter: InputInfo.TouchPad
106 property int oldCount: 0
111 deviceFilter: InputInfo.Keyboard
112 onDeviceAdded: forceOSKEnabled = autopilotDevicePresent();
113 onDeviceRemoved: forceOSKEnabled = autopilotDevicePresent();
117 id: touchScreensModel
118 deviceFilter: InputInfo.TouchScreen
123 property: "keyboardAttached"
124 value: keyboardsModel.count > 0
125 restoreMode: Binding.RestoreBinding
128 readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
129 onPointerInputDevicesChanged: calculateUsageMode()
131 function calculateUsageMode() {
132 if (lomiriSettings.usageMode === undefined)
133 return; // gsettings isn't loaded yet, we'll try again in Component.onCompleted
135 if (deviceConfiguration.foldable) {
136 // A foldable is a phone that happens to have two panels; its
137 // touchscreens expose touchpad input nodes, which would otherwise
138 // flip the shell into windowed/desktop mode. Keep it staged.
139 if (lomiriSettings.usageMode !== "Staged")
140 lomiriSettings.usageMode = "Staged";
144 console.log("Calculating new usage mode. Pointer devices:", pointerInputDevices, "current mode:", lomiriSettings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount, "root width:", root.width, "height:", root.height)
145 if (lomiriSettings.usageMode === "Windowed") {
146 if (Math.min(root.width, root.height) > units.gu(60)) {
147 if (pointerInputDevices === 0) {
148 // All pointer devices have been unplugged. Move to staged.
149 lomiriSettings.usageMode = "Staged";
152 // The display is not large enough, use staged.
153 lomiriSettings.usageMode = "Staged";
156 if (Math.min(root.width, root.height) > units.gu(60)) {
157 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
158 lomiriSettings.usageMode = "Windowed";
161 // Make sure we initialize to something sane
162 lomiriSettings.usageMode = "Staged";
165 miceModel.oldCount = miceModel.count;
166 touchPadModel.oldCount = touchPadModel.count;
169 /* FIXME: This exposes the NameRole as a work arround for lp:1542224.
170 * When QInputInfo exposes NameRole to QML, this should be removed.
172 property bool forceOSKEnabled: false
173 property var autopilotEmulatedDeviceNames: ["py-evdev-uinput"]
174 LomiriSortFilterProxyModel {
176 model: keyboardsModel
179 function autopilotDevicePresent() {
180 for(var i = 0; i < autopilotDevices.count; i++) {
181 var device = autopilotDevices.get(i);
182 if (autopilotEmulatedDeviceNames.indexOf(device.name) != -1) {
183 console.warn("Forcing the OSK to be enabled as there is an autopilot eumlated device present.")
190 property int orientation
191 onPhysicalOrientationChanged: {
192 if (!orientationLocked) {
193 orientation = physicalOrientation;
195 if (orientation !== physicalOrientation && !shell.showingGreeter) {
202 onOrientationLockedChanged: {
203 if (orientationLocked) {
204 orientationLock.savedOrientation = physicalOrientation;
206 orientation = physicalOrientation;
209 Component.onCompleted: {
210 if (orientationLocked) {
211 orientation = orientationLock.savedOrientation;
214 calculateUsageMode();
216 // We need to manually update this on startup as the binding
217 // below doesn't seem to have any effect at that stage
218 oskSettings.disableHeight = !shell.oskEnabled || shell.usageScenario == "desktop"
221 Component.onDestruction: {
222 const from_workspaces = root.screen.workspaces;
223 const from_workspaces_size = from_workspaces.count;
224 for (var i = 0; i < from_workspaces_size; i++) {
225 const from = from_workspaces.get(i);
226 WorkspaceManager.destroyWorkspace(from);
230 // we must rotate to a supported orientation regardless of shell's preference
231 property bool orientationChangesEnabled:
232 (shell.orientation & supportedOrientations) === 0 ? true
233 : shell.orientationChangesEnabled
237 restoreMode: Binding.RestoreBinding
238 property: "disableHeight"
239 value: !shell.oskEnabled || shell.usageScenario == "desktop"
243 target: lomiriSettings
244 restoreMode: Binding.RestoreBinding
245 property: "oskSwitchVisible"
246 value: shell.hasKeyboard
249 readonly property int supportedOrientations: shell.supportedOrientations
250 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
251 ? orientations.native_
252 : deviceConfiguration.supportedOrientations)
254 // During desktop mode switches back to phone mode Qt seems to swallow
255 // supported orientations by itself, not emitting them. Cause them to be emitted
256 // using the attached property here.
257 QtQuickWindow.Screen.orientationUpdateMask: supportedOrientations
259 property int acceptedOrientationAngle: {
260 if (orientation & supportedOrientations) {
261 return QtQuickWindow.Screen.angleBetween(orientations.native_, orientation);
262 } else if (shell.orientation & supportedOrientations) {
264 return shell.orientationAngle;
265 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
266 return shell.mainAppWindowOrientationAngle;
268 // rotate to some supported orientation as we can't stay where we currently are
269 // TODO: Choose the closest to the current one
270 if (supportedOrientations & Qt.PortraitOrientation) {
271 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
272 } else if (supportedOrientations & Qt.LandscapeOrientation) {
273 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
274 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
275 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
276 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
277 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
279 // if all fails, fallback to primary orientation
280 return QtQuickWindow.Screen.angleBetween(orientations.native_, orientations.primary);
285 function rotateOrientation(orientation, angle) {
286 var seq = [Qt.PortraitOrientation, Qt.LandscapeOrientation,
287 Qt.InvertedPortraitOrientation, Qt.InvertedLandscapeOrientation];
288 var idx = seq.indexOf(orientation);
291 return seq[((idx + Math.round(angle / 90)) % 4 + 4) % 4];
294 function angleToOrientation(angle) {
297 return orientations.native_;
299 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
300 : Qt.PortraitOrientation;
302 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
303 : Qt.InvertedLandscapeOrientation;
305 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
306 : Qt.InvertedPortraitOrientation;
308 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
309 return orientations.primary;
315 objectName: "rotationStates"
318 shellCover: shellCover
319 shellSnapshot: shellSnapshot
327 orientation: root.angleToOrientation(orientationAngle)
328 orientations: root.orientations
329 nativeWidth: root.width
330 nativeHeight: root.height
331 mode: applicationArguments.mode
332 hasMouse: pointerInputDevices > 0
333 hasKeyboard: keyboardsModel.count > 0
334 hasTouchscreen: touchScreensModel.count > 0
335 supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
336 lightIndicators: root.lightIndicators
337 oskEnabled: (!hasKeyboard && Screens.count === 1) ||
338 lomiriSettings.alwaysShowOsk || forceOSKEnabled
340 // Multiscreen support: in addition to judging by the device type, go by the screen type.
341 // This allows very flexible usecases beyond the typical "connect a phone to a monitor".
342 // Status quo setups:
343 // - phone + external monitor: virtual touchpad on the device
344 // - tablet + external monitor: dual-screen desktop
345 // - desktop: Has all the bells and whistles of a fully fledged PC/laptop shell
347 if (deviceConfiguration.foldable) return "phone";
348 if (lomiriSettings.usageMode === "Windowed") {
350 } else if (deviceConfiguration.category === "phone") {
352 } else if (deviceConfiguration.category === "tablet") {
355 if (screen.formFactor === Screen.Tablet) {
357 } else if (screen.formFactor === Screen.Phone) {
365 property real transformRotationAngle
366 property real transformOriginX
367 property real transformOriginY
369 transform: Rotation {
370 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
371 angle: shell.transformRotationAngle
378 screenOrientation: root.orientation
379 screenOrientationLocked: root.orientationLocked
382 orientationLock.savedOrientation = root.orientation
383 root.orientation = root.physicalOrientation
401 property real transformRotationAngle
402 property real transformOriginX
403 property real transformOriginY
405 transform: Rotation {
406 origin.x: shellSnapshot.transformOriginX; origin.y: shellSnapshot.transformOriginY;
407 axis { x: 0; y: 0; z: 1 }
408 angle: shellSnapshot.transformRotationAngle