qevdevmousemanager.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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-
52QT_BEGIN_NAMESPACE-
53-
54Q_DECLARE_LOGGING_CATEGORY(qLcEvdevMouse)-
55-
56QEvdevMouseManager::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())
spec.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
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/"))) {
arg.startsWith...ring("/dev/"))Description
TRUEnever evaluated
FALSEnever evaluated
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
arg.startsWith...g("xoffset="))Description
TRUEnever evaluated
FALSEnever evaluated
0
75 m_xoffset = arg.mid(8).toInt();-
76 } else if (arg.startsWith(QLatin1String("yoffset="))) {
never executed: end of block
arg.startsWith...g("yoffset="))Description
TRUEnever evaluated
FALSEnever evaluated
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()) {
devices.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
89 qCDebug(qLcEvdevMouse) << "evdevmouse: Using device discovery";
never executed: QMessageLogger(__FILE__, 89, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "evdevmouse: Using device discovery";
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
90 m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this);-
91 if (m_deviceDiscovery) {
m_deviceDiscoveryDescription
TRUEnever evaluated
FALSEnever evaluated
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-
107QEvdevMouseManager::~QEvdevMouseManager()-
108{-
109 qDeleteAll(m_mice);-
110 m_mice.clear();-
111}
never executed: end of block
0
112-
113void 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())
m_x + m_xoffset < g.left()Description
TRUEnever evaluated
FALSEnever evaluated
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())
m_x + m_xoffset > g.right()Description
TRUEnever evaluated
FALSEnever evaluated
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())
m_y + m_yoffset < g.top()Description
TRUEnever evaluated
FALSEnever evaluated
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())
m_y + m_yoffset > g.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
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-
129void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons)-
130{-
131 // update current absolute coordinates-
132 if (!abs) {
!absDescription
TRUEnever evaluated
FALSEnever evaluated
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-
148void 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-
154void 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;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
157 QEvdevMouseHandler *handler;-
158 handler = QEvdevMouseHandler::create(deviceNode, m_spec);-
159 if (handler) {
handlerDescription
TRUEnever evaluated
FALSEnever evaluated
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-
170void QEvdevMouseManager::removeMouse(const QString &deviceNode)-
171{-
172 if (m_mice.contains(deviceNode)) {
m_mice.contains(deviceNode)Description
TRUEnever evaluated
FALSEnever evaluated
0
173 qCDebug(qLcEvdevMouse) << "Removing mouse at" << deviceNode;
never executed: QMessageLogger(__FILE__, 173, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Removing mouse at" << deviceNode;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
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-
182void 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-
189QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9