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