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
21 // Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
22 import Ubuntu.Components 1.3
26 readonly property alias mice: priv.miceCount
27 readonly property alias keyboards: priv.keyboardCount
29 property alias inputInfo: inputInfo
35 property var keyboards: []
37 property int miceCount: 0
38 property int keyboardCount: 0
40 function addMouse(devicePath) {
41 mice.push(devicePath);
45 function addKeyboard(devicePath) {
46 keyboards.push(devicePath);
50 function removeDevice(devicePath) {
51 for (var i = 0; i < priv.mice.length; i++) {
52 if (priv.mice[i] == devicePath) {
53 priv.mice.splice(i, 1);
57 for (var i = 0; i < priv.keyboards.length; i++) {
58 if (priv.keyboards[i] == devicePath) {
59 priv.keyboards.splice(i, 1);
68 objectName: "inputDeviceInfo"
71 var device = inputInfo.get(inputInfo.indexOf(devicePath));
72 if (device === null) {
76 var hasMouse = (device.types & InputInfo.Mouse) == InputInfo.Mouse
77 var hasTouchpad = (device.types & InputInfo.TouchPad) == InputInfo.TouchPad
78 var hasKeyboard = (device.types & InputInfo.Keyboard) == InputInfo.Keyboard
80 if (hasMouse || hasTouchpad) {
81 priv.addMouse(devicePath);
82 } else if (hasKeyboard) {
83 // Only accepting keyboards that do not claim to be a mouse too
84 // This will be a bit buggy for real hybrid devices, but doesn't
85 // fall for Microsoft mice that claim to be Keyboards too.
86 priv.addKeyboard(devicePath)
90 priv.removeDevice(devicePath)