1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QWAYLANDSEAT_H |
5 | #define QWAYLANDSEAT_H |
6 | |
7 | #include <QtCore/qnamespace.h> |
8 | #include <QtCore/QPoint> |
9 | #include <QtCore/QString> |
10 | |
11 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
12 | #include <QtWaylandCompositor/qtwaylandqmlinclude.h> |
13 | #include <QtWaylandCompositor/qwaylandcompositorextension.h> |
14 | #include <QtWaylandCompositor/qwaylandkeyboard.h> |
15 | #include <QtWaylandCompositor/qwaylandview.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QWaylandCompositor; |
20 | class QWaylandSurface; |
21 | class QKeyEvent; |
22 | class QTouchEvent; |
23 | class QInputEvent; |
24 | class QWaylandSeatPrivate; |
25 | class QWaylandDrag; |
26 | class QWaylandKeyboard; |
27 | class QWaylandPointer; |
28 | class QWaylandTouch; |
29 | |
30 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSeat : public QWaylandObject |
31 | { |
32 | Q_OBJECT |
33 | Q_DECLARE_PRIVATE(QWaylandSeat) |
34 | |
35 | #if QT_CONFIG(draganddrop) |
36 | Q_PROPERTY(QWaylandDrag *drag READ drag CONSTANT) |
37 | Q_MOC_INCLUDE("qwaylanddrag.h" ) |
38 | #endif |
39 | Q_PROPERTY(QWaylandKeymap *keymap READ keymap CONSTANT) |
40 | Q_MOC_INCLUDE("qwaylandkeymap.h" ) |
41 | Q_MOC_INCLUDE("qwaylandview.h" ) |
42 | |
43 | QML_NAMED_ELEMENT(WaylandSeat) |
44 | QML_ADDED_IN_VERSION(1, 0) |
45 | QML_UNCREATABLE("" ) |
46 | public: |
47 | enum CapabilityFlag { |
48 | // The order should match the enum WL_SEAT_CAPABILITY_* |
49 | Pointer = 0x01, |
50 | Keyboard = 0x02, |
51 | Touch = 0x04, |
52 | |
53 | DefaultCapabilities = Pointer | Keyboard | Touch |
54 | }; |
55 | Q_DECLARE_FLAGS(CapabilityFlags, CapabilityFlag) |
56 | Q_ENUM(CapabilityFlags) |
57 | |
58 | QWaylandSeat(QWaylandCompositor *compositor, CapabilityFlags capabilityFlags = DefaultCapabilities); |
59 | ~QWaylandSeat() override; |
60 | virtual void initialize(); |
61 | bool isInitialized() const; |
62 | |
63 | void sendMousePressEvent(Qt::MouseButton button); |
64 | void sendMouseReleaseEvent(Qt::MouseButton button); |
65 | void sendMouseMoveEvent(QWaylandView *surface , const QPointF &localPos, const QPointF &outputSpacePos = QPointF()); |
66 | void sendMouseWheelEvent(Qt::Orientation orientation, int delta); |
67 | |
68 | void sendKeyPressEvent(uint code); |
69 | void sendKeyReleaseEvent(uint code); |
70 | |
71 | void sendFullKeyEvent(QKeyEvent *event); |
72 | Q_INVOKABLE void sendKeyEvent(int qtKey, bool pressed); |
73 | |
74 | uint sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state); |
75 | Q_INVOKABLE uint sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position); |
76 | Q_INVOKABLE uint sendTouchPointReleased(QWaylandSurface *surface, int id, const QPointF &position); |
77 | Q_INVOKABLE uint sendTouchPointMoved(QWaylandSurface *surface, int id, const QPointF &position); |
78 | Q_INVOKABLE void sendTouchFrameEvent(QWaylandClient *client); |
79 | Q_INVOKABLE void sendTouchCancelEvent(QWaylandClient *client); |
80 | |
81 | void sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event); |
82 | |
83 | QWaylandPointer *pointer() const; |
84 | //Normally set by the mouse device, |
85 | //But can be set manually for use with touch or can reset unset the current mouse focus; |
86 | QWaylandView *mouseFocus() const; |
87 | void setMouseFocus(QWaylandView *view); |
88 | |
89 | QWaylandKeyboard *keyboard() const; |
90 | QWaylandSurface *keyboardFocus() const; |
91 | bool setKeyboardFocus(QWaylandSurface *surface); |
92 | QWaylandKeymap *keymap(); |
93 | |
94 | QWaylandTouch *touch() const; |
95 | |
96 | QWaylandCompositor *compositor() const; |
97 | |
98 | #if QT_CONFIG(draganddrop) |
99 | QWaylandDrag *drag() const; |
100 | #endif |
101 | |
102 | QWaylandSeat::CapabilityFlags capabilities() const; |
103 | |
104 | virtual bool isOwner(QInputEvent *inputEvent) const; |
105 | |
106 | static QWaylandSeat *fromSeatResource(struct ::wl_resource *resource); |
107 | |
108 | Q_SIGNALS: |
109 | void mouseFocusChanged(QWaylandView *newFocus, QWaylandView *oldFocus); |
110 | void keyboardFocusChanged(QWaylandSurface *newFocus, QWaylandSurface *oldFocus); |
111 | #if QT_DEPRECATED_SINCE(6, 1) |
112 | void cursorSurfaceRequest(QWaylandSurface *surface, int hotspotX, int hotspotY); |
113 | #endif |
114 | void cursorSurfaceRequested(QWaylandSurface *surface, int hotspotX, int hotspotY, QWaylandClient *client); |
115 | |
116 | private: |
117 | void handleMouseFocusDestroyed(); |
118 | }; |
119 | |
120 | Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandSeat::CapabilityFlags) |
121 | |
122 | QT_END_NAMESPACE |
123 | |
124 | #endif // QWAYLANDSEAT_H |
125 | |