Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qevdevmousemanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtInputSupport/private/qevdevutil_p.h>
7
8#include <QStringList>
9#include <QGuiApplication>
10#include <QScreen>
11#include <QLoggingCategory>
12#include <qpa/qwindowsysteminterface.h>
13#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
14#include <private/qguiapplication_p.h>
15#include <private/qinputdevicemanager_p_p.h>
16#include <private/qhighdpiscaling_p.h>
17
19
20using namespace Qt::StringLiterals;
21
22Q_DECLARE_LOGGING_CATEGORY(qLcEvdevMouse)
23
24QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent)
25 : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0)
26{
28
29 QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS"));
30
31 if (spec.isEmpty())
32 spec = specification;
33
34 auto parsed = QEvdevUtil::parseSpecification(spec);
35 m_spec = std::move(parsed.spec);
36
37 for (const auto &arg : std::as_const(parsed.args)) {
38 if (arg.startsWith("xoffset="_L1)) {
39 m_xoffset = arg.mid(8).toInt();
40 } else if (arg.startsWith("yoffset="_L1)) {
41 m_yoffset = arg.mid(8).toInt();
42 }
43 }
44
45 // add all mice for devices specified in the argument list
46 for (const QString &device : std::as_const(parsed.devices))
47 addMouse(device);
48
49 if (parsed.devices.isEmpty()) {
50 qCDebug(qLcEvdevMouse, "evdevmouse: Using device discovery");
52 // scan and add already connected keyboards
53 const QStringList devices = deviceDiscovery->scanConnectedDevices();
54 for (const QString &device : devices)
55 addMouse(device);
56
61 }
62 }
63
66 m_x = pos.x();
67 m_y = pos.y();
68 clampPosition();
69 });
70}
71
75
76void QEvdevMouseManager::clampPosition()
77{
78 // clamp to screen geometry
79 QScreen *primaryScreen = QGuiApplication::primaryScreen();
80 QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen);
81 if (m_x + m_xoffset < g.left())
82 m_x = g.left() - m_xoffset;
83 else if (m_x + m_xoffset > g.right())
84 m_x = g.right() - m_xoffset;
85
86 if (m_y + m_yoffset < g.top())
87 m_y = g.top() - m_yoffset;
88 else if (m_y + m_yoffset > g.bottom())
89 m_y = g.bottom() - m_yoffset;
90}
91
92void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
94{
95 // update current absolute coordinates
96 if (!abs) {
97 m_x += x;
98 m_y += y;
99 } else {
100 m_x = x;
101 m_y = y;
102 }
103
104 clampPosition();
105
106 QPoint pos(m_x + m_xoffset, m_y + m_yoffset);
107 // Cannot track the keyboard modifiers ourselves here. Instead, report the
108 // modifiers from the last key event that has been seen by QGuiApplication.
110}
111
113{
114 QPoint pos(m_x + m_xoffset, m_y + m_yoffset);
116}
117
119{
120 qCDebug(qLcEvdevMouse, "Adding mouse at %ls", qUtf16Printable(deviceNode));
121 auto handler = QEvdevMouseHandler::create(deviceNode, m_spec);
122 if (handler) {
127 m_mice.add(deviceNode, std::move(handler));
128 updateDeviceCount();
129 } else {
130 qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode));
131 }
132}
133
135{
136 if (m_mice.remove(deviceNode)) {
137 qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode));
138 updateDeviceCount();
139 }
140}
141
142void QEvdevMouseManager::updateDeviceCount()
143{
146}
147
IOBluetoothDevice * device
void deviceDetected(const QString &deviceNode)
static QDeviceDiscovery * create(QDeviceTypes type, QObject *parent=nullptr)
void deviceRemoved(const QString &deviceNode)
void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons, Qt::MouseButton button, QEvent::Type type)
static std::unique_ptr< QEvdevMouseHandler > create(const QString &device, const QString &specification)
void handleWheelEvent(QPoint delta)
void addMouse(const QString &deviceNode=QString())
void removeMouse(const QString &deviceNode)
void handleWheelEvent(QPoint delta)
void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons, Qt::MouseButton button, QEvent::Type type)
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
static QInputDeviceManager * inputDeviceManager()
QScreen * primaryScreen
the primary (or default) screen of the application.
static QInputDeviceManagerPrivate * get(QInputDeviceManager *mgr)
QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
void cursorPositionChangeRequested(const QPoint &pos)
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect virtualGeometry
the pixel geometry of the virtual desktop to which this screen belongs
Definition qscreen.h:47
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
void add(const QString &deviceNode, std::unique_ptr< Handler > handler)
bool remove(const QString &deviceNode)
QPushButton * button
[2]
ParsedSpecification parseSpecification(const QString &specification)
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
MouseButton
Definition qnamespace.h:56
EGLDeviceEXT * devices
#define qWarning
Definition qlogging.h:166
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLint GLint GLint GLint x
[0]
GLuint64 key
GLenum type
GLboolean GLboolean g
GLint y
SSL_CTX int void * arg
#define qUtf16Printable(string)
Definition qstring.h:1543
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define Q_UNUSED(x)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QNetworkAccessManager manager