on xenial help sign in
redo inputinfo on top of rebased shellRotation
commit337d81985480958a2ea1be19e74573abeaa0c946 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 9 Mar 2015, 13:17 (12 years ago) parente15956d
4 files changed+112−6
data/com.canonical.Unity8.gschema.xml+2−1 debian/unity8.install+1 qml/OrientedShell.qml+39−5 qml/UnityInputInfo.qml+70
data/com.canonical.Unity8.gschema.xml+2−1
@@ -2,11 +2,12 @@
22 <enum id="usage-mode-enum">
33 <value nick="Staged" value="0" />
44 <value nick="Windowed" value="1" />
5+ <value nick="Automatic" value="2" />
56 </enum>
67
78 <schema path="/com/canonical/unity8/" id="com.canonical.Unity8" gettext-domain="unity8">
89 <key enum="usage-mode-enum" name="usage-mode">
9− <default>"Staged"</default>
10+ <default>"Automatic"</default>
1011 <summary>The usage mode.</summary>
1112 <description>The usage mode chosen will affect the Window Management behaviour.</description>
1213 </key>
debian/unity8.install+1
@@ -9,6 +9,7 @@ usr/share/unity8/Greeter
99usr/share/unity8/Launcher
1010usr/share/unity8/Panel
1111usr/share/unity8/Rotation
12+usr/share/unity8/UnityInputInfo.qml
1213usr/share/unity8/DeviceConfiguration.qml
1314usr/share/unity8/OrientedShell.qml
1415usr/share/unity8/Shell.qml
qml/OrientedShell.qml+39−5
@@ -37,6 +37,33 @@ Rectangle {
3737 name: applicationArguments.deviceName
3838 }
3939
40+ UnityInputInfo {
41+ id: inputInfo
42+ Component.onCompleted: {
43+ // We need to manually update this on startup as the binding
44+ // below doesn't seem to have any effect at that stage
45+ oskSettings.stayHidden = keyboards > 0
46+ oskSettings.disableHeight = shell.usageScenario == "desktop"
47+ }
48+ }
49+
50+ GSettings {
51+ id: oskSettings
52+ schema.id: "com.canonical.keyboard.maliit"
53+ }
54+
55+ Binding {
56+ target: oskSettings
57+ property: "stayHidden"
58+ value: inputInfo.keyboards > 0
59+ }
60+
61+ Binding {
62+ target: oskSettings
63+ property: "disableHeight"
64+ value: shell.usageScenario == "desktop"
65+ }
66+
4067 // to be overwritten by tests
4168 property var usageModeSettings: GSettings { schema.id: "com.canonical.Unity8" }
4269 property int physicalOrientation: Screen.orientation
@@ -138,11 +165,18 @@ Rectangle {
138165 usageScenario: {
139166 if (root.usageModeSettings.usageMode === "Windowed") {
140167 return "desktop";
141− } else if (root.usageModeSettings.usageMode === "Staged"
142− && deviceConfiguration.category === "desktop") {
143− return "tablet";
144− } else {
145− return deviceConfiguration.category;
168+ } else if (root.usageModeSettings.usageMode === "Staged") {
169+ if (deviceConfiguration.category === "phone") {
170+ return "phone";
171+ } else {
172+ return "tablet";
173+ }
174+ } else { // automatic
175+ if (inputInfo.mice > 0) {
176+ return "desktop";
177+ } else {
178+ return deviceConfiguration.category;
179+ }
146180 }
147181 }
148182
qml/UnityInputInfo.qmlnew file+70
@@ -0,0 +1,70 @@
1+import QtQuick 2.3
2+import QtSystemInfo 5.0
3+
4+Item {
5+ id: root
6+ readonly property alias mice: priv.miceCount
7+ readonly property alias keyboards: priv.keyboardCount
8+
9+ QtObject {
10+ id: priv
11+
12+ property var mice: new Array()
13+ property var keyboards: new Array()
14+
15+ property int miceCount: 0
16+ property int keyboardCount: 0
17+
18+ function addMouse(devicePath) {
19+ mice.push(devicePath);
20+ miceCount++;
21+ }
22+
23+ function addKeyboard(devicePath) {
24+ keyboards.push(devicePath);
25+ keyboardCount++;
26+ }
27+
28+ function removeDevice(devicePath) {
29+ for (var i = 0; i < priv.mice.length; i++) {
30+ if (priv.mice[i] == devicePath) {
31+ priv.mice.splice(i, 1);
32+ priv.miceCount--;
33+ }
34+ }
35+ for (var i = 0; i < priv.keyboards.length; i++) {
36+ if (priv.keyboards[i] == devicePath) {
37+ priv.keyboards.splice(i, 1);
38+ priv.keyboardCount--;
39+ }
40+ }
41+ }
42+ }
43+
44+ InputDeviceInfo {
45+ id: inputInfo
46+
47+ onNewDevice: {
48+ var device = inputInfo.get(inputInfo.indexOf(devicePath));
49+ if (device === null) {
50+ return;
51+ }
52+
53+ var hasMouse = (device.types & InputInfo.Mouse) == InputInfo.Mouse
54+ var hasTouchpad = (device.types & InputInfo.TouchPad) == InputInfo.TouchPad
55+ var hasKeyboard = (device.types & InputInfo.Keyboard) == InputInfo.Keyboard
56+
57+ if (hasMouse || hasTouchpad) {
58+ priv.addMouse(devicePath);
59+ } else if (hasKeyboard) {
60+ // Only accepting keyboards that do not claim to be a mouse too
61+ // This will be a bit buggy for real hybrid devices, but doesn't
62+ // fall for Microsoft mice that claim to be Keyboards too.
63+ priv.addKeyboard(devicePath)
64+ }
65+ }
66+ onDeviceRemoved: {
67+ priv.removeDevice(devicePath)
68+ }
69+ }
70+}