1 | /* |
2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #ifndef WAYLAND_SEAT_H |
7 | #define WAYLAND_SEAT_H |
8 | |
9 | #include <QObject> |
10 | |
11 | #include "KWayland/Client/kwaylandclient_export.h" |
12 | |
13 | struct wl_seat; |
14 | struct wl_touch; |
15 | |
16 | namespace KWayland |
17 | { |
18 | namespace Client |
19 | { |
20 | class EventQueue; |
21 | class Keyboard; |
22 | class Pointer; |
23 | class Touch; |
24 | |
25 | /** |
26 | * @short Wrapper for the wl_seat interface. |
27 | * |
28 | * This class provides a convenient wrapper for the wl_seat interface. |
29 | * It's main purpose is to provide the interfaces for Keyboard, Pointer and Touch. |
30 | * |
31 | * To use this class one needs to interact with the Registry. There are two |
32 | * possible ways to create the Seat interface: |
33 | * @code |
34 | * Seat *s = registry->createSeat(name, version); |
35 | * @endcode |
36 | * |
37 | * This creates the Seat and sets it up directly. As an alternative this |
38 | * can also be done in a more low level way: |
39 | * @code |
40 | * Seat *s = new Seat; |
41 | * s->setup(registry->bindSeat(name, version)); |
42 | * @endcode |
43 | * |
44 | * The Seat can be used as a drop-in replacement for any wl_seat |
45 | * pointer as it provides matching cast operators. |
46 | * |
47 | * @see Registry |
48 | * @see Keyboard |
49 | * @see Pointer |
50 | **/ |
51 | class KWAYLANDCLIENT_EXPORT Seat : public QObject |
52 | { |
53 | Q_OBJECT |
54 | /** |
55 | * The seat has pointer devices. Default value is @c false. |
56 | **/ |
57 | Q_PROPERTY(bool keyboard READ hasKeyboard NOTIFY hasKeyboardChanged) |
58 | /** |
59 | * The seat has pointer devices. Default value is @c false. |
60 | **/ |
61 | Q_PROPERTY(bool pointer READ hasPointer NOTIFY hasPointerChanged) |
62 | /** |
63 | * The seat has touch devices. Default value is @c false. |
64 | **/ |
65 | Q_PROPERTY(bool touch READ hasTouch NOTIFY hasTouchChanged) |
66 | /** |
67 | * In a multiseat configuration this can be used by the client to help identify |
68 | * which physical devices the seat represents. |
69 | * Based on the seat configuration used by the compositor. |
70 | **/ |
71 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
72 | public: |
73 | explicit Seat(QObject *parent = nullptr); |
74 | ~Seat() override; |
75 | |
76 | /** |
77 | * @returns @c true if managing a wl_seat. |
78 | **/ |
79 | bool isValid() const; |
80 | /** |
81 | * Setup this Seat to manage the @p seat. |
82 | * When using Registry::createSeat there is no need to call this |
83 | * method. |
84 | **/ |
85 | void setup(wl_seat *seat); |
86 | /** |
87 | * Releases the wl_seat interface. |
88 | * After the interface has been released the Seat instance is no |
89 | * longer valid and can be setup with another wl_seat interface. |
90 | * |
91 | * Right before the interface is released the signal interfaceAboutToBeReleased is emitted. |
92 | * @see interfaceAboutToBeReleased |
93 | **/ |
94 | void release(); |
95 | /** |
96 | * Destroys the data held by this Seat. |
97 | * This method is supposed to be used when the connection to the Wayland |
98 | * server goes away. If the connection is not valid anymore, it's not |
99 | * possible to call release anymore as that calls into the Wayland |
100 | * connection and the call would fail. This method cleans up the data, so |
101 | * that the instance can be deleted or set up to a new wl_shell interface |
102 | * once there is a new connection available. |
103 | * |
104 | * This method is automatically invoked when the Registry which created this |
105 | * Seat gets destroyed. |
106 | * |
107 | * Right before the data is destroyed the signal interfaceAboutToBeDestroyed is emitted. |
108 | * |
109 | * @see release |
110 | * @see interfaceAboutToBeDestroyed |
111 | **/ |
112 | void destroy(); |
113 | |
114 | /** |
115 | * Sets the @p queue to use for creating Keyboard, Pointer and Touch. |
116 | **/ |
117 | void setEventQueue(EventQueue *queue); |
118 | /** |
119 | * @returns The event queue to use for creating Keyboard, Pointer and Touch. |
120 | **/ |
121 | EventQueue *eventQueue(); |
122 | |
123 | bool hasKeyboard() const; |
124 | bool hasPointer() const; |
125 | bool hasTouch() const; |
126 | QString name() const; |
127 | operator wl_seat *(); |
128 | operator wl_seat *() const; |
129 | |
130 | /** |
131 | * Creates a Keyboard. |
132 | * |
133 | * This method may only be called if the Seat has a keyboard. |
134 | * |
135 | * @param parent The parent to pass to the created Keyboard. |
136 | * @returns The created Keyboard. |
137 | **/ |
138 | Keyboard *createKeyboard(QObject *parent = nullptr); |
139 | /** |
140 | * Creates a Pointer. |
141 | * |
142 | * This method may only be called if the Seat has a pointer. |
143 | * |
144 | * @param parent The parent to pass to the created Pointer. |
145 | * @returns The created Pointer. |
146 | **/ |
147 | Pointer *createPointer(QObject *parent = nullptr); |
148 | /** |
149 | * Creates a Touch. |
150 | * |
151 | * This method may only be called if the Seat has touch support. |
152 | * |
153 | * @param parent The parent to pass to the created Touch. |
154 | * @returns The created Touch. |
155 | **/ |
156 | Touch *createTouch(QObject *parent = nullptr); |
157 | |
158 | Q_SIGNALS: |
159 | void hasKeyboardChanged(bool); |
160 | void hasPointerChanged(bool); |
161 | void hasTouchChanged(bool); |
162 | void nameChanged(const QString &name); |
163 | |
164 | /** |
165 | * This signal is emitted right before the interface is going to be released. |
166 | **/ |
167 | void interfaceAboutToBeReleased(); |
168 | /** |
169 | * This signal is emitted right before the data is going to be destroyed. |
170 | **/ |
171 | void interfaceAboutToBeDestroyed(); |
172 | |
173 | /** |
174 | * The corresponding global for this interface on the Registry got removed. |
175 | * |
176 | * This signal gets only emitted if the Compositor got created by |
177 | * Registry::createSeat |
178 | * |
179 | * @since 5.5 |
180 | **/ |
181 | void removed(); |
182 | |
183 | private: |
184 | class Private; |
185 | QScopedPointer<Private> d; |
186 | }; |
187 | |
188 | } |
189 | } |
190 | |
191 | #endif |
192 | |