Merge lp:~mzanetti/unity8/inputinfo-plugin into lp:unity8

Proposed by Michael Zanetti
Status: Superseded
Proposed branch: lp:~mzanetti/unity8/inputinfo-plugin
Merge into: lp:unity8
Prerequisite: lp:~unity-team/unity8/shellRotation
Diff against target: 1072 lines (+984/-0)
13 files modified
debian/changelog (+6/-0)
debian/control (+2/-0)
plugins/Unity/CMakeLists.txt (+1/-0)
plugins/Unity/InputInfo/CMakeLists.txt (+39/-0)
plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cpp (+249/-0)
plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.h (+91/-0)
plugins/Unity/InputInfo/plugin.cpp (+32/-0)
plugins/Unity/InputInfo/plugin.h (+30/-0)
plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cpp (+143/-0)
plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.h (+86/-0)
plugins/Unity/InputInfo/qinputinfo.cpp (+159/-0)
plugins/Unity/InputInfo/qinputinfo.h (+143/-0)
plugins/Unity/InputInfo/qmldir (+3/-0)
To merge this branch: bzr merge lp:~mzanetti/unity8/inputinfo-plugin
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Albert Astals Cid (community) Needs Fixing
Review via email: mp+259445@code.launchpad.net

This proposal supersedes a proposal from 2015-05-05.

This proposal has been superseded by a proposal from 2015-06-23.

Commit message

Added a snapshot of the WIP Qt InputInfo API

Description of the change

WIP: Just trying to get it through Jenkins once.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1748
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mzanetti/unity8/inputinfo-plugin/+merge/259445/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity8-ci/5736/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-wily-touch/15/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity8-wily-amd64-ci/14/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity8-wily-i386-ci/14/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-wily-armhf/15/console

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/5736/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Text conflict in qml/Stages/PhoneStage.qml
Text conflict in qml/Stages/TabletStage.qml
2 conflicts encountered.

lp:~mzanetti/unity8/inputinfo-plugin updated
1749. By Michael Zanetti

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1749
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mzanetti/unity8/inputinfo-plugin/+merge/259445/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity8-ci/5814/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-wily-touch/106/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity8-wily-amd64-ci/92/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity8-wily-i386-ci/92/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-wily-armhf/106/console

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/5814/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

You have bad tags

review: Needs Fixing
lp:~mzanetti/unity8/inputinfo-plugin updated
1750. By Michael Zanetti

drop debug print

1751. By Michael Zanetti

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2015-06-16 15:12:59 +0000
+++ debian/changelog 2015-06-22 12:17:35 +0000
@@ -66,6 +66,12 @@
6666
67 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 12 Jun 2015 16:07:47 +000067 -- CI Train Bot <ci-train-bot@canonical.com> Fri, 12 Jun 2015 16:07:47 +0000
6868
69unity8 (8.10-0ubuntu1) UNRELEASED; urgency=medium
70
71 * Implement full-shell rotation (LP: #1210199)
72
73 -- Michał Sawicz <michal.sawicz@canonical.com> Wed, 15 Apr 2015 14:47:17 +0200
74
69unity8 (8.02+15.10.20150603.1-0ubuntu1) wily; urgency=medium75unity8 (8.02+15.10.20150603.1-0ubuntu1) wily; urgency=medium
7076
71 [ CI Train Bot ]77 [ CI Train Bot ]
7278
=== modified file 'debian/control'
--- debian/control 2015-06-16 15:12:46 +0000
+++ debian/control 2015-06-22 12:17:35 +0000
@@ -16,6 +16,7 @@
16 graphviz,16 graphviz,
17 gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),17 gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),
18 libconnectivity-qt1-dev,18 libconnectivity-qt1-dev,
19 libevdev-dev,
19 libgl1-mesa-dev[!armhf] | libgl-dev[!armhf],20 libgl1-mesa-dev[!armhf] | libgl-dev[!armhf],
20 libgl1-mesa-dri,21 libgl1-mesa-dri,
21 libgles2-mesa-dev[armhf],22 libgles2-mesa-dev[armhf],
@@ -28,6 +29,7 @@
28 libqmenumodel-dev (>= 0.2.9),29 libqmenumodel-dev (>= 0.2.9),
29 libqt5xmlpatterns5-dev,30 libqt5xmlpatterns5-dev,
30 libsystemsettings-dev,31 libsystemsettings-dev,
32 libudev-dev,
31 libunity-api-dev (>= 7.97),33 libunity-api-dev (>= 7.97),
32 libusermetricsoutput1-dev,34 libusermetricsoutput1-dev,
33 libxcb1-dev,35 libxcb1-dev,
3436
=== modified file 'plugins/Unity/CMakeLists.txt'
--- plugins/Unity/CMakeLists.txt 2014-08-25 10:05:13 +0000
+++ plugins/Unity/CMakeLists.txt 2015-06-22 12:17:35 +0000
@@ -3,3 +3,4 @@
3add_subdirectory(Launcher)3add_subdirectory(Launcher)
4add_subdirectory(Session)4add_subdirectory(Session)
5add_subdirectory(DashCommunicator)5add_subdirectory(DashCommunicator)
6add_subdirectory(InputInfo)
67
=== added directory 'plugins/Unity/InputInfo'
=== added file 'plugins/Unity/InputInfo/CMakeLists.txt'
--- plugins/Unity/InputInfo/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/CMakeLists.txt 2015-06-22 12:17:35 +0000
@@ -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
6project(InputInfo)
7
8find_package(Qt5Core REQUIRED)
9find_package(Qt5Quick REQUIRED)
10
11pkg_check_modules(LIBUDEV REQUIRED libudev)
12pkg_check_modules(LIBEVDEV REQUIRED libevdev)
13
14include_directories(
15 ${CMAKE_CURRENT_SOURCE_DIR}
16 ${CMAKE_CURRENT_BINARY_DIR}
17 ${LIBUDEV_INCLUDE_DIRS}
18 ${LIBEVDEV_INCLUDE_DIRS}
19)
20
21set(InputInfo_SOURCES
22 plugin.cpp
23 qinputinfo.cpp
24 qdeclarativeinputdeviceinfo.cpp
25 linux/qinputdeviceinfo_linux.cpp
26)
27
28add_library(InputInfo SHARED
29 ${InputInfo_SOURCES}
30)
31
32target_link_libraries(InputInfo
33 ${LIBUDEV_LDFLAGS}
34 ${LIBEVDEV_LDFLAGS}
35)
36
37qt5_use_modules(InputInfo Core Qml Quick)
38
39add_unity8_plugin(Unity.InputInfo 0.1 Unity/InputInfo TARGETS InputInfo)
040
=== added directory 'plugins/Unity/InputInfo/linux'
=== added file 'plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cpp'
--- plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux.cpp 2015-06-22 12:17:35 +0000
@@ -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
51QInputDeviceInfoPrivate::QInputDeviceInfoPrivate(QObject *parent) :
52 QObject(parent)
53 , udev(0)
54{
55 QTimer::singleShot(250,this,SLOT(init()));
56}
57
58void 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
126QInputDeviceInfo::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
151QInputDevice *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
198void 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
209void 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}
0250
=== added file 'plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.h'
--- plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/linux/qinputdeviceinfo_linux_p.h 2015-06-22 12:17:35 +0000
@@ -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
49class QInputDevicePrivate : public QObject
50{
51 Q_OBJECT
52public:
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
64class QInputDeviceInfoPrivate : public QObject
65{
66 Q_OBJECT
67public:
68 explicit QInputDeviceInfoPrivate(QObject *parent = 0);
69 QVector <QInputDevice *> deviceList;
70 QMap <QString, QInputDevice *> deviceMap;
71
72Q_SIGNALS:
73 void newDevice(const QString &);
74 void deviceRemoved(const QString &);
75 void ready();
76
77private:
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
86private Q_SLOTS:
87 void onUDevChanges();
88 void init();
89};
90
91#endif // QINPUTDEVICEINFO_LINUX_P_H
092
=== added file 'plugins/Unity/InputInfo/plugin.cpp'
--- plugins/Unity/InputInfo/plugin.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/plugin.cpp 2015-06-22 12:17:35 +0000
@@ -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
26void 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}
033
=== added file 'plugins/Unity/InputInfo/plugin.h'
--- plugins/Unity/InputInfo/plugin.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/plugin.h 2015-06-22 12:17:35 +0000
@@ -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
22class InputInfoPlugin : public QQmlExtensionPlugin
23{
24 Q_OBJECT
25 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26public:
27 void registerTypes(const char *uri);
28};
29
30#endif // INPUTINFO_PLUGIN_H
031
=== added file 'plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cpp'
--- plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo.cpp 2015-06-22 12:17:35 +0000
@@ -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
43QDeclarativeInputDeviceInfo::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
52QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
53{
54 delete deviceInfo;
55}
56
57QVariant 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
67int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
68{
69 Q_UNUSED(parent);
70
71 return inputDevices.count();
72}
73
74int 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
85QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
86{
87 if (index < 0 || index > inputDevices.count())
88 return 0;
89 return inputDevices.value(index);
90}
91
92void 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
126void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
127{
128 updateDeviceList();
129 Q_EMIT newDevice(devicePath);
130}
131
132void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
133{
134 updateDeviceList();
135 Q_EMIT deviceRemoved(devicePath);
136}
137
138QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
139{
140 QHash<int, QByteArray> roles;
141 roles.insert(ServiceRole, "service");
142 return roles;
143}
0144
=== added file 'plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.h'
--- plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/qdeclarativeinputdeviceinfo_p.h 2015-06-22 12:17:35 +0000
@@ -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
49class QDeclarativeInputDeviceInfo : public QAbstractListModel
50{
51 Q_OBJECT
52 Q_DISABLE_COPY(QDeclarativeInputDeviceInfo)
53
54public:
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
71Q_SIGNALS:
72 void newDevice(const QString &devicePath);
73 void deviceRemoved(const QString &devicePath);
74
75public Q_SLOTS:
76 void updateDeviceList();
77private:
78 QInputDeviceInfo *deviceInfo;
79 QVector<QInputDevice *> inputDevices;
80private Q_SLOTS:
81 void addedDevice(const QString &);
82 void removedDevice(const QString &path);
83
84};
85
86#endif // QDECLARATIVEINPUTDEVICEINFO_H
087
=== added file 'plugins/Unity/InputInfo/qinputinfo.cpp'
--- plugins/Unity/InputInfo/qinputinfo.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/qinputinfo.cpp 2015-06-22 12:17:35 +0000
@@ -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
48QT_BEGIN_NAMESPACE
49
50
51QInputDevicePrivate::QInputDevicePrivate(QObject *parent) :
52 QObject(parent),
53 types(QInputDeviceInfo::Unknown)
54{
55}
56
57QInputDevice::QInputDevice(QObject *parent) :
58 QObject(parent),
59 d_ptr(new QInputDevicePrivate(this))
60{
61}
62
63QString QInputDevice::name() const
64{
65 return d_ptr->name;
66}
67
68void QInputDevice::setName(const QString &name)
69{
70 d_ptr->name = name;
71}
72
73QString QInputDevice::devicePath() const
74{
75 return d_ptr->devicePath;
76}
77
78void QInputDevice::setDevicePath(const QString &path)
79{
80 d_ptr->devicePath = path;
81}
82
83QList <int> QInputDevice::buttons() const
84{
85 return d_ptr->buttons;
86}
87
88void QInputDevice::addButton(int buttonCode)
89{
90 d_ptr->buttons.append(buttonCode);
91}
92
93QList <int> QInputDevice::switches() const
94{
95 return d_ptr->switches;
96}
97
98void QInputDevice::addSwitch(int switchCode)
99{
100 d_ptr->switches.append(switchCode);
101}
102
103QList <int> QInputDevice::relativeAxis() const
104{
105 return d_ptr->relativeAxis;
106}
107
108void QInputDevice::addRelativeAxis(int axisCode)
109{
110 d_ptr->relativeAxis.append(axisCode);
111}
112
113QList <int> QInputDevice::absoluteAxis() const
114{
115 return d_ptr->absoluteAxis;
116}
117
118void QInputDevice::addAbsoluteAxis(int axisCode)
119{
120 d_ptr->absoluteAxis.append(axisCode);
121}
122
123QInputDeviceInfo::InputTypes QInputDevice::types()
124{
125 return d_ptr->types;
126}
127
128void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
129{
130 d_ptr->types = types;
131}
132
133
134QInputDeviceInfo::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
144QVector <QInputDevice *> QInputDeviceInfo::deviceList()
145{
146 return d_ptr->deviceList;
147}
148
149QMap <QString, QInputDevice *> QInputDeviceInfo::deviceMap()
150{
151 return d_ptr->deviceMap;
152}
153
154void QInputDeviceInfo::addedDevice(const QString & devicePath)
155{
156 Q_EMIT deviceAdded(devicePath);
157}
158
159QT_END_NAMESPACE
0160
=== added file 'plugins/Unity/InputInfo/qinputinfo.h'
--- plugins/Unity/InputInfo/qinputinfo.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/qinputinfo.h 2015-06-22 12:17:35 +0000
@@ -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
51class QInputDeviceInfoPrivate;
52class QInputDevicePrivate;
53class QInputDevice;
54
55class QInputDeviceInfoPrivate;
56class QInputDeviceInfo : public QObject
57{
58 Q_OBJECT
59 Q_PROPERTY(int deviceCount READ deviceCount)
60public:
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(); }
81Q_SIGNALS:
82
83 void deviceAdded(const QString & devicePath);
84 void deviceRemoved(const QString & devicePath);
85
86 void ready();
87
88public Q_SLOTS:
89 void addedDevice(const QString & devicePath);
90
91private:
92 Q_DISABLE_COPY(QInputDeviceInfo)
93#if !defined(QT_SIMULATOR)
94 QInputDeviceInfoPrivate *const d_ptr;
95 Q_DECLARE_PRIVATE(QInputDeviceInfo)
96#endif
97};
98
99class 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
113public:
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();
124Q_SIGNALS:
125 void nameChanged();
126 void devicePathChanged();
127 void buttonsChanged();
128 void switchesChanged();
129 void relativeAxisChanged();
130 void absoluteAxisChanged();
131 void typesChanged();
132private:
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
0144
=== added file 'plugins/Unity/InputInfo/qmldir'
--- plugins/Unity/InputInfo/qmldir 1970-01-01 00:00:00 +0000
+++ plugins/Unity/InputInfo/qmldir 2015-06-22 12:17:35 +0000
@@ -0,0 +1,3 @@
1module Unity.InputInfo
2plugin InputInfo
3typeinfo InputInfo.qmltypes

Subscribers

People subscribed via source and target branches