2 * Copyright 2015 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import Unity.InputInfo 0.1
24 readonly property alias mice: priv.miceCount
25 readonly property alias keyboards: priv.keyboardCount
27 property alias inputInfo: inputInfo
33 property var keyboards: []
35 property int miceCount: 0
36 property int keyboardCount: 0
38 function addMouse(devicePath) {
39 mice.push(devicePath);
43 function addKeyboard(devicePath) {
44 keyboards.push(devicePath);
48 function removeDevice(devicePath) {
49 for (var i = 0; i < priv.mice.length; i++) {
50 if (priv.mice[i] == devicePath) {
51 priv.mice.splice(i, 1);
55 for (var i = 0; i < priv.keyboards.length; i++) {
56 if (priv.keyboards[i] == devicePath) {
57 priv.keyboards.splice(i, 1);
66 objectName: "inputDeviceInfo"
69 var device = inputInfo.get(inputInfo.indexOf(devicePath));
70 if (device === null) {
74 var hasMouse = (device.types & InputInfo.Mouse) == InputInfo.Mouse
75 var hasTouchpad = (device.types & InputInfo.TouchPad) == InputInfo.TouchPad
76 var hasKeyboard = (device.types & InputInfo.Keyboard) == InputInfo.Keyboard
78 if (hasMouse || hasTouchpad) {
79 priv.addMouse(devicePath);
80 } else if (hasKeyboard) {
81 // Only accepting keyboards that do not claim to be a mouse too
82 // This will be a bit buggy for real hybrid devices, but doesn't
83 // fall for Microsoft mice that claim to be Keyboards too.
84 priv.addKeyboard(devicePath)
88 priv.removeDevice(devicePath)