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 as QtQuickWindow
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 property var screen: null
42 onFormFactorChanged: calculateUsageMode();
45 onWidthChanged: calculateUsageMode();
46 property var overrideDeviceName: Screens.count > 1 ? "desktop" : false
49 id: _deviceConfiguration
51 // Override for convergence to set scale etc for second monitor
52 overrideName: root.overrideDeviceName
58 property Orientations orientations: Orientations {
60 // NB: native and primary orientations here don't map exactly to their QScreen counterparts
61 native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
63 primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
64 ? native_ : deviceConfiguration.primaryOrientation
66 landscape: deviceConfiguration.landscapeOrientation
67 invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
68 portrait: deviceConfiguration.portraitOrientation
69 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
75 schema.id: "com.lomiri.Shell"
80 objectName: "oskSettings"
81 schema.id: "com.lomiri.keyboard.maliit"
84 property int physicalOrientation: QtQuickWindow.Screen.orientation
85 property bool orientationLocked: OrientationLock.enabled
86 property var orientationLock: OrientationLock
90 deviceFilter: InputInfo.Mouse
91 property int oldCount: 0
96 deviceFilter: InputInfo.TouchPad
97 property int oldCount: 0
102 deviceFilter: InputInfo.Keyboard
103 onDeviceAdded: forceOSKEnabled = autopilotDevicePresent();
104 onDeviceRemoved: forceOSKEnabled = autopilotDevicePresent();
108 id: touchScreensModel
109 deviceFilter: InputInfo.TouchScreen
114 property: "keyboardAttached"
115 value: keyboardsModel.count > 0
118 readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
119 onPointerInputDevicesChanged: calculateUsageMode()
121 function calculateUsageMode() {
122 if (lomiriSettings.usageMode === undefined)
123 return; // gsettings isn't loaded yet, we'll try again in Component.onCompleted
125 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)
126 if (lomiriSettings.usageMode === "Windowed") {
127 if (Math.min(root.width, root.height) > units.gu(60)) {
128 if (pointerInputDevices === 0) {
129 // All pointer devices have been unplugged. Move to staged.
130 lomiriSettings.usageMode = "Staged";
133 // The display is not large enough, use staged.
134 lomiriSettings.usageMode = "Staged";
137 if (Math.min(root.width, root.height) > units.gu(60)) {
138 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
139 lomiriSettings.usageMode = "Windowed";
142 // Make sure we initialize to something sane
143 lomiriSettings.usageMode = "Staged";
146 miceModel.oldCount = miceModel.count;
147 touchPadModel.oldCount = touchPadModel.count;
150 /* FIXME: This exposes the NameRole as a work arround for lp:1542224.
151 * When QInputInfo exposes NameRole to QML, this should be removed.
153 property bool forceOSKEnabled: false
154 property var autopilotEmulatedDeviceNames: ["py-evdev-uinput"]
155 LomiriSortFilterProxyModel {
157 model: keyboardsModel
160 function autopilotDevicePresent() {
161 for(var i = 0; i < autopilotDevices.count; i++) {
162 var device = autopilotDevices.get(i);
163 if (autopilotEmulatedDeviceNames.indexOf(device.name) != -1) {
164 console.warn("Forcing the OSK to be enabled as there is an autopilot eumlated device present.")
171 property int orientation
172 onPhysicalOrientationChanged: {
173 if (!orientationLocked) {
174 orientation = physicalOrientation;
176 if (orientation !== physicalOrientation && !shell.showingGreeter) {
183 onOrientationLockedChanged: {
184 if (orientationLocked) {
185 orientationLock.savedOrientation = physicalOrientation;
187 orientation = physicalOrientation;
190 Component.onCompleted: {
191 if (orientationLocked) {
192 orientation = orientationLock.savedOrientation;
195 calculateUsageMode();
197 // We need to manually update this on startup as the binding
198 // below doesn't seem to have any effect at that stage
199 oskSettings.disableHeight = !shell.oskEnabled || shell.usageScenario == "desktop"
202 Component.onDestruction: {
203 const from_workspaces = root.screen.workspaces;
204 const from_workspaces_size = from_workspaces.count;
205 for (var i = 0; i < from_workspaces_size; i++) {
206 const from = from_workspaces.get(i);
207 WorkspaceManager.destroyWorkspace(from);
211 // we must rotate to a supported orientation regardless of shell's preference
212 property bool orientationChangesEnabled:
213 (shell.orientation & supportedOrientations) === 0 ? true
214 : shell.orientationChangesEnabled
218 property: "disableHeight"
219 value: !shell.oskEnabled || shell.usageScenario == "desktop"
223 target: lomiriSettings
224 property: "oskSwitchVisible"
225 value: shell.hasKeyboard
228 readonly property int supportedOrientations: shell.supportedOrientations
229 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
230 ? orientations.native_
231 : deviceConfiguration.supportedOrientations)
233 // During desktop mode switches back to phone mode Qt seems to swallow
234 // supported orientations by itself, not emitting them. Cause them to be emitted
235 // using the attached property here.
236 QtQuickWindow.Screen.orientationUpdateMask: supportedOrientations
238 property int acceptedOrientationAngle: {
239 if (orientation & supportedOrientations) {
240 return QtQuickWindow.Screen.angleBetween(orientations.native_, orientation);
241 } else if (shell.orientation & supportedOrientations) {
243 return shell.orientationAngle;
244 } else if (angleToOrientation(shell.mainAppWindowOrientationAngle) & supportedOrientations) {
245 return shell.mainAppWindowOrientationAngle;
247 // rotate to some supported orientation as we can't stay where we currently are
248 // TODO: Choose the closest to the current one
249 if (supportedOrientations & Qt.PortraitOrientation) {
250 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
251 } else if (supportedOrientations & Qt.LandscapeOrientation) {
252 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
253 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
254 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
255 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
256 return QtQuickWindow.Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
258 // if all fails, fallback to primary orientation
259 return QtQuickWindow.Screen.angleBetween(orientations.native_, orientations.primary);
264 function angleToOrientation(angle) {
267 return orientations.native_;
269 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
270 : Qt.PortraitOrientation;
272 return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
273 : Qt.InvertedLandscapeOrientation;
275 return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
276 : Qt.InvertedPortraitOrientation;
278 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
279 return orientations.primary;
285 objectName: "rotationStates"
288 shellCover: shellCover
289 shellSnapshot: shellSnapshot
297 orientation: root.angleToOrientation(orientationAngle)
298 orientations: root.orientations
299 nativeWidth: root.width
300 nativeHeight: root.height
301 mode: applicationArguments.mode
302 hasMouse: pointerInputDevices > 0
303 hasKeyboard: keyboardsModel.count > 0
304 hasTouchscreen: touchScreensModel.count > 0
305 supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
306 lightIndicators: root.lightIndicators
307 oskEnabled: (!hasKeyboard && Screens.count === 1) ||
308 lomiriSettings.alwaysShowOsk || forceOSKEnabled
310 // Multiscreen support: in addition to judging by the device type, go by the screen type.
311 // This allows very flexible usecases beyond the typical "connect a phone to a monitor".
312 // Status quo setups:
313 // - phone + external monitor: virtual touchpad on the device
314 // - tablet + external monitor: dual-screen desktop
315 // - desktop: Has all the bells and whistles of a fully fledged PC/laptop shell
317 if (lomiriSettings.usageMode === "Windowed") {
319 } else if (deviceConfiguration.category === "phone") {
321 } else if (deviceConfiguration.category === "tablet") {
324 if (screen.formFactor === Screen.Tablet) {
326 } else if (shell.hasTouchscreen) {
328 } else if (screen.formFactor === Screen.Phone) {
336 property real transformRotationAngle
337 property real transformOriginX
338 property real transformOriginY
340 transform: Rotation {
341 origin.x: shell.transformOriginX; origin.y: shell.transformOriginY; axis { x: 0; y: 0; z: 1 }
342 angle: shell.transformRotationAngle
349 readonly property real visibleOpacity: 0.8
350 readonly property bool rotateAvailable: root.orientationLocked && root.physicalOrientation !== root.orientation
352 anchors.margins: units.gu(3)
355 when: !rotateButton.rotateAvailable
358 anchors.right: parent.left
359 anchors.top: parent.bottom
363 when: rotateButton.rotateAvailable && root.physicalOrientation == Qt.InvertedLandscapeOrientation
366 anchors.left: parent.left
367 anchors.bottom: parent.bottom
371 when: rotateButton.rotateAvailable && root.physicalOrientation == Qt.LandscapeOrientation
374 anchors.right: parent.right
375 anchors.top: parent.top
379 anchors.topMargin: shell.shellMargin
383 when: rotateButton.rotateAvailable && root.physicalOrientation == Qt.PortraitOrientation
386 anchors.right: parent.right
387 anchors.bottom: parent.bottom
391 when: rotateButton.rotateAvailable && root.physicalOrientation == Qt.InvertedPortraitOrientation
394 anchors.left: parent.left
395 anchors.top: parent.top
399 anchors.topMargin: shell.shellMargin
408 color: theme.palette.normal.background
411 color: theme.palette.normal.backgroundText
421 hideAnimation.restart()
428 implicitWidth: units.gu(3)
429 implicitHeight: implicitWidth
430 anchors.centerIn: parent
432 color: theme.palette.normal.backgroundText
439 orientationLock.savedOrientation = root.orientation
440 root.orientation = root.physicalOrientation
444 LomiriNumberAnimation {
451 to: rotateButton.visibleOpacity
452 duration: LomiriAnimation.SlowDuration
455 LomiriNumberAnimation {
463 duration: LomiriAnimation.FastDuration
466 SequentialAnimation {
467 running: rotateButton.visible
471 duration: LomiriAnimation.SnapDuration
473 direction: RotationAnimation.Shortest
475 NumberAnimation { target: icon; duration: LomiriAnimation.SnapDuration; property: "opacity"; to: 1 }
476 PauseAnimation { duration: LomiriAnimation.SlowDuration }
479 duration: LomiriAnimation.SlowDuration
480 to: root.orientationLocked ? QtQuickWindow.Screen.angleBetween(root.orientation, root.physicalOrientation) : 0
481 direction: RotationAnimation.Shortest
483 PauseAnimation { duration: LomiriAnimation.SlowDuration }
484 NumberAnimation { target: icon; duration: LomiriAnimation.SnapDuration; property: "opacity"; to: 0 }
486 onFinished: rotateButton.hide()
495 showAnimation.restart()
504 onTriggered: rotateButton.hide()
522 property real transformRotationAngle
523 property real transformOriginX
524 property real transformOriginY
526 transform: Rotation {
527 origin.x: shellSnapshot.transformOriginX; origin.y: shellSnapshot.transformOriginY;
528 axis { x: 0; y: 0; z: 1 }
529 angle: shellSnapshot.transformRotationAngle