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 Unity.InputInfo 0.1
20import Unity.Session 0.1
21import Unity.Screens 0.1
26// Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
27import Ubuntu.Components 1.3
32 implicitWidth: units.gu(40)
33 implicitHeight: units.gu(71)
35 onWidthChanged: calculateUsageMode();
38 id: deviceConfiguration
39 name: applicationArguments.deviceName
42 property alias orientations: d.orientations
47 property Orientations orientations: Orientations {
49 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
50 native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
52 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
53 ? native_ : deviceConfiguration.primaryOrientation
55 landscape: deviceConfiguration.landscapeOrientation
56 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
57 portrait: deviceConfiguration.portraitOrientation
58 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
64 schema.id: "com.canonical.Unity8"
69 objectName: "oskSettings"
70 schema.id: "com.canonical.keyboard.maliit"
73 property int physicalOrientation: Screen.orientation
74 property bool orientationLocked: OrientationLock.enabled
75 property var orientationLock: OrientationLock
79 deviceFilter: InputInfo.Mouse
80 property int oldCount: 0
85 deviceFilter: InputInfo.TouchPad
86 property int oldCount: 0
91 deviceFilter: InputInfo.Keyboard
92 onDeviceAdded: forceOSKEnabled = autopilotDevicePresent();
93 onDeviceRemoved: forceOSKEnabled = autopilotDevicePresent();
98 deviceFilter: InputInfo.TouchScreen
103 property: "keyboardAttached"
104 value: keyboardsModel.count > 0
107 readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
108 onPointerInputDevicesChanged: calculateUsageMode()
110 function calculateUsageMode() {
111 if (unity8Settings.usageMode === undefined)
112 return; // gsettings isn't loaded yet, we'll try again in Component.onCompleted
114 console.log("Calculating new usage mode. Pointer devices:", pointerInputDevices, "current mode:", unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount, "root width:", root.width / units.gu(1), "height:", root.height / units.gu(1))
115 if (unity8Settings.usageMode === "Windowed") {
116 if (Math.min(root.width, root.height) > units.gu(60)) {
117 if (pointerInputDevices === 0) {
118 // All pointer devices have been unplugged. Move to staged.
119 unity8Settings.usageMode = "Staged";
122 // The display is not large enough, use staged.
123 unity8Settings.usageMode = "Staged";
126 if (Math.min(root.width, root.height) > units.gu(60)) {
127 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
128 unity8Settings.usageMode = "Windowed";
131 // Make sure we initialize to something sane
132 unity8Settings.usageMode = "Staged";
135 miceModel.oldCount = miceModel.count;
136 touchPadModel.oldCount = touchPadModel.count;
139 /* FIXME: This exposes the NameRole as a work arround for lp:1542224.
140 * When QInputInfo exposes NameRole to QML, this should be removed.
142 property bool forceOSKEnabled: false
143 property var autopilotEmulatedDeviceNames: ["py-evdev-uinput"]
144 UnitySortFilterProxyModel {
146 model: keyboardsModel
149 function autopilotDevicePresent() {
150 for(var i = 0; i < autopilotDevices.count; i++) {
151 var device = autopilotDevices.get(i);
152 if (autopilotEmulatedDeviceNames.indexOf(device.name) != -1) {
153 console.warn("Forcing the OSK to be enabled as there is an autopilot eumlated device present.")
164 property int orientation
165 onPhysicalOrientationChanged: {
166 if (!orientationLocked) {
167 orientation = physicalOrientation;
170 onOrientationLockedChanged: {
171 if (orientationLocked) {
172 orientationLock.savedOrientation = physicalOrientation;
174 orientation = physicalOrientation;
177 Component.onCompleted: {
178 if (orientationLocked) {
179 orientation = orientationLock.savedOrientation;
182 calculateUsageMode();
184 // We need to manually update this on startup as the binding
185 // below doesn't seem to have any effect at that stage
186 oskSettings.disableHeight = !shell.oskEnabled || shell.usageScenario == "desktop"
189 // we must rotate to a supported orientation regardless of shell's preference
190 property bool orientationChangesEnabled:
191 (shell.orientation & supportedOrientations) === 0 ? true
192 : shell.orientationChangesEnabled
196 property: "disableHeight"
197 value: !shell.oskEnabled || shell.usageScenario == "desktop"
200 readonly property int supportedOrientations: shell.supportedOrientations
201 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
202 ? orientations.native_
203 : deviceConfiguration.supportedOrientations)
205 property int acceptedOrientationAngle: {
206 if (orientation & supportedOrientations) {
207 return Screen.angleBetween(orientations.native_, orientation);
208 } else if (shell.orientation & supportedOrientations) {
210 return shell.orientationAngle;
211 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
212 return shell.mainAppWindowOrientationAngle;
214 // rotate to some supported orientation as we can't stay where we currently are
215 // TODO: Choose the closest to the current one
216 if (supportedOrientations & Qt.PortraitOrientation) {
217 return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
218 } else if (supportedOrientations & Qt.LandscapeOrientation) {
219 return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
220 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
221 return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
222 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
223 return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
225 // if all fails, fallback to primary orientation
226 return Screen.angleBetween(orientations.native_, orientations.primary);
231 function angleToOrientation(angle) {
234 return orientations.native_;
236 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
237 : Qt.PortraitOrientation;
239 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
240 : Qt.InvertedLandscapeOrientation;
242 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
243 : Qt.InvertedPortraitOrientation;
245 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
246 return orientations.primary;
252 objectName: "rotationStates"
255 shellCover: shellCover
256 shellSnapshot: shellSnapshot
264 orientation: root.angleToOrientation(orientationAngle)
265 orientations: root.orientations
266 nativeWidth: root.width
267 nativeHeight: root.height
268 mode: applicationArguments.mode
269 hasMouse: pointerInputDevices > 0
270 hasKeyboard: keyboardsModel.count > 0
271 // TODO: Factor in if the current screen is a touch screen and if the user wants to
272 // have multiple keyboards around. For now we only enable one keyboard at a time
273 // thus hiding it here if there is a physical one around or if we have a second
274 // screen (the virtual touchpad & osk on the phone) attached.
275 oskEnabled: (keyboardsModel.count === 0 && screens.count === 1) ||
279 if (unity8Settings.usageMode === "Windowed") {
282 if (deviceConfiguration.category === "phone") {
290 property real transformRotationAngle
291 property real transformOriginX
292 property real transformOriginY
294 transform: Rotation {
295 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
296 angle: shell.transformRotationAngle
314 property real transformRotationAngle
315 property real transformOriginX
316 property real transformOriginY
318 transform: Rotation {
319 origin.x: shellSnapshot.transformOriginX; origin.y: shellSnapshot.transformOriginY;
320 axis { x: 0; y: 0; z: 1 }
321 angle: shellSnapshot.transformRotationAngle
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list