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
qlibinputpointer.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#include <libinput.h>
6#include <QtCore/QEvent>
7#include <QtGui/QGuiApplication>
8#include <QtGui/QScreen>
9#include <QtGui/private/qguiapplication_p.h>
10#include <QtGui/private/qinputdevicemanager_p.h>
11#include <qpa/qwindowsysteminterface.h>
12#include <private/qhighdpiscaling_p.h>
13
15
20
21void QLibInputPointer::processButton(libinput_event_pointer *e)
22{
23 const uint32_t b = libinput_event_pointer_get_button(e);
24 const bool pressed = libinput_event_pointer_get_button_state(e) == LIBINPUT_BUTTON_STATE_PRESSED;
25
27 switch (b) {
28 case 0x110: button = Qt::LeftButton; break; // BTN_LEFT
29 case 0x111: button = Qt::RightButton; break;
30 case 0x112: button = Qt::MiddleButton; break;
31 case 0x113: button = Qt::ExtraButton1; break; // AKA Qt::BackButton
32 case 0x114: button = Qt::ExtraButton2; break; // AKA Qt::ForwardButton
33 case 0x115: button = Qt::ExtraButton3; break; // AKA Qt::TaskButton
34 case 0x116: button = Qt::ExtraButton4; break;
35 case 0x117: button = Qt::ExtraButton5; break;
36 case 0x118: button = Qt::ExtraButton6; break;
37 case 0x119: button = Qt::ExtraButton7; break;
38 case 0x11a: button = Qt::ExtraButton8; break;
39 case 0x11b: button = Qt::ExtraButton9; break;
40 case 0x11c: button = Qt::ExtraButton10; break;
41 case 0x11d: button = Qt::ExtraButton11; break;
42 case 0x11e: button = Qt::ExtraButton12; break;
43 case 0x11f: button = Qt::ExtraButton13; break;
44 }
45
46 m_buttons.setFlag(button, pressed);
47
49 Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers();
50
51 QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons, button, type, mods);
52}
53
54void QLibInputPointer::processMotion(libinput_event_pointer *e)
55{
56 const double dx = libinput_event_pointer_get_dx(e);
57 const double dy = libinput_event_pointer_get_dy(e);
58 QScreen * const primaryScreen = QGuiApplication::primaryScreen();
59 const QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen);
60
61 m_pos.setX(qBound(g.left(), qRound(m_pos.x() + dx), g.right()));
62 m_pos.setY(qBound(g.top(), qRound(m_pos.y() + dy), g.bottom()));
63
64 Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers();
65
66 QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons,
68}
69
70void QLibInputPointer::processAbsMotion(libinput_event_pointer *e)
71{
72 QScreen * const primaryScreen = QGuiApplication::primaryScreen();
73 const QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen);
74
75 const double x = libinput_event_pointer_get_absolute_x_transformed(e, g.width());
76 const double y = libinput_event_pointer_get_absolute_y_transformed(e, g.height());
77
78 m_pos.setX(qBound(g.left(), qRound(g.left() + x), g.right()));
79 m_pos.setY(qBound(g.top(), qRound(g.top() + y), g.bottom()));
80
81 Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers();
82
83 QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons,
85
86}
87
88void QLibInputPointer::processAxis(libinput_event_pointer *e)
89{
90 double value; // default axis value is 15 degrees per wheel click
91 QPoint angleDelta;
92#if !QT_CONFIG(libinput_axis_api)
93 value = libinput_event_pointer_get_axis_value(e);
94 if (libinput_event_pointer_get_axis(e) == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)
95 angleDelta.setY(qRound(value));
96 else
97 angleDelta.setX(qRound(value));
98#else
99 if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
100#if QT_CONFIG(libinput_hires_wheel_support)
101 value = libinput_event_pointer_get_scroll_value_v120(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
102#else
103 value = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
104#endif
105 angleDelta.setY(qRound(value));
106 }
107 if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
108#if QT_CONFIG(libinput_hires_wheel_support)
109 value = libinput_event_pointer_get_scroll_value_v120(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
110#else
111 value = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
112#endif
113 angleDelta.setX(qRound(value));
114 }
115#endif
116#if QT_CONFIG(libinput_hires_wheel_support)
117 const int factor = -1;
118#else
119 const int factor = -8;
120#endif
121 angleDelta *= factor;
122 Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers();
123 QWindowSystemInterface::handleWheelEvent(nullptr, m_pos, m_pos, QPoint(), angleDelta, mods);
124}
125
127{
128 QScreen * const primaryScreen = QGuiApplication::primaryScreen();
129 const QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen);
130
131 m_pos.setX(qBound(g.left(), pos.x(), g.right()));
132 m_pos.setY(qBound(g.top(), pos.y(), g.bottom()));
133}
134
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ MouseButtonRelease
Definition qcoreevent.h:61
static QInputDeviceManager * inputDeviceManager()
QScreen * primaryScreen
the primary (or default) screen of the application.
void processAxis(libinput_event_pointer *e)
void setPos(const QPoint &pos)
void processButton(libinput_event_pointer *e)
void processMotion(libinput_event_pointer *e)
void processAbsMotion(libinput_event_pointer *e)
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr void setY(int y) noexcept
Sets the y coordinate of this point to the given y coordinate.
Definition qpoint.h:145
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:140
\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
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)
QPushButton * button
[2]
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
Definition qcompare.h:63
MouseButton
Definition qnamespace.h:56
@ ExtraButton9
Definition qnamespace.h:74
@ LeftButton
Definition qnamespace.h:58
@ ExtraButton5
Definition qnamespace.h:70
@ ExtraButton6
Definition qnamespace.h:71
@ RightButton
Definition qnamespace.h:59
@ ExtraButton12
Definition qnamespace.h:77
@ ExtraButton10
Definition qnamespace.h:75
@ MiddleButton
Definition qnamespace.h:60
@ ExtraButton2
Definition qnamespace.h:66
@ ExtraButton1
Definition qnamespace.h:63
@ ExtraButton11
Definition qnamespace.h:76
@ ExtraButton13
Definition qnamespace.h:78
@ NoButton
Definition qnamespace.h:57
@ ExtraButton8
Definition qnamespace.h:73
@ ExtraButton3
Definition qnamespace.h:68
@ ExtraButton7
Definition qnamespace.h:72
@ ExtraButton4
Definition qnamespace.h:69
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
Qt::MouseButtons m_buttons
Definition qnsview.mm:102
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLenum type
GLboolean GLboolean g
GLint y