on xenial help sign in
merge lp:~mzanetti/unity8/better-windowed-logic
commitd8374b91c593f4ce067852e135ec43ce6774fff9 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 8 Mar 2016, 15:30 (11 years ago) parent51e24ac895dd86
2 files changed+27−67
qml/Components/Unity8Settings.qml−50 qml/OrientedShell.qml+27−17
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+27−17
@@ -57,7 +57,7 @@ Rectangle {
5757 }
5858 }
5959 // to be overwritten by tests
60− property var unity8Settings: Unity8Settings {}
60+ property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
6161 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
6262
6363 property int physicalOrientation: Screen.orientation
@@ -67,11 +67,13 @@ Rectangle {
6767 InputDeviceModel {
6868 id: miceModel
6969 deviceFilter: InputInfo.Mouse
70+ property int oldCount: 0
7071 }
7172
7273 InputDeviceModel {
7374 id: touchPadModel
7475 deviceFilter: InputInfo.TouchPad
76+ property int oldCount: 0
7577 }
7678
7779 InputDeviceModel {
@@ -84,6 +86,29 @@ Rectangle {
8486 deviceFilter: InputInfo.TouchScreen
8587 }
8688
89+ readonly property int pointerInputDevices: miceModel.count + touchPadModel.count
90+ onPointerInputDevicesChanged: {
91+ console.log("Pointer input devices changed:", pointerInputDevices, "current mode:", root.unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount)
92+ if (root.unity8Settings.usageMode === "Windowed") {
93+ if (pointerInputDevices === 0) {
94+ // All pointer devices have been unplugged. Move to staged.
95+ root.unity8Settings.usageMode = "Staged";
96+ }
97+ } else {
98+ var longEdgeWidth = Math.max(root.width, root.height)
99+ if (longEdgeWidth > units.gu(90)){
100+ if (pointerInputDevices > 0 && pointerInputDevices > 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+ }
111+
87112 Screens {
88113 id: screens
89114 }
@@ -197,30 +222,15 @@ Rectangle {
197222 // screen (the virtual touchpad & osk on the phone) attached.
198223 oskEnabled: keyboardsModel.count === 0 && screens.count === 1
199224
200− // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
201− // what's the output device (eg: big TV, desktop monitor, phone display), etc.
202225 usageScenario: {
203226 if (root.unity8Settings.usageMode === "Windowed") {
204227 return "desktop";
205− } else if (root.unity8Settings.usageMode === "Staged") {
228+ } else {
206229 if (deviceConfiguration.category === "phone") {
207230 return "phone";
208231 } else {
209232 return "tablet";
210233 }
211− } else { // automatic
212− var longEdgeWidth = Math.max(root.width, root.height)
213− if (longEdgeWidth > units.gu(120)) {
214− if (keyboardsModel.count + miceModel.count + touchPadModel.count > 0) {
215− return "desktop";
216− }
217− } else if (longEdgeWidth > units.gu(90)){
218− if (miceModel.count + touchPadModel.count > 0) {
219− return "desktop";
220− }
221− }
222−
223− return deviceConfiguration.category;
224234 }
225235 }
226236