@@ -57,7 +57,7 @@ Rectangle {
59 // to be overwritten by tests
59 // to be overwritten by tests
60− property var unity8Settings: Unity8Settings {}
60+ property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
61 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
61 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
63 property int physicalOrientation: Screen.orientation
63 property int physicalOrientation: Screen.orientation
@@ -67,11 +67,13 @@ Rectangle {
67 InputDeviceModel {
67 InputDeviceModel {
68 id: miceModel
68 id: miceModel
69 deviceFilter: InputInfo.Mouse
69 deviceFilter: InputInfo.Mouse
70+ property int oldCount: 0
72 InputDeviceModel {
73 InputDeviceModel {
73 id: touchPadModel
74 id: touchPadModel
74 deviceFilter: InputInfo.TouchPad
75 deviceFilter: InputInfo.TouchPad
76+ property int oldCount: 0
77 InputDeviceModel {
79 InputDeviceModel {
@@ -84,6 +86,29 @@ Rectangle {
84 deviceFilter: InputInfo.TouchScreen
86 deviceFilter: InputInfo.TouchScreen
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";
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";
104+ // Make sure we initialize to something sane
105+ root.unity8Settings.usageMode = "Staged";
108+ miceModel.oldCount = miceModel.count;
109+ touchPadModel.oldCount = touchPadModel.count;
87 Screens {
112 Screens {
88 id: screens
113 id: screens
@@ -197,30 +222,15 @@ Rectangle {
197 // screen (the virtual touchpad & osk on the phone) attached.
222 // screen (the virtual touchpad & osk on the phone) attached.
198 oskEnabled: keyboardsModel.count === 0 && screens.count === 1
223 oskEnabled: keyboardsModel.count === 0 && screens.count === 1
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.
202 usageScenario: {
225 usageScenario: {
203 if (root.unity8Settings.usageMode === "Windowed") {
226 if (root.unity8Settings.usageMode === "Windowed") {
204 return "desktop";
227 return "desktop";
205− } else if (root.unity8Settings.usageMode === "Staged") {
228+ } else {
206 if (deviceConfiguration.category === "phone") {
229 if (deviceConfiguration.category === "phone") {
207 return "phone";
230 return "phone";
209 return "tablet";
232 return "tablet";
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) {
217− } else if (longEdgeWidth > units.gu(90)){
218− if (miceModel.count + touchPadModel.count > 0) {
223− return deviceConfiguration.category;