@@ -56,7 +56,7 @@ Rectangle {
58 // to be overwritten by tests
58 // to be overwritten by tests
59− property var unity8Settings: Unity8Settings {}
59+ property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
60 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
60 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
62 property int physicalOrientation: Screen.orientation
62 property int physicalOrientation: Screen.orientation
@@ -66,16 +66,48 @@ Rectangle {
66 InputDeviceModel {
66 InputDeviceModel {
67 id: miceModel
67 id: miceModel
68 deviceFilter: InputInfo.Mouse
68 deviceFilter: InputInfo.Mouse
69+ property int oldCount: 0
71 InputDeviceModel {
72 InputDeviceModel {
72 id: touchPadModel
73 id: touchPadModel
73 deviceFilter: InputInfo.TouchPad
74 deviceFilter: InputInfo.TouchPad
75+ property int oldCount: 0
76 InputDeviceModel {
78 InputDeviceModel {
77 id: keyboardsModel
79 id: keyboardsModel
78 deviceFilter: InputInfo.Keyboard
80 deviceFilter: InputInfo.Keyboard
81+ property int oldCount: 0
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";
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"
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";
104+ // Make sure we initialize to something sane
105+ root.unity8Settings.usageMode = "Staged";
108+ miceModel.oldCount = miceModel.count;
109+ touchPadModel.oldCount = touchPadModel.count;
110+ keyboardsModel.oldCount = keyboardsModel.count;
81 property int orientation
113 property int orientation
@@ -190,32 +222,15 @@ Rectangle {
190 mode: applicationArguments.mode
222 mode: applicationArguments.mode
191 hasMouse: miceModel.count + touchPadModel.count > 0
223 hasMouse: miceModel.count + touchPadModel.count > 0
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.
195 usageScenario: {
225 usageScenario: {
196 if (root.unity8Settings.usageMode === "Windowed") {
226 if (root.unity8Settings.usageMode === "Windowed") {
197 return "desktop";
227 return "desktop";
198− } else if (root.unity8Settings.usageMode === "Staged") {
228+ } else if (root.unity8Settings.usageMode === "Staged"){
199 if (deviceConfiguration.category === "phone") {
229 if (deviceConfiguration.category === "phone") {
200 return "phone";
230 return "phone";
202 return "tablet";
232 return "tablet";
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) {
212− } else if (longEdgeWidth > units.gu(90)){
213− if (miceModel.count + touchPadModel.count > 0) {
218− return deviceConfiguration.category;