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/>.
18 import QtQuick.Window 2.2
19 import Unity.InputInfo 0.1
20 import Unity.Session 0.1
21 import Unity.Screens 0.1
26 // Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
27 import Ubuntu.Components 1.3
33 implicitWidth: units.gu(40)
34 implicitHeight: units.gu(71)
37 id: deviceConfiguration
38 name: applicationArguments.deviceName
41 property alias orientations: d.orientations
46 property Orientations orientations: Orientations {
48 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
49 native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
51 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
52 ? native_ : deviceConfiguration.primaryOrientation
54 landscape: deviceConfiguration.landscapeOrientation
55 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
56 portrait: deviceConfiguration.portraitOrientation
57 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
60 // to be overwritten by tests
61 property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
62 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
64 property int physicalOrientation: Screen.orientation
65 property bool orientationLocked: OrientationLock.enabled
66 property var orientationLock: OrientationLock
70 deviceFilter: InputInfo.Mouse
71 property int oldCount: 0
76 deviceFilter: InputInfo.TouchPad
77 property int oldCount: 0
82 deviceFilter: InputInfo.Keyboard
83 onDeviceAdded: forceOSKEnabled = autopilotDevicePresent();
84 onDeviceRemoved: forceOSKEnabled = autopilotDevicePresent();
89 deviceFilter: InputInfo.TouchScreen
92 readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
93 onPointerInputDevicesChanged: {
94 console.log("Pointer input devices changed:", pointerInputDevices, "current mode:", root.unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount)
95 if (root.unity8Settings.usageMode === "Windowed") {
96 if (pointerInputDevices === 0) {
97 // All pointer devices have been unplugged. Move to staged.
98 root.unity8Settings.usageMode = "Staged";
101 var longEdgeWidth = Math.max(root.width, root.height)
102 if (longEdgeWidth > units.gu(90)){
103 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
104 root.unity8Settings.usageMode = "Windowed";
107 // Make sure we initialize to something sane
108 root.unity8Settings.usageMode = "Staged";
111 miceModel.oldCount = miceModel.count;
112 touchPadModel.oldCount = touchPadModel.count;
115 /* FIXME: This exposes the NameRole as a work arround for lp:1542224.
116 * When QInputInfo exposes NameRole to QML, this should be removed.
118 property bool forceOSKEnabled: false
119 property var autopilotEmulatedDeviceNames: ["py-evdev-uinput"]
120 UnitySortFilterProxyModel {
122 model: keyboardsModel
125 function autopilotDevicePresent() {
126 for(var i = 0; i < autopilotDevices.count; i++) {
127 var device = autopilotDevices.get(i);
128 if (autopilotEmulatedDeviceNames.indexOf(device.name) != -1) {
129 console.warn("Forcing the OSK to be enabled as there is an autopilot eumlated device present.")
140 property int orientation
141 onPhysicalOrientationChanged: {
142 if (!orientationLocked) {
143 orientation = physicalOrientation;
146 onOrientationLockedChanged: {
147 if (orientationLocked) {
148 orientationLock.savedOrientation = physicalOrientation;
150 orientation = physicalOrientation;
153 Component.onCompleted: {
154 if (orientationLocked) {
155 orientation = orientationLock.savedOrientation;
157 // We need to manually update this on startup as the binding
158 // below doesn't seem to have any effect at that stage
159 oskSettings.disableHeight = !shell.oskEnabled || shell.usageScenario == "desktop"
162 // we must rotate to a supported orientation regardless of shell's preference
163 property bool orientationChangesEnabled:
164 (shell.orientation & supportedOrientations) === 0 ? true
165 : shell.orientationChangesEnabled
169 property: "disableHeight"
170 value: !shell.oskEnabled || shell.usageScenario == "desktop"
173 readonly property int supportedOrientations: shell.supportedOrientations
174 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
175 ? orientations.native_
176 : deviceConfiguration.supportedOrientations)
178 property int acceptedOrientationAngle: {
179 if (orientation & supportedOrientations) {
180 return Screen.angleBetween(orientations.native_, orientation);
181 } else if (shell.orientation & supportedOrientations) {
183 return shell.orientationAngle;
184 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
185 return shell.mainAppWindowOrientationAngle;
187 // rotate to some supported orientation as we can't stay where we currently are
188 // TODO: Choose the closest to the current one
189 if (supportedOrientations & Qt.PortraitOrientation) {
190 return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
191 } else if (supportedOrientations & Qt.LandscapeOrientation) {
192 return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
193 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
194 return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
195 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
196 return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
198 // if all fails, fallback to primary orientation
199 return Screen.angleBetween(orientations.native_, orientations.primary);
204 function angleToOrientation(angle) {
207 return orientations.native_;
209 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
210 : Qt.PortraitOrientation;
212 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
213 : Qt.InvertedLandscapeOrientation;
215 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
216 : Qt.InvertedPortraitOrientation;
218 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
219 return orientations.primary;
225 objectName: "rotationStates"
228 shellCover: shellCover
229 windowScreenshot: windowScreenshot
237 orientation: root.angleToOrientation(orientationAngle)
238 orientations: root.orientations
239 nativeWidth: root.width
240 nativeHeight: root.height
241 mode: applicationArguments.mode
242 hasMouse: miceModel.count + touchPadModel.count > 0
243 // TODO: Factor in if the current screen is a touch screen and if the user wants to
244 // have multiple keyboards around. For now we only enable one keyboard at a time
245 // thus hiding it here if there is a physical one around or if we have a second
246 // screen (the virtual touchpad & osk on the phone) attached.
247 oskEnabled: (keyboardsModel.count === 0 && screens.count === 1) ||
251 if (root.unity8Settings.usageMode === "Windowed") {
254 if (deviceConfiguration.category === "phone") {
262 property real transformRotationAngle
263 property real transformOriginX
264 property real transformOriginY
266 transform: Rotation {
267 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
268 angle: shell.transformRotationAngle
285 property real transformRotationAngle
286 property real transformOriginX
287 property real transformOriginY
289 transform: Rotation {
290 origin.x: windowScreenshot.transformOriginX; origin.y: windowScreenshot.transformOriginY;
291 axis { x: 0; y: 0; z: 1 }
292 angle: windowScreenshot.transformRotationAngle