| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef QWAYLANDINPUTDEVICE_H |
| 6 |
#define QWAYLANDINPUTDEVICE_H |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h> |
| 20 |
#include <QtWaylandClient/private/qwaylandwindow_p.h> |
| 21 |
|
| 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 <wayland-client.h> |
| 30 |
|
| 31 |
#include <QtWaylandClient/private/qwayland-wayland.h> |
| 32 |
|
| 33 |
#if QT_CONFIG(xkbcommon_evdev) |
| 34 |
#include <xkbcommon/xkbcommon.h> |
| 35 |
#include <xkbcommon/xkbcommon-keysyms.h> |
| 36 |
#endif |
| 37 |
|
| 38 |
#include <QtCore/QDebug> |
| 39 |
#include <QPointer> |
| 40 |
|
| 41 |
#if QT_CONFIG(cursor) |
| 42 |
struct wl_cursor_image; |
| 43 |
#endif |
| 44 |
|
| 45 |
#if QT_CONFIG(xkbcommon_evdev) |
| 46 |
struct xkb_compose_state; |
| 47 |
struct xkb_compose_table; |
| 48 |
#endif |
| 49 |
|
| 50 |
QT_BEGIN_NAMESPACE |
| 51 |
|
| 52 |
namespace QtWaylandClient { |
| 53 |
|
| 54 |
class QWaylandWindow; |
| 55 |
class QWaylandDisplay; |
| 56 |
class QWaylandDataDevice; |
| 57 |
class QWaylandTextInput; |
| 58 |
|
| 59 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice |
| 60 |
: public QObject |
| 61 |
, public QtWayland::wl_seat |
| 62 |
{ |
| 63 |
Q_OBJECT |
| 64 |
public: |
| 65 |
class Keyboard; |
| 66 |
class Pointer; |
| 67 |
class Touch; |
| 68 |
|
| 69 |
QWaylandInputDevice(QWaylandDisplay *display, int version, uint32_t id); |
| 70 |
~QWaylandInputDevice() override; |
| 71 |
|
| 72 |
uint32_t capabilities() const { return mCaps; } |
| 73 |
|
| 74 |
struct ::wl_seat *wl_seat() { return QtWayland::wl_seat::object(); } |
| 75 |
|
| 76 |
#if QT_CONFIG(cursor) |
| 77 |
void setCursor(const QCursor &cursor, QWaylandScreen *screen); |
| 78 |
void setCursor(struct wl_buffer *buffer, struct ::wl_cursor_image *image, int bufferScale); |
| 79 |
void setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size, int bufferScale); |
| 80 |
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, int bufferScale); |
| 81 |
#endif |
| 82 |
void handleWindowDestroyed(QWaylandWindow *window); |
| 83 |
void handleEndDrag(); |
| 84 |
|
| 85 |
#if QT_CONFIG(wayland_datadevice) |
| 86 |
void setDataDevice(QWaylandDataDevice *device); |
| 87 |
QWaylandDataDevice *dataDevice() const; |
| 88 |
#endif |
| 89 |
|
| 90 |
void setTextInput(QWaylandTextInput *textInput); |
| 91 |
QWaylandTextInput *textInput() const; |
| 92 |
|
| 93 |
void removeMouseButtonFromState(Qt::MouseButton button); |
| 94 |
|
| 95 |
QWaylandWindow *pointerFocus() const; |
| 96 |
QWaylandWindow *keyboardFocus() const; |
| 97 |
QWaylandWindow *touchFocus() const; |
| 98 |
|
| 99 |
Qt::KeyboardModifiers modifiers() const; |
| 100 |
|
| 101 |
uint32_t serial() const; |
| 102 |
uint32_t cursorSerial() const; |
| 103 |
|
| 104 |
virtual Keyboard *createKeyboard(QWaylandInputDevice *device); |
| 105 |
virtual Pointer *createPointer(QWaylandInputDevice *device); |
| 106 |
virtual Touch *createTouch(QWaylandInputDevice *device); |
| 107 |
|
| 108 |
private: |
| 109 |
void setCursor(Qt::CursorShape cursor, QWaylandScreen *screen); |
| 110 |
|
| 111 |
QWaylandDisplay *mQDisplay = nullptr; |
| 112 |
struct wl_display *mDisplay = nullptr; |
| 113 |
|
| 114 |
int mVersion; |
| 115 |
uint32_t mCaps = 0; |
| 116 |
|
| 117 |
struct wl_surface *pointerSurface = nullptr; |
| 118 |
|
| 119 |
#if QT_CONFIG(wayland_datadevice) |
| 120 |
QWaylandDataDevice *mDataDevice = nullptr; |
| 121 |
#endif |
| 122 |
|
| 123 |
Keyboard *mKeyboard = nullptr; |
| 124 |
Pointer *mPointer = nullptr; |
| 125 |
Touch *mTouch = nullptr; |
| 126 |
|
| 127 |
QWaylandTextInput *mTextInput = nullptr; |
| 128 |
|
| 129 |
uint32_t mTime = 0; |
| 130 |
uint32_t mSerial = 0; |
| 131 |
|
| 132 |
void seat_capabilities(uint32_t caps) override; |
| 133 |
void handleTouchPoint(int id, double x, double y, Qt::TouchPointState state); |
| 134 |
|
| 135 |
QTouchDevice *mTouchDevice = nullptr; |
| 136 |
|
| 137 |
QSharedPointer<QWaylandBuffer> mPixmapCursor; |
| 138 |
|
| 139 |
friend class QWaylandTouchExtension; |
| 140 |
friend class QWaylandQtKeyExtension; |
| 141 |
}; |
| 142 |
|
| 143 |
inline uint32_t QWaylandInputDevice::serial() const |
| 144 |
{ |
| 145 |
return mSerial; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Keyboard : public QObject, public QtWayland::wl_keyboard |
| 150 |
{ |
| 151 |
Q_OBJECT |
| 152 |
|
| 153 |
public: |
| 154 |
Keyboard(QWaylandInputDevice *p); |
| 155 |
~Keyboard() override; |
| 156 |
|
| 157 |
void stopRepeat(); |
| 158 |
|
| 159 |
void keyboard_keymap(uint32_t format, |
| 160 |
int32_t fd, |
| 161 |
uint32_t size) override; |
| 162 |
void keyboard_enter(uint32_t time, |
| 163 |
struct wl_surface *surface, |
| 164 |
struct wl_array *keys) override; |
| 165 |
void keyboard_leave(uint32_t time, |
| 166 |
struct wl_surface *surface) override; |
| 167 |
void keyboard_key(uint32_t serial, uint32_t time, |
| 168 |
uint32_t key, uint32_t state) override; |
| 169 |
void keyboard_modifiers(uint32_t serial, |
| 170 |
uint32_t mods_depressed, |
| 171 |
uint32_t mods_latched, |
| 172 |
uint32_t mods_locked, |
| 173 |
uint32_t group) override; |
| 174 |
|
| 175 |
QWaylandInputDevice *mParent = nullptr; |
| 176 |
QPointer<QWaylandWindow> mFocus; |
| 177 |
#if QT_CONFIG(xkbcommon_evdev) |
| 178 |
xkb_context *mXkbContext = nullptr; |
| 179 |
xkb_keymap *mXkbMap = nullptr; |
| 180 |
xkb_state *mXkbState = nullptr; |
| 181 |
xkb_compose_table *mXkbComposeTable = nullptr; |
| 182 |
xkb_compose_state *mXkbComposeState = nullptr; |
| 183 |
#endif |
| 184 |
uint32_t mNativeModifiers = 0; |
| 185 |
|
| 186 |
int mRepeatKey; |
| 187 |
uint32_t mRepeatCode; |
| 188 |
uint32_t mRepeatTime; |
| 189 |
QString mRepeatText; |
| 190 |
#if QT_CONFIG(xkbcommon_evdev) |
| 191 |
xkb_keysym_t mRepeatSym; |
| 192 |
#endif |
| 193 |
QTimer mRepeatTimer; |
| 194 |
|
| 195 |
Qt::KeyboardModifiers modifiers() const; |
| 196 |
|
| 197 |
private slots: |
| 198 |
void repeatKey(); |
| 199 |
|
| 200 |
private: |
| 201 |
#if QT_CONFIG(xkbcommon_evdev) |
| 202 |
bool createDefaultKeyMap(); |
| 203 |
void releaseKeyMap(); |
| 204 |
void createComposeState(); |
| 205 |
void releaseComposeState(); |
| 206 |
#endif |
| 207 |
|
| 208 |
}; |
| 209 |
|
| 210 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Pointer : public QtWayland::wl_pointer |
| 211 |
{ |
| 212 |
|
| 213 |
public: |
| 214 |
Pointer(QWaylandInputDevice *p); |
| 215 |
~Pointer() override; |
| 216 |
|
| 217 |
void pointer_enter(uint32_t serial, struct wl_surface *surface, |
| 218 |
wl_fixed_t sx, wl_fixed_t sy) override; |
| 219 |
void pointer_leave(uint32_t time, struct wl_surface *surface) override; |
| 220 |
void pointer_motion(uint32_t time, |
| 221 |
wl_fixed_t sx, wl_fixed_t sy) override; |
| 222 |
void pointer_button(uint32_t serial, uint32_t time, |
| 223 |
uint32_t button, uint32_t state) override; |
| 224 |
void pointer_axis(uint32_t time, |
| 225 |
uint32_t axis, |
| 226 |
wl_fixed_t value) override; |
| 227 |
|
| 228 |
void releaseButtons(); |
| 229 |
|
| 230 |
QWaylandInputDevice *mParent = nullptr; |
| 231 |
QPointer<QWaylandWindow> mFocus; |
| 232 |
uint32_t mEnterSerial = 0; |
| 233 |
#if QT_CONFIG(cursor) |
| 234 |
uint32_t mCursorSerial = 0; |
| 235 |
#endif |
| 236 |
QPointF mSurfacePos; |
| 237 |
QPointF mGlobalPos; |
| 238 |
Qt::MouseButtons mButtons = Qt::NoButton; |
| 239 |
#if QT_CONFIG(cursor) |
| 240 |
wl_buffer *mCursorBuffer = nullptr; |
| 241 |
Qt::CursorShape mCursorShape = Qt::BitmapCursor; |
| 242 |
#endif |
| 243 |
}; |
| 244 |
|
| 245 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Touch : public QtWayland::wl_touch |
| 246 |
{ |
| 247 |
public: |
| 248 |
Touch(QWaylandInputDevice *p); |
| 249 |
~Touch() override; |
| 250 |
|
| 251 |
void touch_down(uint32_t serial, |
| 252 |
uint32_t time, |
| 253 |
struct wl_surface *surface, |
| 254 |
int32_t id, |
| 255 |
wl_fixed_t x, |
| 256 |
wl_fixed_t y) override; |
| 257 |
void touch_up(uint32_t serial, |
| 258 |
uint32_t time, |
| 259 |
int32_t id) override; |
| 260 |
void touch_motion(uint32_t time, |
| 261 |
int32_t id, |
| 262 |
wl_fixed_t x, |
| 263 |
wl_fixed_t y) override; |
| 264 |
void touch_frame() override; |
| 265 |
void touch_cancel() override; |
| 266 |
|
| 267 |
bool allTouchPointsReleased(); |
| 268 |
void releasePoints(); |
| 269 |
|
| 270 |
QWaylandInputDevice *mParent = nullptr; |
| 271 |
QPointer<QWaylandWindow> mFocus; |
| 272 |
QList<QWindowSystemInterface::TouchPoint> mTouchPoints; |
| 273 |
QList<QWindowSystemInterface::TouchPoint> mPrevTouchPoints; |
| 274 |
}; |
| 275 |
|
| 276 |
class QWaylandPointerEvent |
| 277 |
{ |
| 278 |
public: |
| 279 |
enum Type { |
| 280 |
Enter, |
| 281 |
Motion, |
| 282 |
Wheel |
| 283 |
}; |
| 284 |
inline QWaylandPointerEvent(Type t, ulong ts, const QPointF &l, const QPointF &g, Qt::MouseButtons b, Qt::KeyboardModifiers m) |
| 285 |
: type(t) |
| 286 |
, timestamp(ts) |
| 287 |
, local(l) |
| 288 |
, global(g) |
| 289 |
, buttons(b) |
| 290 |
, modifiers(m) |
| 291 |
{} |
| 292 |
inline QWaylandPointerEvent(Type t, ulong ts, const QPointF &l, const QPointF &g, const QPoint &pd, const QPoint &ad, Qt::KeyboardModifiers m) |
| 293 |
: type(t) |
| 294 |
, timestamp(ts) |
| 295 |
, local(l) |
| 296 |
, global(g) |
| 297 |
, modifiers(m) |
| 298 |
, pixelDelta(pd) |
| 299 |
, angleDelta(ad) |
| 300 |
{} |
| 301 |
|
| 302 |
Type type; |
| 303 |
ulong timestamp; |
| 304 |
QPointF local; |
| 305 |
QPointF global; |
| 306 |
Qt::MouseButtons buttons; |
| 307 |
Qt::KeyboardModifiers modifiers; |
| 308 |
QPoint pixelDelta; |
| 309 |
QPoint angleDelta; |
| 310 |
}; |
| 311 |
|
| 312 |
} |
| 313 |
|
| 314 |
QT_END_NAMESPACE |
| 315 |
|
| 316 |
#endif |