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

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