on xenial help sign in
change window switching logic to something that works better with a manual switch
commit50c0064c98455957f66fb6e23e56a3636b256a6a authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 2 Feb 2016, 14:11 (11 years ago) parentcad5529
2 files changed+34−69
qml/Components/Unity8Settings.qml−50 qml/OrientedShell.qml+34−19
qml/Components/Unity8Settings.qmldeleted−50
@@ -1,50 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
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.
7− *
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.
12− *
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/>.
15− */
16−
17−import QtQuick 2.4
18−import GSettings 1.0
19−
20−QtObject {
21− id: root
22−
23− property string usageMode: "Staged"
24−
25− // FIXME: Works around a bug where if we change a Loader's source in response to a GSettings
26− // property change in the same event loop, the Loader's previously loaded component does not
27− // get destroyed and its bindings continue to operate!
28− //
29− // Shouldn't be needed after
30− // https://code.launchpad.net/~lukas-kde/gsettings-qt/queued-processing/+merge/259883 gets
31− // merged.
32− property var timer: Timer {
33− interval: 1
34− onTriggered: { root.usageMode = root.wrapped.usageMode; }
35− }
36− property var wrappedConnections: Connections {
37− target: root.wrapped
38− ignoreUnknownSignals: true // don't spam us
39− onUsageModeChanged: { root.timer.start(); }
40− }
41− property var wrapped: GSettings {
42− schema.id: "com.canonical.Unity8"
43− Component.onCompleted: {
44− // init the value. it's a dynamic prop, so we have to check first
45− if (root.usageMode) {
46− root.usageMode = root.wrapped.usageMode;
47− }
48− }
49− }
50−}
qml/OrientedShell.qml+34−19
@@ -56,7 +56,7 @@ Rectangle {
5656 }
5757 }
5858 // to be overwritten by tests
59− property var unity8Settings: Unity8Settings {}
59+ property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
6060 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
6161
6262 property int physicalOrientation: Screen.orientation
@@ -66,16 +66,48 @@ Rectangle {
6666 InputDeviceModel {
6767 id: miceModel
6868 deviceFilter: InputInfo.Mouse
69+ property int oldCount: 0
6970 }
7071
7172 InputDeviceModel {
7273 id: touchPadModel
7374 deviceFilter: InputInfo.TouchPad
75+ property int oldCount: 0
7476 }
7577
7678 InputDeviceModel {
7779 id: keyboardsModel
7880 deviceFilter: InputInfo.Keyboard
81+ property int oldCount: 0
82+ }
83+ readonly property int physicalInputDevices: miceModel.count + keyboardsModel.count + touchPadModel.count
84+ onPhysicalInputDevicesChanged: {
85+ console.log("Input devices changed:", physicalInputDevices, "current mode:", root.unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount + keyboardsModel.oldCount)
86+ if (root.unity8Settings.usageMode === "Windowed") {
87+ if (physicalInputDevices === 0) {
88+ // All devices have been unplugged. Move to staged.
89+ root.unity8Settings.usageMode = "Staged";
90+ }
91+ } else {
92+ var longEdgeWidth = Math.max(root.width, root.height)
93+ if (longEdgeWidth > units.gu(120)) {
94+ if (keyboardsModel.count + miceModel.count + touchPadModel.count > 0 &&
95+ physicalInputDevices > miceModel.oldCount + touchPadModel.oldCount + keyboardsModel.oldCount) {
96+ root.unity8Settings.usageMode = "Windowed"
97+ }
98+ } else if (longEdgeWidth > units.gu(90)){
99+ if (miceModel.count + touchPadModel.count > 0 &&
100+ miceModel.count + touchPadModel.count > miceModel.oldCount + touchPadModel.oldCount) {
101+ root.unity8Settings.usageMode = "Windowed";
102+ }
103+ } else {
104+ // Make sure we initialize to something sane
105+ root.unity8Settings.usageMode = "Staged";
106+ }
107+ }
108+ miceModel.oldCount = miceModel.count;
109+ touchPadModel.oldCount = touchPadModel.count;
110+ keyboardsModel.oldCount = keyboardsModel.count;
79111 }
80112
81113 property int orientation
@@ -190,32 +222,15 @@ Rectangle {
190222 mode: applicationArguments.mode
191223 hasMouse: miceModel.count + touchPadModel.count > 0
192224
193− // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
194− // what's the output device (eg: big TV, desktop monitor, phone display), etc.
195225 usageScenario: {
196226 if (root.unity8Settings.usageMode === "Windowed") {
197227 return "desktop";
198− } else if (root.unity8Settings.usageMode === "Staged") {
228+ } else if (root.unity8Settings.usageMode === "Staged"){
199229 if (deviceConfiguration.category === "phone") {
200230 return "phone";
201231 } else {
202232 return "tablet";
203233 }
204− } else { // automatic
205− var longEdgeWidth = Math.max(root.width, root.height)
206− print("Automatic mode:", longEdgeWidth, "gu size", units.gu(1), "kbds", keyboardsModel.count, "mice", miceModel.count + touchPadModel.count, root)
207− if (longEdgeWidth > units.gu(120)) {
208− print("longedge is big!")
209− if (keyboardsModel.count + miceModel.count + touchPadModel.count > 0) {
210− return "desktop";
211− }
212− } else if (longEdgeWidth > units.gu(90)){
213− if (miceModel.count + touchPadModel.count > 0) {
214− return "desktop";
215− }
216− }
217−
218− return deviceConfiguration.category;
219234 }
220235 }
221236