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
qwaylandinputdevice_p.h
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
4#ifndef QWAYLANDINPUTDEVICE_H
5#define QWAYLANDINPUTDEVICE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
19#include <QtWaylandClient/private/qwaylandwindow_p.h>
20
21#include <QtCore/QScopedPointer>
22#include <QSocketNotifier>
23#include <QObject>
24#include <QTimer>
25#include <qpa/qplatformintegration.h>
26#include <qpa/qplatformscreen.h>
27#include <qpa/qwindowsysteminterface.h>
28
29#include <QtWaylandClient/private/qwayland-wayland.h>
30#include <QtWaylandClient/private/qwayland-pointer-gestures-unstable-v1.h>
31
32#if QT_CONFIG(xkbcommon)
33#include <QtGui/private/qxkbcommon_p.h>
34#endif
35
36#include <QtCore/QDebug>
37#include <QtCore/QElapsedTimer>
38#include <QtCore/QPointer>
39
40#if QT_CONFIG(cursor)
41struct wl_cursor_image;
42#endif
43
45
46namespace QtWayland {
47class zwp_primary_selection_device_v1;
48} //namespace QtWayland
49
50namespace QtWaylandClient {
51
52class QWaylandDataDevice;
53class QWaylandDisplay;
54#if QT_CONFIG(wayland_client_primary_selection)
55class QWaylandPrimarySelectionDeviceV1;
56#endif
57#if QT_CONFIG(tabletevent)
58class QWaylandTabletSeatV2;
59#endif
60class QWaylandPointerGestures;
61class QWaylandPointerGestureSwipe;
62class QWaylandPointerGesturePinch;
63class QWaylandTextInputInterface;
64class QWaylandTextInputMethod;
65#if QT_CONFIG(cursor)
66class QWaylandCursorTheme;
67class QWaylandCursorShape;
68class CursorSurface;
69#endif
70
71Q_DECLARE_LOGGING_CATEGORY(lcQpaWaylandInput);
72
73class Q_WAYLANDCLIENT_EXPORT QWaylandInputDevice
74 : public QObject
75 , public QtWayland::wl_seat
76{
78public:
79 class Keyboard;
80 class Pointer;
81 class Touch;
82
83 QWaylandInputDevice(QWaylandDisplay *display, int version, uint32_t id);
84 ~QWaylandInputDevice() override;
85
86 uint32_t capabilities() const { return mCaps; }
87 QString seatname() const { return mSeatName; }
88
89 QWaylandDisplay *display() const { return mQDisplay; }
90 struct ::wl_seat *wl_seat() { return QtWayland::wl_seat::object(); }
91
92#if QT_CONFIG(cursor)
93 void setCursor(const QCursor *cursor, const QSharedPointer<QWaylandBuffer> &cachedBuffer = {}, int fallbackOutputScale = 1);
94#endif
95 void handleEndDrag();
96
97#if QT_CONFIG(wayland_datadevice)
98 void setDataDevice(QWaylandDataDevice *device);
99 QWaylandDataDevice *dataDevice() const;
100#endif
101
102#if QT_CONFIG(wayland_client_primary_selection)
103 void setPrimarySelectionDevice(QWaylandPrimarySelectionDeviceV1 *primarySelectionDevice);
104 QWaylandPrimarySelectionDeviceV1 *primarySelectionDevice() const;
105#endif
106
107#if QT_CONFIG(tabletevent)
108 void setTabletSeat(QWaylandTabletSeatV2 *tabletSeat);
109 QWaylandTabletSeatV2* tabletSeat() const;
110#endif
111
112 void setTextInput(QWaylandTextInputInterface *textInput);
113 QWaylandTextInputInterface *textInput() const;
114
115 void setTextInputMethod(QWaylandTextInputMethod *textInputMethod);
116 QWaylandTextInputMethod *textInputMethod() const;
117
118 void removeMouseButtonFromState(Qt::MouseButton button);
119
120 QWaylandWindow *pointerFocus() const;
121 QWaylandWindow *keyboardFocus() const;
122 QWaylandWindow *touchFocus() const;
123
124 QList<int> possibleKeys(const QKeyEvent *event) const;
125
126 QPointF pointerSurfacePosition() const;
127
128 Qt::KeyboardModifiers modifiers() const;
129
130 uint32_t serial() const;
131
132 virtual Keyboard *createKeyboard(QWaylandInputDevice *device);
133 virtual Pointer *createPointer(QWaylandInputDevice *device);
134 virtual Touch *createTouch(QWaylandInputDevice *device);
135
136 Keyboard *keyboard() const;
137 Pointer *pointer() const;
138 QWaylandPointerGestureSwipe *pointerGestureSwipe() const;
139 QWaylandPointerGesturePinch *pointerGesturePinch() const;
140 Touch *touch() const;
141
142protected:
143 QWaylandDisplay *mQDisplay = nullptr;
144 struct wl_display *mDisplay = nullptr;
145
146 uint32_t mCaps = 0;
148
149#if QT_CONFIG(cursor)
150 struct CursorState {
151 QSharedPointer<QWaylandBuffer> bitmapBuffer; // not used with shape cursors
152 int bitmapScale = 1;
154 int fallbackOutputScale = 1;
155 QPoint hotspot;
156 QElapsedTimer animationTimer;
157 } mCursor;
158#endif
159
160#if QT_CONFIG(wayland_datadevice)
161 QWaylandDataDevice *mDataDevice = nullptr;
162#endif
163
164#if QT_CONFIG(wayland_client_primary_selection)
165 QScopedPointer<QWaylandPrimarySelectionDeviceV1> mPrimarySelectionDevice;
166#endif
167
168 QScopedPointer<Keyboard> mKeyboard;
169 QScopedPointer<Pointer> mPointer;
170 QScopedPointer<QWaylandPointerGestureSwipe> mPointerGestureSwipe;
171 QScopedPointer<QWaylandPointerGesturePinch> mPointerGesturePinch;
172 QScopedPointer<Touch> mTouch;
173
174 QScopedPointer<QWaylandTextInputInterface> mTextInput;
175 QScopedPointer<QWaylandTextInputMethod> mTextInputMethod;
176#if QT_CONFIG(tabletevent)
177 QScopedPointer<QWaylandTabletSeatV2> mTabletSeat;
178#endif
179
180 uint32_t mTime = 0;
181 uint32_t mSerial = 0;
182
183 void seat_capabilities(uint32_t caps) override;
184 void seat_name(const QString &name) override;
185 void handleTouchPoint(int id, QEventPoint::State state, const QPointF &surfacePosition = QPoint());
186
187 QPointingDevice *mTouchDevice = nullptr;
188 QPointingDevice *mTouchPadDevice = nullptr;
189
194 friend class QWaylandWindow;
195};
196
197inline uint32_t QWaylandInputDevice::serial() const
198{
199 return mSerial;
200}
201
202
203class Q_WAYLANDCLIENT_EXPORT QWaylandInputDevice::Keyboard : public QObject, public QtWayland::wl_keyboard
204{
206
207public:
209 ~Keyboard() override;
210
212
213 void keyboard_keymap(uint32_t format,
214 int32_t fd,
215 uint32_t size) override;
216 void keyboard_enter(uint32_t time,
217 struct wl_surface *surface,
218 struct wl_array *keys) override;
219 void keyboard_leave(uint32_t time,
220 struct wl_surface *surface) override;
221 void keyboard_key(uint32_t serial, uint32_t time,
222 uint32_t key, uint32_t state) override;
223 void keyboard_modifiers(uint32_t serial,
224 uint32_t mods_depressed,
225 uint32_t mods_latched,
226 uint32_t mods_locked,
227 uint32_t group) override;
228 void keyboard_repeat_info(int32_t rate, int32_t delay) override;
229
230 QWaylandInputDevice *mParent = nullptr;
231 QPointer<QWaylandSurface> mFocus;
232
233 uint32_t mNativeModifiers = 0;
234
235 struct repeatKey {
236 int key = 0;
237 uint32_t code = 0;
238 uint32_t time = 0 ;
240 uint32_t nativeVirtualKey = 0;
241 } mRepeatKey;
242
244 int mRepeatRate = 25;
245 int mRepeatDelay = 400;
246
247 uint32_t mKeymapFormat = WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1;
248
249 Qt::KeyboardModifiers modifiers() const;
250
251 struct ::wl_keyboard *wl_keyboard() { return QtWayland::wl_keyboard::object(); }
252
253#if QT_CONFIG(xkbcommon)
254 virtual int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, xkb_state *state, xkb_keycode_t code) {
256 }
257#endif
258
259private Q_SLOTS:
260 void handleFocusDestroyed();
261 void handleFocusLost();
262
263private:
264#if QT_CONFIG(xkbcommon)
265 bool createDefaultKeymap();
266#endif
267 void handleKey(ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
268 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
269 const QString &text, bool autorepeat = false, ushort count = 1);
270
271#if QT_CONFIG(xkbcommon)
274#endif
276};
277
278class Q_WAYLANDCLIENT_EXPORT QWaylandInputDevice::Pointer : public QObject, public QtWayland::wl_pointer
279{
281public:
283 ~Pointer() override;
285#if QT_CONFIG(cursor)
286 int idealCursorScale() const;
287 void updateCursorTheme();
288 void updateCursor();
289 void cursorTimerCallback();
290 void cursorFrameCallback();
291 CursorSurface *getOrCreateCursorSurface();
292#endif
293 QWaylandInputDevice *seat() const { return mParent; }
294
295 struct ::wl_pointer *wl_pointer() { return QtWayland::wl_pointer::object(); }
296
297protected:
298 void pointer_enter(uint32_t serial, struct wl_surface *surface,
299 wl_fixed_t sx, wl_fixed_t sy) override;
300 void pointer_leave(uint32_t time, struct wl_surface *surface) override;
301 void pointer_motion(uint32_t time,
302 wl_fixed_t sx, wl_fixed_t sy) override;
303 void pointer_button(uint32_t serial, uint32_t time,
304 uint32_t button, uint32_t state) override;
305 void pointer_axis(uint32_t time,
306 uint32_t axis,
307 wl_fixed_t value) override;
308 void pointer_axis_source(uint32_t source) override;
309 void pointer_axis_stop(uint32_t time, uint32_t axis) override;
310 void pointer_axis_discrete(uint32_t axis, int32_t value) override;
311 void pointer_frame() override;
312 void pointer_axis_value120(uint32_t axis, int32_t value120) override;
313 void pointer_axis_relative_direction(uint32_t axis, uint32_t direction) override;
314
315private Q_SLOTS:
316 void handleFocusDestroyed() { invalidateFocus(); }
317
318private:
319 void invalidateFocus();
320
321public:
323
324 QWaylandInputDevice *mParent = nullptr;
325 QPointer<QWaylandSurface> mFocus;
326 uint32_t mEnterSerial = 0;
327#if QT_CONFIG(cursor)
328 struct {
329 QScopedPointer<QWaylandCursorShape> shape;
330 QWaylandCursorTheme *theme = nullptr;
331 int themeBufferScale = 0;
332 QScopedPointer<CursorSurface> surface;
334 bool gotFrameCallback = false;
335 bool gotTimerCallback = false;
336 } mCursor;
337#endif
340 Qt::MouseButtons mButtons = Qt::NoButton;
342
343 struct FrameData {
344 QWaylandPointerEvent *event = nullptr;
345
348 axis_source axisSource = axis_source_wheel;
349 bool verticalAxisInverted = false;
350 bool horizontalAxisInverted = false;
351
353 bool hasPixelDelta() const;
354 QPoint pixelDeltaAndError(QPointF *accumulatedError) const;
355 QPoint pixelDelta() const { return hasPixelDelta() ? delta.toPoint() : QPoint(); }
358 } mFrameData;
359
360 bool mScrollBeginSent = false;
362
366private: //TODO: should other methods be private as well?
367 bool isDefinitelyTerminated(axis_source source) const;
368};
369
370class Q_WAYLANDCLIENT_EXPORT QWaylandInputDevice::Touch : public QtWayland::wl_touch
371{
372public:
374 ~Touch() override;
375
376 void touch_down(uint32_t serial,
377 uint32_t time,
378 struct wl_surface *surface,
379 int32_t id,
380 wl_fixed_t x,
381 wl_fixed_t y) override;
382 void touch_up(uint32_t serial,
383 uint32_t time,
384 int32_t id) override;
385 void touch_motion(uint32_t time,
386 int32_t id,
387 wl_fixed_t x,
388 wl_fixed_t y) override;
389 void touch_frame() override;
390 void touch_cancel() override;
391
394
395 struct ::wl_touch *wl_touch() { return QtWayland::wl_touch::object(); }
396
397 QWaylandInputDevice *mParent = nullptr;
398 QPointer<QWaylandWindow> mFocus;
399 QList<QWindowSystemInterface::TouchPoint> mPendingTouchPoints;
400};
401
403{
405public:
407 ulong timestamp, const QPointF &localPos, const QPointF &globalPos,
408 Qt::MouseButtons buttons, Qt::MouseButton button,
409 Qt::KeyboardModifiers modifiers)
410 : type(type)
411 , phase(phase)
413 , local(localPos)
414 , global(globalPos)
416 , button(button)
419 {}
437
443 Qt::MouseButtons buttons;
444 Qt::MouseButton button = Qt::NoButton; // Button that caused the event (QMouseEvent::button)
445 Qt::KeyboardModifiers modifiers;
449 QPointer<QWaylandWindow> surface;
450 bool inverted = false;
451};
452
453#ifndef QT_NO_GESTURES
478
508#endif // #ifndef QT_NO_GESTURES
509
510}
511
513
514#endif
IOBluetoothDevice * device
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
State
Specifies the state of this event point.
Definition qeventpoint.h:48
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qtimer.h:20
std::unique_ptr< struct xkb_keymap, XKBKeymapDeleter > ScopedXKBKeymap
std::unique_ptr< struct xkb_state, XKBStateDeleter > ScopedXKBState
static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers)
void keyboard_key(uint32_t serial, uint32_t time, uint32_t key, uint32_t state) override
void touch_down(uint32_t serial, uint32_t time, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y) override
void touch_up(uint32_t serial, uint32_t time, int32_t id) override
void pointer_axis(uint32_t time, uint32_t axis, wl_fixed_t value) override
void pointer_axis_value120(uint32_t axis, int32_t value120) override
void pointer_axis_stop(uint32_t time, uint32_t axis) override
void pointer_axis_discrete(uint32_t axis, int32_t value) override
QList< QWindowSystemInterface::TouchPoint > mPendingTouchPoints
Pointer(QWaylandInputDevice *seat)
void touch_motion(uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y) override
void keyboard_repeat_info(int32_t rate, int32_t delay) override
QScopedPointer< QWaylandPointerGestureSwipe > mPointerGestureSwipe
QScopedPointer< QWaylandTextInputInterface > mTextInput
Keyboard(QWaylandInputDevice *p)
Qt::KeyboardModifiers modifiers() const
void keyboard_modifiers(uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) override
QWaylandWindow * focusWindow() const
void pointer_button(uint32_t serial, uint32_t time, uint32_t button, uint32_t state) override
void pointer_leave(uint32_t time, struct wl_surface *surface) override
void setFrameEvent(QWaylandPointerEvent *event)
void keyboard_keymap(uint32_t format, int32_t fd, uint32_t size) override
void keyboard_enter(uint32_t time, struct wl_surface *surface, struct wl_array *keys) override
QScopedPointer< QWaylandPointerGesturePinch > mPointerGesturePinch
void pointer_enter(uint32_t serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) override
void keyboard_leave(uint32_t time, struct wl_surface *surface) override
QScopedPointer< QWaylandTextInputMethod > mTextInputMethod
Touch(QWaylandInputDevice *p)
void pointer_axis_relative_direction(uint32_t axis, uint32_t direction) override
void pointer_motion(uint32_t time, wl_fixed_t sx, wl_fixed_t sy) override
void pointer_axis_source(uint32_t source) override
QWaylandPointerEvent(QEvent::Type type, Qt::ScrollPhase phase, QWaylandWindow *surface, ulong timestamp, const QPointF &local, const QPointF &global, const QPoint &pixelDelta, const QPoint &angleDelta, Qt::MouseEventSource source, Qt::KeyboardModifiers modifiers, bool inverted)
QWaylandPointerEvent(QEvent::Type type, Qt::ScrollPhase phase, QWaylandWindow *surface, ulong timestamp, const QPointF &localPos, const QPointF &globalPos, Qt::MouseButtons buttons, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
QWaylandPointerGesturePinchEvent(QWaylandWindow *surface, Qt::GestureState state, ulong timestamp, const QPointF &local, const QPointF &global, uint fingers, const QPointF &delta, qreal scale_delta, qreal rotation_delta)
QWaylandPointerGestureSwipeEvent(QWaylandWindow *surface, Qt::GestureState state, ulong timestamp, const QPointF &local, const QPointF &global, uint fingers, const QPointF &delta)
EGLImageKHR int int EGLuint64KHR * modifiers
QString text
QPushButton * button
[2]
QCursor cursor
direction
else opt state
[0]
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
MouseButton
Definition qnamespace.h:56
@ NoButton
Definition qnamespace.h:57
GestureState
@ NoGesture
MouseEventSource
@ MouseEventNotSynthesized
CursorShape
@ ArrowCursor
ScrollPhase
@ NoScrollPhase
@ Keyboard
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLint GLint GLint GLint x
[0]
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLenum type
GLboolean GLuint group
GLuint64 GLenum GLint fd
GLuint name
GLint GLsizei GLsizei GLenum format
GLint y
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint GLenum * rate
GLsizei const void * pointer
Definition qopenglext.h:384
GLfloat GLfloat p
[1]
static QT_BEGIN_NAMESPACE QElapsedTimer frameTimer
#define Q_OBJECT
#define Q_SLOTS
#define Q_GADGET
unsigned int quint32
Definition qtypes.h:50
unsigned long ulong
Definition qtypes.h:35
unsigned int uint
Definition qtypes.h:34
unsigned short ushort
Definition qtypes.h:33
double qreal
Definition qtypes.h:187
int keysym
Definition qvnc.cpp:139
QStringList keys
item setCursor(Qt::IBeamCursor)
[1]
Qt::MouseEventSource wheelEventSource() const
QPoint pixelDeltaAndError(QPointF *accumulatedError) const