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/>.
18import QtQuick.Window 2.2
19import Lomiri.InputInfo 0.1
20import Lomiri.Session 0.1
21import WindowManager 1.0
26// Workaround https://bugs.launchpad.net/lomiri/+source/lomiri/+bug/1473471
27import Lomiri.Components 1.3
32 implicitWidth: units.gu(40)
33 implicitHeight: units.gu(71)
35 property alias deviceConfiguration: _deviceConfiguration
36 property alias orientations: d.orientations
37 property bool lightIndicators: false
39 onWidthChanged: calculateUsageMode();
40 property var overrideDeviceName: screens.count > 1 ? "desktop" : false
43 id: _deviceConfiguration
45 // Override for convergence to set scale etc for second monitor
46 overrideName: root.overrideDeviceName
52 property Orientations orientations: Orientations {
54 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
55 native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
57 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
58 ? native_ : deviceConfiguration.primaryOrientation
60 landscape: deviceConfiguration.landscapeOrientation
61 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
62 portrait: deviceConfiguration.portraitOrientation
63 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
69 schema.id: "com.lomiri.Shell"
74 objectName: "oskSettings"
75 schema.id: "com.canonical.keyboard.maliit"
78 property int physicalOrientation: Screen.orientation
79 property bool orientationLocked: OrientationLock.enabled
80 property var orientationLock: OrientationLock
84 deviceFilter: InputInfo.Mouse
85 property int oldCount: 0
90 deviceFilter: InputInfo.TouchPad
91 property int oldCount: 0
96 deviceFilter: InputInfo.Keyboard
97 onDeviceAdded: forceOSKEnabled = autopilotDevicePresent();
98 onDeviceRemoved: forceOSKEnabled = autopilotDevicePresent();
102 id: touchScreensModel
103 deviceFilter: InputInfo.TouchScreen
108 property: "keyboardAttached"
109 value: keyboardsModel.count > 0
112 readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
113 onPointerInputDevicesChanged: calculateUsageMode()
115 function calculateUsageMode() {
116 if (lomiriSettings.usageMode === undefined)
117 return; // gsettings isn't loaded yet, we'll try again in Component.onCompleted
119 console.log("Calculating new usage mode. Pointer devices:", pointerInputDevices, "current mode:", lomiriSettings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount, "root width:", root.width / units.gu(1), "height:", root.height / units.gu(1))
120 if (lomiriSettings.usageMode === "Windowed") {
121 if (Math.min(root.width, root.height) > units.gu(60)) {
122 if (pointerInputDevices === 0) {
123 // All pointer devices have been unplugged. Move to staged.
124 lomiriSettings.usageMode = "Staged";
127 // The display is not large enough, use staged.
128 lomiriSettings.usageMode = "Staged";
131 if (Math.min(root.width, root.height) > units.gu(60)) {
132 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
133 lomiriSettings.usageMode = "Windowed";
136 // Make sure we initialize to something sane
137 lomiriSettings.usageMode = "Staged";
140 miceModel.oldCount = miceModel.count;
141 touchPadModel.oldCount = touchPadModel.count;
144 /* FIXME: This exposes the NameRole as a work arround for lp:1542224.
145 * When QInputInfo exposes NameRole to QML, this should be removed.
147 property bool forceOSKEnabled: false
148 property var autopilotEmulatedDeviceNames: ["py-evdev-uinput"]
149 LomiriSortFilterProxyModel {
151 model: keyboardsModel
154 function autopilotDevicePresent() {
155 for(var i = 0; i < autopilotDevices.count; i++) {
156 var device = autopilotDevices.get(i);
157 if (autopilotEmulatedDeviceNames.indexOf(device.name) != -1) {
158 console.warn("Forcing the OSK to be enabled as there is an autopilot eumlated device present.")
165 property int orientation
166 onPhysicalOrientationChanged: {
167 if (!orientationLocked) {
168 orientation = physicalOrientation;
171 onOrientationLockedChanged: {
172 if (orientationLocked) {
173 orientationLock.savedOrientation = physicalOrientation;
175 orientation = physicalOrientation;
178 Component.onCompleted: {
179 if (orientationLocked) {
180 orientation = orientationLock.savedOrientation;
183 calculateUsageMode();
185 // We need to manually update this on startup as the binding
186 // below doesn't seem to have any effect at that stage
187 oskSettings.disableHeight = !shell.oskEnabled || shell.usageScenario == "desktop"
190 // we must rotate to a supported orientation regardless of shell's preference
191 property bool orientationChangesEnabled:
192 (shell.orientation & supportedOrientations) === 0 ? true
193 : shell.orientationChangesEnabled
197 property: "disableHeight"
198 value: !shell.oskEnabled || shell.usageScenario == "desktop"
202 target: lomiriSettings
203 property: "oskSwitchVisible"
204 value: shell.hasKeyboard
207 readonly property int supportedOrientations: shell.supportedOrientations
208 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
209 ? orientations.native_
210 : deviceConfiguration.supportedOrientations)
212 property int acceptedOrientationAngle: {
213 if (orientation & supportedOrientations) {
214 return Screen.angleBetween(orientations.native_, orientation);
215 } else if (shell.orientation & supportedOrientations) {
217 return shell.orientationAngle;
218 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
219 return shell.mainAppWindowOrientationAngle;
221 // rotate to some supported orientation as we can't stay where we currently are
222 // TODO: Choose the closest to the current one
223 if (supportedOrientations & Qt.PortraitOrientation) {
224 return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
225 } else if (supportedOrientations & Qt.LandscapeOrientation) {
226 return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
227 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
228 return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
229 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
230 return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
232 // if all fails, fallback to primary orientation
233 return Screen.angleBetween(orientations.native_, orientations.primary);
238 function angleToOrientation(angle) {
241 return orientations.native_;
243 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
244 : Qt.PortraitOrientation;
246 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
247 : Qt.InvertedLandscapeOrientation;
249 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
250 : Qt.InvertedPortraitOrientation;
252 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
253 return orientations.primary;
259 objectName: "rotationStates"
262 shellCover: shellCover
263 shellSnapshot: shellSnapshot
271 orientation: root.angleToOrientation(orientationAngle)
272 orientations: root.orientations
273 nativeWidth: root.width
274 nativeHeight: root.height
275 mode: applicationArguments.mode
276 hasMouse: pointerInputDevices > 0
277 hasKeyboard: keyboardsModel.count > 0
278 hasTouchscreen: touchScreensModel.count > 0
279 supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
280 lightIndicators: root.lightIndicators
282 // Since we dont have proper multiscreen support yet
283 // hardcode screen count to only show osk on this screen
284 // when it's the only one connected.
285 // FIXME once multiscreen has landed
286 oskEnabled: (!hasKeyboard && Screens.count === 1) ||
287 lomiriSettings.alwaysShowOsk || forceOSKEnabled
290 if (lomiriSettings.usageMode === "Windowed") {
293 if (deviceConfiguration.category === "phone") {
301 property real transformRotationAngle
302 property real transformOriginX
303 property real transformOriginY
305 transform: Rotation {
306 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
307 angle: shell.transformRotationAngle
325 property real transformRotationAngle
326 property real transformOriginX
327 property real transformOriginY
329 transform: Rotation {
330 origin.x: shellSnapshot.transformOriginX; origin.y: shellSnapshot.transformOriginY;
331 axis { x: 0; y: 0; z: 1 }
332 angle: shellSnapshot.transformRotationAngle