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.Session 0.1
22 import "Components/UnityInputInfo"
24 // Backup Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
25 // in case we remove the UnityInputInfo import
26 import Ubuntu.Components 1.3
32 implicitWidth: units.gu(40)
33 implicitHeight: units.gu(71)
36 id: deviceConfiguration
37 name: applicationArguments.deviceName
40 property alias orientations: d.orientations
45 property Orientations orientations: Orientations {
47 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
48 native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
50 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
51 ? native_ : deviceConfiguration.primaryOrientation
53 landscape: deviceConfiguration.landscapeOrientation
54 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
55 portrait: deviceConfiguration.portraitOrientation
56 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
59 // to be overwritten by tests
60 property var unity8Settings: Unity8Settings {}
61 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
63 property int physicalOrientation: Screen.orientation
64 property bool orientationLocked: OrientationLock.enabled
65 property var orientationLock: OrientationLock
67 property int orientation
68 onPhysicalOrientationChanged: {
69 if (!orientationLocked) {
70 orientation = physicalOrientation;
73 onOrientationLockedChanged: {
74 if (orientationLocked) {
75 orientationLock.savedOrientation = physicalOrientation;
77 orientation = physicalOrientation;
80 Component.onCompleted: {
81 if (orientationLocked) {
82 orientation = orientationLock.savedOrientation;
84 // We need to manually update this on startup as the binding
85 // below doesn't seem to have any effect at that stage
86 oskSettings.stayHidden = UnityInputInfo.keyboards > 0
87 oskSettings.disableHeight = shell.usageScenario == "desktop"
90 // we must rotate to a supported orientation regardless of shell's preference
91 property bool orientationChangesEnabled:
92 (shell.orientation & supportedOrientations) === 0 ? true
93 : shell.orientationChangesEnabled
98 property: "stayHidden"
99 value: UnityInputInfo.keyboards > 0
104 property: "disableHeight"
105 value: shell.usageScenario == "desktop"
108 readonly property int supportedOrientations: shell.supportedOrientations
109 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
110 ? orientations.native_
111 : deviceConfiguration.supportedOrientations)
113 property int acceptedOrientationAngle: {
114 if (orientation & supportedOrientations) {
115 return Screen.angleBetween(orientations.native_, orientation);
116 } else if (shell.orientation & supportedOrientations) {
118 return shell.orientationAngle;
119 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
120 return shell.mainAppWindowOrientationAngle;
122 // rotate to some supported orientation as we can't stay where we currently are
123 // TODO: Choose the closest to the current one
124 if (supportedOrientations & Qt.PortraitOrientation) {
125 return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
126 } else if (supportedOrientations & Qt.LandscapeOrientation) {
127 return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
128 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
129 return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
130 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
131 return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
133 // if all fails, fallback to primary orientation
134 return Screen.angleBetween(orientations.native_, orientations.primary);
139 function angleToOrientation(angle) {
142 return orientations.native_;
144 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
145 : Qt.PortraitOrientation;
147 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
148 : Qt.InvertedLandscapeOrientation;
150 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
151 : Qt.InvertedPortraitOrientation;
153 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
154 return orientations.primary;
160 objectName: "rotationStates"
163 shellCover: shellCover
164 windowScreenshot: windowScreenshot
172 orientation: root.angleToOrientation(orientationAngle)
173 orientations: root.orientations
174 nativeWidth: root.width
175 nativeHeight: root.height
176 mode: applicationArguments.mode
177 hasMouse: UnityInputInfo.mice > deviceConfiguration.ignoredMice
179 // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
180 // what's the output device (eg: big TV, desktop monitor, phone display), etc.
182 if (root.unity8Settings.usageMode === "Windowed") {
184 } else if (root.unity8Settings.usageMode === "Staged") {
185 if (deviceConfiguration.category === "phone") {
190 } else { // automatic
191 if (UnityInputInfo.mice > deviceConfiguration.ignoredMice) {
194 return deviceConfiguration.category;
199 property real transformRotationAngle
200 property real transformOriginX
201 property real transformOriginY
203 transform: Rotation {
204 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
205 angle: shell.transformRotationAngle
222 property real transformRotationAngle
223 property real transformOriginX
224 property real transformOriginY
226 transform: Rotation {
227 origin.x: windowScreenshot.transformOriginX; origin.y: windowScreenshot.transformOriginY;
228 axis { x: 0; y: 0; z: 1 }
229 angle: windowScreenshot.transformRotationAngle