@@ -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