Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtGui 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 The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | - | ||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
24 | ** | - | ||||||
25 | ** GNU General Public License Usage | - | ||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
35 | ** | - | ||||||
36 | ** $QT_END_LICENSE$ | - | ||||||
37 | ** | - | ||||||
38 | ****************************************************************************/ | - | ||||||
39 | - | |||||||
40 | #include "qevdevmousemanager_p.h" | - | ||||||
41 | - | |||||||
42 | #include <QStringList> | - | ||||||
43 | #include <QGuiApplication> | - | ||||||
44 | #include <QScreen> | - | ||||||
45 | #include <QLoggingCategory> | - | ||||||
46 | #include <qpa/qwindowsysteminterface.h> | - | ||||||
47 | #include <QtPlatformSupport/private/qdevicediscovery_p.h> | - | ||||||
48 | #include <private/qguiapplication_p.h> | - | ||||||
49 | #include <private/qinputdevicemanager_p_p.h> | - | ||||||
50 | #include <private/qhighdpiscaling_p.h> | - | ||||||
51 | - | |||||||
52 | QT_BEGIN_NAMESPACE | - | ||||||
53 | - | |||||||
54 | Q_DECLARE_LOGGING_CATEGORY(qLcEvdevMouse) | - | ||||||
55 | - | |||||||
56 | QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent) | - | ||||||
57 | : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0) | - | ||||||
58 | { | - | ||||||
59 | Q_UNUSED(key); | - | ||||||
60 | - | |||||||
61 | QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS")); | - | ||||||
62 | - | |||||||
63 | if (spec.isEmpty())
| 0 | ||||||
64 | spec = specification; never executed: spec = specification; | 0 | ||||||
65 | - | |||||||
66 | QStringList args = spec.split(QLatin1Char(':')); | - | ||||||
67 | QStringList devices; | - | ||||||
68 | - | |||||||
69 | foreach (const QString &arg, args) { | - | ||||||
70 | if (arg.startsWith(QLatin1String("/dev/"))) {
| 0 | ||||||
71 | // if device is specified try to use it | - | ||||||
72 | devices.append(arg); | - | ||||||
73 | args.removeAll(arg); | - | ||||||
74 | } else if (arg.startsWith(QLatin1String("xoffset="))) { never executed: end of block
| 0 | ||||||
75 | m_xoffset = arg.mid(8).toInt(); | - | ||||||
76 | } else if (arg.startsWith(QLatin1String("yoffset="))) { never executed: end of block
| 0 | ||||||
77 | m_yoffset = arg.mid(8).toInt(); | - | ||||||
78 | } never executed: end of block | 0 | ||||||
79 | } never executed: end of block | 0 | ||||||
80 | - | |||||||
81 | // build new specification without /dev/ elements | - | ||||||
82 | m_spec = args.join(QLatin1Char(':')); | - | ||||||
83 | - | |||||||
84 | // add all mice for devices specified in the argument list | - | ||||||
85 | foreach (const QString &device, devices) | - | ||||||
86 | addMouse(device); never executed: addMouse(device); | 0 | ||||||
87 | - | |||||||
88 | if (devices.isEmpty()) {
| 0 | ||||||
89 | qCDebug(qLcEvdevMouse) << "evdevmouse: Using device discovery"; never executed: QMessageLogger(__FILE__, 89, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "evdevmouse: Using device discovery";
| 0 | ||||||
90 | m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); | - | ||||||
91 | if (m_deviceDiscovery) {
| 0 | ||||||
92 | // scan and add already connected keyboards | - | ||||||
93 | QStringList devices = m_deviceDiscovery->scanConnectedDevices(); | - | ||||||
94 | foreach (const QString &device, devices) { | - | ||||||
95 | addMouse(device); | - | ||||||
96 | } never executed: end of block | 0 | ||||||
97 | - | |||||||
98 | connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addMouse(QString))); | - | ||||||
99 | connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeMouse(QString))); | - | ||||||
100 | } never executed: end of block | 0 | ||||||
101 | } never executed: end of block | 0 | ||||||
102 | - | |||||||
103 | connect(QGuiApplicationPrivate::inputDeviceManager(), SIGNAL(cursorPositionChangeRequested(QPoint)), | - | ||||||
104 | this, SLOT(handleCursorPositionChange(QPoint))); | - | ||||||
105 | } never executed: end of block | 0 | ||||||
106 | - | |||||||
107 | QEvdevMouseManager::~QEvdevMouseManager() | - | ||||||
108 | { | - | ||||||
109 | qDeleteAll(m_mice); | - | ||||||
110 | m_mice.clear(); | - | ||||||
111 | } never executed: end of block | 0 | ||||||
112 | - | |||||||
113 | void QEvdevMouseManager::clampPosition() | - | ||||||
114 | { | - | ||||||
115 | // clamp to screen geometry | - | ||||||
116 | QScreen *primaryScreen = QGuiApplication::primaryScreen(); | - | ||||||
117 | QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen); | - | ||||||
118 | if (m_x + m_xoffset < g.left())
| 0 | ||||||
119 | m_x = g.left() - m_xoffset; never executed: m_x = g.left() - m_xoffset; | 0 | ||||||
120 | else if (m_x + m_xoffset > g.right())
| 0 | ||||||
121 | m_x = g.right() - m_xoffset; never executed: m_x = g.right() - m_xoffset; | 0 | ||||||
122 | - | |||||||
123 | if (m_y + m_yoffset < g.top())
| 0 | ||||||
124 | m_y = g.top() - m_yoffset; never executed: m_y = g.top() - m_yoffset; | 0 | ||||||
125 | else if (m_y + m_yoffset > g.bottom())
| 0 | ||||||
126 | m_y = g.bottom() - m_yoffset; never executed: m_y = g.bottom() - m_yoffset; | 0 | ||||||
127 | } never executed: end of block | 0 | ||||||
128 | - | |||||||
129 | void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons) | - | ||||||
130 | { | - | ||||||
131 | // update current absolute coordinates | - | ||||||
132 | if (!abs) {
| 0 | ||||||
133 | m_x += x; | - | ||||||
134 | m_y += y; | - | ||||||
135 | } else { never executed: end of block | 0 | ||||||
136 | m_x = x; | - | ||||||
137 | m_y = y; | - | ||||||
138 | } never executed: end of block | 0 | ||||||
139 | - | |||||||
140 | clampPosition(); | - | ||||||
141 | - | |||||||
142 | QPoint pos(m_x + m_xoffset, m_y + m_yoffset); | - | ||||||
143 | // Cannot track the keyboard modifiers ourselves here. Instead, report the | - | ||||||
144 | // modifiers from the last key event that has been seen by QGuiApplication. | - | ||||||
145 | QWindowSystemInterface::handleMouseEvent(0, pos, pos, buttons, QGuiApplication::keyboardModifiers()); | - | ||||||
146 | } never executed: end of block | 0 | ||||||
147 | - | |||||||
148 | void QEvdevMouseManager::handleWheelEvent(int delta, Qt::Orientation orientation) | - | ||||||
149 | { | - | ||||||
150 | QPoint pos(m_x + m_xoffset, m_y + m_yoffset); | - | ||||||
151 | QWindowSystemInterface::handleWheelEvent(0, pos, pos, delta, orientation, QGuiApplication::keyboardModifiers()); | - | ||||||
152 | } never executed: end of block | 0 | ||||||
153 | - | |||||||
154 | void QEvdevMouseManager::addMouse(const QString &deviceNode) | - | ||||||
155 | { | - | ||||||
156 | qCDebug(qLcEvdevMouse) << "Adding mouse at" << deviceNode; never executed: QMessageLogger(__FILE__, 156, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Adding mouse at" << deviceNode;
| 0 | ||||||
157 | QEvdevMouseHandler *handler; | - | ||||||
158 | handler = QEvdevMouseHandler::create(deviceNode, m_spec); | - | ||||||
159 | if (handler) {
| 0 | ||||||
160 | connect(handler, SIGNAL(handleMouseEvent(int,int,bool,Qt::MouseButtons)), this, SLOT(handleMouseEvent(int,int,bool,Qt::MouseButtons))); | - | ||||||
161 | connect(handler, SIGNAL(handleWheelEvent(int,Qt::Orientation)), this, SLOT(handleWheelEvent(int,Qt::Orientation))); | - | ||||||
162 | m_mice.insert(deviceNode, handler); | - | ||||||
163 | QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( | - | ||||||
164 | QInputDeviceManager::DeviceTypePointer, m_mice.count()); | - | ||||||
165 | } else { never executed: end of block | 0 | ||||||
166 | qWarning("evdevmouse: Failed to open mouse device %s", qPrintable(deviceNode)); | - | ||||||
167 | } never executed: end of block | 0 | ||||||
168 | } | - | ||||||
169 | - | |||||||
170 | void QEvdevMouseManager::removeMouse(const QString &deviceNode) | - | ||||||
171 | { | - | ||||||
172 | if (m_mice.contains(deviceNode)) {
| 0 | ||||||
173 | qCDebug(qLcEvdevMouse) << "Removing mouse at" << deviceNode; never executed: QMessageLogger(__FILE__, 173, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Removing mouse at" << deviceNode;
| 0 | ||||||
174 | QEvdevMouseHandler *handler = m_mice.value(deviceNode); | - | ||||||
175 | m_mice.remove(deviceNode); | - | ||||||
176 | QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( | - | ||||||
177 | QInputDeviceManager::DeviceTypePointer, m_mice.count()); | - | ||||||
178 | delete handler; | - | ||||||
179 | } never executed: end of block | 0 | ||||||
180 | } never executed: end of block | 0 | ||||||
181 | - | |||||||
182 | void QEvdevMouseManager::handleCursorPositionChange(const QPoint &pos) | - | ||||||
183 | { | - | ||||||
184 | m_x = pos.x(); | - | ||||||
185 | m_y = pos.y(); | - | ||||||
186 | clampPosition(); | - | ||||||
187 | } never executed: end of block | 0 | ||||||
188 | - | |||||||
189 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |