on xenial help sign in
Added a snapshot of the WIP Qt InputInfo API

https://codereview.qt-project.org/#/c/101049/ The API is not really great yet, but it works. Instead of coming up with something ourselves this should be synced with the upstream api and eventually be dropped when the InputInfo API lands in QtSystemInfo. Approved by: Lukáš Tinkl

commit23ba646f7c92f4f3d53338c4e5f7f71039652b43 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 2 Jul 2015, 16:08 (11 years ago) parent4b10ec33d09fe2
13 files changed+984
debian/changelog+6 debian/control+2 plugins/Unity/CMakeLists.txt+1 plugins/Unity/InputInfo/CMakeLists.txt+39 plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cpp+249 plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.h+91 plugins/Unity/InputInfo/plugin.cpp+32 plugins/Unity/InputInfo/plugin.h+30 plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cpp+143 plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.h+86 plugins/Unity/InputInfo/qinputinfo.cpp+159 plugins/Unity/InputInfo/qinputinfo.h+143 plugins/Unity/InputInfo/qmldir+3
debian/changelog+6
@@ -59,6 +59,12 @@ unity8 (8.10+15.10.20150612-0ubuntu1) wily; urgency=medium
5959
6060 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 12 Jun 2015 16:07:47 +0000
6161
62+unity8 (8.10-0ubuntu1) UNRELEASED; urgency=medium
63+
64+ * Implement full-shell rotation (LP: #1210199)
65+
66+ -- Michał Sawicz <michal.sawicz@canonical.com> Wed, 15 Apr 2015 14:47:17 +0200
67+
6268unity8 (8.02+15.10.20150603.1-0ubuntu1) wily; urgency=medium
6369
6470 [ CI Train Bot ]
debian/control+2
@@ -16,6 +16,7 @@ Build-Depends: cmake,
1616 graphviz,
1717 gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),
1818 libconnectivity-qt1-dev,
19+ libevdev-dev,
1920 libgl1-mesa-dev[!armhf] | libgl-dev[!armhf],
2021 libgl1-mesa-dri,
2122 libgles2-mesa-dev[armhf],
@@ -28,6 +29,7 @@ Build-Depends: cmake,
2829 libqmenumodel-dev (>= 0.2.9),
2930 libqt5xmlpatterns5-dev,
3031 libsystemsettings-dev,
32+ libudev-dev,
3133 libunity-api-dev (>= 7.97),
3234 libusermetricsoutput1-dev,
3335 libxcb1-dev,
plugins/Unity/CMakeLists.txt+1
@@ -3,3 +3,4 @@ add_subdirectory(Indicators)
33add_subdirectory(Launcher)
44add_subdirectory(Session)
55add_subdirectory(DashCommunicator)
6+add_subdirectory(InputInfo)
plugins/Unity/InputInfo/CMakeLists.txtnew file+39
@@ -0,0 +1,39 @@
1+# This is a temporary snapshot of the WIP QInputInfo API as we
2+# require this in unity now but upstream isn't finished yet.
3+# Eventually this should be dropped in favor of the upstream
4+# QInputInfo API.
5+
6+project(InputInfo)
7+
8+find_package(Qt5Core REQUIRED)
9+find_package(Qt5Quick REQUIRED)
10+
11+pkg_check_modules(LIBUDEV REQUIRED libudev)
12+pkg_check_modules(LIBEVDEV REQUIRED libevdev)
13+
14+include_directories(
15+ ${CMAKE_CURRENT_SOURCE_DIR}
16+ ${CMAKE_CURRENT_BINARY_DIR}
17+ ${LIBUDEV_INCLUDE_DIRS}
18+ ${LIBEVDEV_INCLUDE_DIRS}
19+)
20+
21+set(InputInfo_SOURCES
22+ plugin.cpp
23+ qinputinfo.cpp
24+ qdeclarativeinputdeviceinfo.cpp
25+ linux/qinputdeviceinfo_linux.cpp
26+)
27+
28+add_library(InputInfo SHARED
29+ ${InputInfo_SOURCES}
30+)
31+
32+target_link_libraries(InputInfo
33+ ${LIBUDEV_LDFLAGS}
34+ ${LIBEVDEV_LDFLAGS}
35+)
36+
37+qt5_use_modules(InputInfo Core Qml Quick)
38+
39+add_unity8_plugin(Unity.InputInfo 0.1 Unity/InputInfo TARGETS InputInfo)
plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cppnew file+249
@@ -0,0 +1,249 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#include "qinputdeviceinfo_linux_p.h"
43+
44+#include <libudev.h>
45+#include <libevdev/libevdev.h>
46+#include <fcntl.h>
47+#include <QDebug>
48+#include <QSocketNotifier>
49+#include <QTimer>
50+
51+QInputDeviceInfoPrivate::QInputDeviceInfoPrivate(QObject *parent) :
52+ QObject(parent)
53+ , udev(0)
54+{
55+ QTimer::singleShot(250,this,SLOT(init()));
56+}
57+
58+void QInputDeviceInfoPrivate::init()
59+{
60+ if (!udev)
61+ udev = udev_new();
62+
63+ struct udev_list_entry *devices, *dev_list_entry;
64+ struct udev_device *dev;
65+
66+ QString subsystem = QStringLiteral("input");
67+ struct udev_enumerate *enumerate = 0;
68+
69+ if (udev) {
70+
71+ udevMonitor = udev_monitor_new_from_netlink(udev, "udev");
72+ udev_monitor_filter_add_match_subsystem_devtype(udevMonitor, subsystem.toLatin1(), NULL);
73+ enumerate = udev_enumerate_new(udev);
74+ udev_enumerate_add_match_subsystem(enumerate, subsystem.toLatin1());
75+
76+
77+ udev_monitor_enable_receiving(udevMonitor);
78+ notifierFd = udev_monitor_get_fd(udevMonitor);
79+
80+ notifier = new QSocketNotifier(notifierFd, QSocketNotifier::Read, this);
81+ connect(notifier, SIGNAL(activated(int)), this, SLOT(onUDevChanges()));
82+
83+
84+ udev_enumerate_scan_devices(enumerate);
85+ devices = udev_enumerate_get_list_entry(enumerate);
86+
87+ udev_list_entry_foreach(dev_list_entry, devices) {
88+ const char *path;
89+ path = udev_list_entry_get_name(dev_list_entry);
90+
91+ dev = udev_device_new_from_syspath(udev, path);
92+
93+ QString eventPath = QString::fromLatin1(udev_device_get_sysname(dev));
94+
95+ if (qstrcmp(udev_device_get_subsystem(dev), "input") == 0 ) {
96+
97+ if (eventPath.contains(QStringLiteral("event"))) {
98+ eventPath.prepend(QStringLiteral("/dev/input/"));
99+
100+ QInputDevice *iDevice = addDevice(eventPath);
101+ if (!iDevice)
102+ continue;
103+
104+ qDebug() << "*** ADDING DEVICE" << eventPath;
105+
106+ iDevice->setTypes(getInputTypes(dev));
107+
108+ if (iDevice->switches().count() > 0 && iDevice->buttons().count() == 0)
109+ iDevice->setTypes(iDevice->types() | QInputDeviceInfo::Switch);
110+
111+ if (iDevice->buttons().count() > 0 && iDevice->types() == QInputDeviceInfo::Unknown)
112+ iDevice->setTypes(iDevice->types() | QInputDeviceInfo::Button);
113+
114+ deviceList.append(iDevice);
115+ deviceMap.insert(eventPath,iDevice);
116+ Q_EMIT newDevice(eventPath);
117+
118+ }
119+ }
120+ }
121+ udev_enumerate_unref(enumerate);
122+ }
123+ Q_EMIT ready();
124+}
125+
126+QInputDeviceInfo::InputTypes QInputDeviceInfoPrivate::getInputTypes( struct udev_device *dev)
127+{
128+ qDebug() << "******* have input type Keyboard" << udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
129+ qDebug() << "******* have input type Mouse" << udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
130+ qDebug() << "******* have input type Touchpad" << udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
131+ qDebug() << "******* have input type Touchscreen" << udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
132+ qDebug() << "******* have input type Tablet" << udev_device_get_property_value(dev, "ID_INPUT_TABLET");
133+ qDebug() << "******* have input type joystick" << udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
134+ QInputDeviceInfo::InputTypes types = QInputDeviceInfo::Unknown;
135+ if (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )
136+ types |= QInputDeviceInfo::Keyboard;
137+
138+ if (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_MOUSE"), "1") == 0)
139+ types |= QInputDeviceInfo::Mouse;
140+
141+ if (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"), "1") == 0)
142+ types |= QInputDeviceInfo::TouchPad;
143+
144+ if (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"), "1") == 0
145+ || qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TABLET"), "1") == 0)
146+ types |= QInputDeviceInfo::TouchScreen;
147+
148+ return types;
149+}
150+
151+QInputDevice *QInputDeviceInfoPrivate::addDevice(const QString &path)
152+{
153+ QInputDevice *inputDevice = new QInputDevice(this);
154+
155+ struct libevdev *dev = NULL;
156+ int fd;
157+ int rc = 1;
158+ fd = open(path.toLatin1(), O_RDONLY|O_NONBLOCK);
159+
160+ if (fd == -1) {
161+ qDebug() << "Failed to open";
162+ return inputDevice;
163+ }
164+ rc = libevdev_new_from_fd(fd, &dev);
165+ if (rc < 0) {
166+ qDebug() << "Failed to init libevdev ("<< strerror(-rc) << ")";
167+ return inputDevice;
168+ }
169+
170+ inputDevice->setName(QString::fromLatin1(libevdev_get_name(dev)));
171+ inputDevice->setDevicePath(path);
172+ for (int i = 0; i < EV_MAX; i++) {
173+ if (i == EV_KEY || i == EV_SW || i == EV_REL
174+ || i == EV_REL || i == EV_ABS) {
175+ for (int j = 0; j < libevdev_event_type_get_max(i); j++) {
176+ if (libevdev_has_event_code(dev, i, j)) {
177+ switch (i) {
178+ case EV_KEY:
179+ inputDevice->addButton(j);
180+ break;
181+ case EV_SW:
182+ inputDevice->addSwitch(j);
183+ break;
184+ case EV_REL:
185+ inputDevice->addRelativeAxis(j);
186+ break;
187+ case EV_ABS:
188+ inputDevice->addAbsoluteAxis(j);
189+ break;
190+ };
191+ }
192+ }
193+ }
194+ }
195+ return inputDevice;
196+}
197+
198+void QInputDeviceInfoPrivate::removeDevice(const QString &path)
199+{
200+ for (int i = 0; i < deviceList.size(); ++i) {
201+ if (deviceList.at(i)->devicePath() == path) {
202+ delete deviceList.takeAt(i);
203+ deviceMap.remove(path);
204+ Q_EMIT deviceRemoved(path);
205+ }
206+ }
207+}
208+
209+void QInputDeviceInfoPrivate::onUDevChanges()
210+{
211+ struct udev_device *dev = udev_monitor_receive_device(udevMonitor);
212+ if (dev) {
213+ if (qstrcmp(udev_device_get_subsystem(dev), "input") == 0 ) {
214+ QString eventPath = QString::fromLatin1(udev_device_get_sysname(dev));
215+
216+ if (eventPath.contains(QStringLiteral("input")))
217+ return;
218+
219+ QString action = QString::fromStdString(udev_device_get_action(dev));
220+
221+ if (!eventPath.contains(QStringLiteral("/dev/input/")))
222+ eventPath.prepend(QStringLiteral("/dev/input/"));
223+
224+ if (action == QStringLiteral("add")) {
225+
226+ QInputDevice *iDevice = addDevice(eventPath);
227+ if (!iDevice)
228+ return;
229+
230+ iDevice->setTypes(getInputTypes(dev));
231+ udev_device_unref(dev);
232+
233+ if (iDevice->switches().count() > 0 && iDevice->buttons().count() == 0)
234+ iDevice->setTypes(iDevice->types() | QInputDeviceInfo::Switch);
235+
236+ if (iDevice->buttons().count() > 0 && iDevice->types() == QInputDeviceInfo::Unknown)
237+ iDevice->setTypes(iDevice->types() | QInputDeviceInfo::Button);
238+
239+ deviceList.append(iDevice);
240+ deviceMap.insert(eventPath,iDevice);
241+
242+ Q_EMIT newDevice(eventPath);
243+
244+ } else if (action == QStringLiteral("remove")) {
245+ removeDevice(eventPath);
246+ }
247+ }
248+ }
249+}
plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.hnew file+91
@@ -0,0 +1,91 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#ifndef QINPUTDEVICEINFO_LINUX_P_H
43+#define QINPUTDEVICEINFO_LINUX_P_H
44+
45+#include <QObject>
46+#include "qinputinfo.h"
47+#include <libudev.h>
48+
49+class QInputDevicePrivate : public QObject
50+{
51+ Q_OBJECT
52+public:
53+ explicit QInputDevicePrivate(QObject *parent = 0);
54+
55+ QString name;
56+ QString devicePath;
57+ QList <int> buttons; //keys
58+ QList <int> switches;
59+ QList <int> relativeAxis;
60+ QList <int> absoluteAxis;
61+ QInputDeviceInfo::InputTypes types;
62+};
63+
64+class QInputDeviceInfoPrivate : public QObject
65+{
66+ Q_OBJECT
67+public:
68+ explicit QInputDeviceInfoPrivate(QObject *parent = 0);
69+ QVector <QInputDevice *> deviceList;
70+ QMap <QString, QInputDevice *> deviceMap;
71+
72+Q_SIGNALS:
73+ void newDevice(const QString &);
74+ void deviceRemoved(const QString &);
75+ void ready();
76+
77+private:
78+ struct udev *udev;
79+ QInputDevice *addDevice(const QString &path);
80+ void removeDevice(const QString &path);
81+ QSocketNotifier *notifier;
82+ int notifierFd;
83+ struct udev_monitor *udevMonitor;
84+ QInputDeviceInfo::InputTypes getInputTypes( struct udev_device *);
85+
86+private Q_SLOTS:
87+ void onUDevChanges();
88+ void init();
89+};
90+
91+#endif // QINPUTDEVICEINFO_LINUX_P_H
plugins/Unity/InputInfo/plugin.cppnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+// Qt
18+#include <QtQml/qqml.h>
19+
20+// self
21+#include "plugin.h"
22+
23+// local
24+#include "qdeclarativeinputdeviceinfo_p.h"
25+
26+void InputInfoPlugin::registerTypes(const char *uri)
27+{
28+ int major = 0;
29+ int minor = 1;
30+ qmlRegisterType<QDeclarativeInputDeviceInfo>(uri, major, minor, "InputDeviceInfo");
31+ qmlRegisterType<QInputDevice>(uri, major, minor, "InputInfo");
32+}
plugins/Unity/InputInfo/plugin.hnew file+30
@@ -0,0 +1,30 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+#ifndef INPUTINFO_PLUGIN_H
18+#define INPUTINFO_PLUGIN_H
19+
20+#include <QtQml/QQmlExtensionPlugin>
21+
22+class InputInfoPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+public:
27+ void registerTypes(const char *uri);
28+};
29+
30+#endif // INPUTINFO_PLUGIN_H
plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cppnew file+143
@@ -0,0 +1,143 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2015 Jolla.
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+#include "qdeclarativeinputdeviceinfo_p.h"
42+
43+QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
44+ QAbstractListModel(parent),
45+ deviceInfo(new QInputDeviceInfo)
46+{
47+ connect(deviceInfo,SIGNAL(ready()),this,SLOT(updateDeviceList()));
48+ connect(deviceInfo, &QInputDeviceInfo::deviceAdded,this,&QDeclarativeInputDeviceInfo::addedDevice);
49+ connect(deviceInfo, &QInputDeviceInfo::deviceRemoved,this,&QDeclarativeInputDeviceInfo::removedDevice);
50+}
51+
52+QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
53+{
54+ delete deviceInfo;
55+}
56+
57+QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
58+{
59+ switch (role) {
60+ case ServiceRole:
61+ return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
62+ }
63+
64+ return QVariant();
65+}
66+
67+int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
68+{
69+ Q_UNUSED(parent);
70+
71+ return inputDevices.count();
72+}
73+
74+int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
75+{
76+ int idx(-1);
77+ Q_FOREACH (QInputDevice *device, inputDevices) {
78+ idx++;
79+ if (device->devicePath() == devicePath) return idx;
80+ }
81+
82+ return -1;
83+}
84+
85+QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
86+{
87+ if (index < 0 || index > inputDevices.count())
88+ return 0;
89+ return inputDevices.value(index);
90+}
91+
92+void QDeclarativeInputDeviceInfo::updateDeviceList()
93+{
94+ QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
95+
96+ int numNew = newDevices.count();
97+
98+ for (int i = 0; i < numNew; i++) {
99+ int j = inputDevices.indexOf(newDevices.value(i));
100+ if (j == -1) {
101+ // not found -> remove from list
102+ beginInsertRows(QModelIndex(), i, i);
103+ inputDevices.insert(i, newDevices.value(i));
104+ endInsertRows();
105+ } else if (i != j) {
106+ // changed its position -> move it
107+ QInputDevice* device = inputDevices.value(j);
108+ beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
109+ inputDevices.remove(j);
110+ inputDevices.insert(i, device);
111+ endMoveRows();
112+ } else {
113+ QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
114+ Q_EMIT dataChanged(changedIndex, changedIndex);
115+ }
116+ }
117+
118+ int numOld = inputDevices.count();
119+ if (numOld > numNew) {
120+ beginRemoveRows(QModelIndex(), numNew, numOld - 1);
121+ inputDevices.remove(numNew, numOld - numNew);
122+ endRemoveRows();
123+ }
124+}
125+
126+void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
127+{
128+ updateDeviceList();
129+ Q_EMIT newDevice(devicePath);
130+}
131+
132+void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
133+{
134+ updateDeviceList();
135+ Q_EMIT deviceRemoved(devicePath);
136+}
137+
138+QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
139+{
140+ QHash<int, QByteArray> roles;
141+ roles.insert(ServiceRole, "service");
142+ return roles;
143+}
plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.hnew file+86
@@ -0,0 +1,86 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2015 Jolla.
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#ifndef QDECLARATIVEINPUTDEVICEINFO_H
43+#define QDECLARATIVEINPUTDEVICEINFO_H
44+
45+#include <QObject>
46+#include <QAbstractListModel>
47+#include "qinputinfo.h"
48+
49+class QDeclarativeInputDeviceInfo : public QAbstractListModel
50+{
51+ Q_OBJECT
52+ Q_DISABLE_COPY(QDeclarativeInputDeviceInfo)
53+
54+public:
55+ enum ItemRoles {
56+ ServiceRole = Qt::UserRole + 1
57+ };
58+
59+ explicit QDeclarativeInputDeviceInfo(QObject *parent = 0);
60+ virtual ~QDeclarativeInputDeviceInfo();
61+
62+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
63+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
64+
65+ QHash<int, QByteArray> roleNames() const;
66+
67+ Q_INVOKABLE int indexOf(const QString &devicePath) const;
68+
69+ Q_INVOKABLE QInputDevice *get(int index) const;
70+
71+Q_SIGNALS:
72+ void newDevice(const QString &devicePath);
73+ void deviceRemoved(const QString &devicePath);
74+
75+public Q_SLOTS:
76+ void updateDeviceList();
77+private:
78+ QInputDeviceInfo *deviceInfo;
79+ QVector<QInputDevice *> inputDevices;
80+private Q_SLOTS:
81+ void addedDevice(const QString &);
82+ void removedDevice(const QString &path);
83+
84+};
85+
86+#endif // QDECLARATIVEINPUTDEVICEINFO_H
plugins/Unity/InputInfo/qinputinfo.cppnew file+159
@@ -0,0 +1,159 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#include "qinputinfo.h"
43+
44+#if defined(Q_OS_LINUX)
45+#include "linux/qinputdeviceinfo_linux_p.h"
46+#endif
47+
48+QT_BEGIN_NAMESPACE
49+
50+
51+QInputDevicePrivate::QInputDevicePrivate(QObject *parent) :
52+ QObject(parent),
53+ types(QInputDeviceInfo::Unknown)
54+{
55+}
56+
57+QInputDevice::QInputDevice(QObject *parent) :
58+ QObject(parent),
59+ d_ptr(new QInputDevicePrivate(this))
60+{
61+}
62+
63+QString QInputDevice::name() const
64+{
65+ return d_ptr->name;
66+}
67+
68+void QInputDevice::setName(const QString &name)
69+{
70+ d_ptr->name = name;
71+}
72+
73+QString QInputDevice::devicePath() const
74+{
75+ return d_ptr->devicePath;
76+}
77+
78+void QInputDevice::setDevicePath(const QString &path)
79+{
80+ d_ptr->devicePath = path;
81+}
82+
83+QList <int> QInputDevice::buttons() const
84+{
85+ return d_ptr->buttons;
86+}
87+
88+void QInputDevice::addButton(int buttonCode)
89+{
90+ d_ptr->buttons.append(buttonCode);
91+}
92+
93+QList <int> QInputDevice::switches() const
94+{
95+ return d_ptr->switches;
96+}
97+
98+void QInputDevice::addSwitch(int switchCode)
99+{
100+ d_ptr->switches.append(switchCode);
101+}
102+
103+QList <int> QInputDevice::relativeAxis() const
104+{
105+ return d_ptr->relativeAxis;
106+}
107+
108+void QInputDevice::addRelativeAxis(int axisCode)
109+{
110+ d_ptr->relativeAxis.append(axisCode);
111+}
112+
113+QList <int> QInputDevice::absoluteAxis() const
114+{
115+ return d_ptr->absoluteAxis;
116+}
117+
118+void QInputDevice::addAbsoluteAxis(int axisCode)
119+{
120+ d_ptr->absoluteAxis.append(axisCode);
121+}
122+
123+QInputDeviceInfo::InputTypes QInputDevice::types()
124+{
125+ return d_ptr->types;
126+}
127+
128+void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
129+{
130+ d_ptr->types = types;
131+}
132+
133+
134+QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
135+ QObject(parent),
136+ d_ptr(new QInputDeviceInfoPrivate(this))
137+{
138+ connect(d_ptr, &QInputDeviceInfoPrivate::newDevice,this,&QInputDeviceInfo::addedDevice);
139+ connect(d_ptr, &QInputDeviceInfoPrivate::deviceRemoved,this,&QInputDeviceInfo::deviceRemoved);
140+
141+ connect(d_ptr,SIGNAL(ready()),this,SIGNAL(ready()));
142+}
143+
144+QVector <QInputDevice *> QInputDeviceInfo::deviceList()
145+{
146+ return d_ptr->deviceList;
147+}
148+
149+QMap <QString, QInputDevice *> QInputDeviceInfo::deviceMap()
150+{
151+ return d_ptr->deviceMap;
152+}
153+
154+void QInputDeviceInfo::addedDevice(const QString & devicePath)
155+{
156+ Q_EMIT deviceAdded(devicePath);
157+}
158+
159+QT_END_NAMESPACE
plugins/Unity/InputInfo/qinputinfo.hnew file+143
@@ -0,0 +1,143 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#ifndef QINPUTINFO_H
43+#define QINPUTINFO_H
44+
45+#include <QObject>
46+#include <QVector>
47+#include <QMap>
48+#include <QSocketNotifier>
49+#include <QDebug>
50+
51+class QInputDeviceInfoPrivate;
52+class QInputDevicePrivate;
53+class QInputDevice;
54+
55+class QInputDeviceInfoPrivate;
56+class QInputDeviceInfo : public QObject
57+{
58+ Q_OBJECT
59+ Q_PROPERTY(int deviceCount READ deviceCount)
60+public:
61+
62+ enum InputType {
63+ Unknown = 0,
64+ Button = 1,
65+ Mouse = 2,
66+ TouchPad = 4,
67+ TouchScreen = 8,
68+ Keyboard = 16,
69+ Switch = 32
70+ };
71+ Q_ENUMS(InputType)
72+ Q_FLAGS(InputTypes)
73+ Q_DECLARE_FLAGS(InputTypes, InputType)
74+
75+ explicit QInputDeviceInfo(QObject *parent = 0);
76+
77+ Q_INVOKABLE QVector <QInputDevice *> deviceList();
78+
79+ Q_INVOKABLE QMap <QString, QInputDevice *> deviceMap();
80+ int deviceCount() { return deviceList().count(); }
81+Q_SIGNALS:
82+
83+ void deviceAdded(const QString & devicePath);
84+ void deviceRemoved(const QString & devicePath);
85+
86+ void ready();
87+
88+public Q_SLOTS:
89+ void addedDevice(const QString & devicePath);
90+
91+private:
92+ Q_DISABLE_COPY(QInputDeviceInfo)
93+#if !defined(QT_SIMULATOR)
94+ QInputDeviceInfoPrivate *const d_ptr;
95+ Q_DECLARE_PRIVATE(QInputDeviceInfo)
96+#endif
97+};
98+
99+class QInputDevice : public QObject
100+{
101+ friend class QInputDeviceInfoPrivate;
102+ Q_OBJECT
103+ Q_ENUMS(InputType)
104+ Q_FLAGS(InputTypes)
105+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
106+ Q_PROPERTY(QString devicePath READ devicePath NOTIFY devicePathChanged)
107+ Q_PROPERTY(QList <int> buttons READ buttons NOTIFY buttonsChanged)
108+ Q_PROPERTY(QList <int> switches READ switches NOTIFY switchesChanged)
109+ Q_PROPERTY(QList <int> relativeAxis READ relativeAxis NOTIFY relativeAxisChanged)
110+ Q_PROPERTY(QList <int> absoluteAxis READ absoluteAxis NOTIFY absoluteAxisChanged)
111+ Q_PROPERTY(QInputDeviceInfo::InputTypes types READ types NOTIFY typesChanged)
112+
113+public:
114+ explicit QInputDevice(QObject *parent = 0);
115+
116+ QString name() const;
117+ QString devicePath() const;
118+ QList <int> buttons() const; //keys event code
119+ QList <int> switches() const;
120+ QList <int> relativeAxis() const;
121+ QList <int> absoluteAxis() const;
122+
123+ QInputDeviceInfo::InputTypes types();
124+Q_SIGNALS:
125+ void nameChanged();
126+ void devicePathChanged();
127+ void buttonsChanged();
128+ void switchesChanged();
129+ void relativeAxisChanged();
130+ void absoluteAxisChanged();
131+ void typesChanged();
132+private:
133+ QInputDevicePrivate *d_ptr;
134+ void setName(const QString &);
135+ void setDevicePath(const QString &);
136+ void addButton(int);
137+ void addSwitch(int);
138+ void addRelativeAxis(int);
139+ void addAbsoluteAxis(int);
140+ void setTypes(QInputDeviceInfo::InputTypes);
141+};
142+
143+#endif // QINPUTINFO_H
plugins/Unity/InputInfo/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.InputInfo
2+plugin InputInfo
3+typeinfo InputInfo.qmltypes