1/*
2 SPDX-FileCopyrightText: 2015 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 KWAYLAND_FAKEINPUT_H
7#define KWAYLAND_FAKEINPUT_H
8
9#include <QObject>
10
11#include "KWayland/Client/kwaylandclient_export.h"
12
13struct org_kde_kwin_fake_input;
14
15namespace KWayland
16{
17namespace Client
18{
19class EventQueue;
20
21/**
22 * @short Wrapper for the org_kde_kwin_fake_input interface.
23 *
24 * FakeInput allows to fake input events into the Wayland server. This is a privileged
25 * Wayland interface and the Wayland server is allowed to ignore all events.
26 *
27 * This class provides a convenient wrapper for the org_kde_kwin_fake_input interface.
28 *
29 * To use this class one needs to interact with the Registry. There are two
30 * possible ways to create the FakeInput interface:
31 * @code
32 * FakeInput *m = registry->createFakeInput(name, version);
33 * @endcode
34 *
35 * This creates the FakeInput and sets it up directly. As an alternative this
36 * can also be done in a more low level way:
37 * @code
38 * FakeInput *m = new FakeInput;
39 * m->setup(registry->bindFakeInput(name, version));
40 * @endcode
41 *
42 * The FakeInput can be used as a drop-in replacement for any org_kde_kwin_fake_input
43 * pointer as it provides matching cast operators.
44 *
45 * @see Registry
46 **/
47class KWAYLANDCLIENT_EXPORT FakeInput : public QObject
48{
49 Q_OBJECT
50public:
51 /**
52 * Creates a new FakeInput.
53 * Note: after constructing the FakeInput it is not yet valid and one needs
54 * to call setup. In order to get a ready to use FakeInput prefer using
55 * Registry::createFakeInput.
56 **/
57 explicit FakeInput(QObject *parent = nullptr);
58 ~FakeInput() override;
59
60 /**
61 * @returns @c true if managing a org_kde_kwin_fake_input.
62 **/
63 bool isValid() const;
64 /**
65 * Setup this FakeInput to manage the @p manager.
66 * When using Registry::createFakeInput there is no need to call this
67 * method.
68 **/
69 void setup(org_kde_kwin_fake_input *manager);
70 /**
71 * Releases the org_kde_kwin_fake_input interface.
72 * After the interface has been released the FakeInput instance is no
73 * longer valid and can be setup with another org_kde_kwin_fake_input interface.
74 **/
75 void release();
76 /**
77 * Destroys the data held by this FakeInput.
78 * This method is supposed to be used when the connection to the Wayland
79 * server goes away. If the connection is not valid anymore, it's not
80 * possible to call release anymore as that calls into the Wayland
81 * connection and the call would fail. This method cleans up the data, so
82 * that the instance can be deleted or set up to a new org_kde_kwin_fake_input interface
83 * once there is a new connection available.
84 *
85 * This method is automatically invoked when the Registry which created this
86 * FakeInput gets destroyed.
87 *
88 * @see release
89 **/
90 void destroy();
91
92 /**
93 * Sets the @p queue to use for bound proxies.
94 **/
95 void setEventQueue(EventQueue *queue);
96 /**
97 * @returns The event queue to use for bound proxies.
98 **/
99 EventQueue *eventQueue();
100
101 /**
102 * Authenticate with the Wayland server in order to request sending fake input events.
103 * The Wayland server might ignore all requests without a prior authentication.
104 *
105 * The Wayland server might use the provided @p applicationName and @p reason to ask
106 * the user whether this request should get authenticated.
107 *
108 * There is no way for the client to figure out whether the authentication was granted
109 * or denied. The client should assume that it wasn't granted.
110 *
111 * @param applicationName A human readable description of the application
112 * @param reason A human readable explanation why this application wants to send fake requests
113 **/
114 void authenticate(const QString &applicationName, const QString &reason);
115 /**
116 * Request a relative pointer motion of @p delta pixels.
117 **/
118 void requestPointerMove(const QSizeF &delta);
119 /**
120 * Request an absolute pointer motion to @p pos position.
121 *
122 * @since 5.54
123 **/
124 void requestPointerMoveAbsolute(const QPointF &pos);
125 /**
126 * Convenience overload.
127 * @see requestPointerButtonPress(quint32)
128 **/
129 void requestPointerButtonPress(Qt::MouseButton button);
130 /**
131 * Request a pointer button press.
132 * @param linuxButton The button code as defined in linux/input-event-codes.h
133 **/
134 void requestPointerButtonPress(quint32 linuxButton);
135 /**
136 * Convenience overload.
137 * @see requestPointerButtonRelease(quint32)
138 **/
139 void requestPointerButtonRelease(Qt::MouseButton button);
140 /**
141 * Request a pointer button release.
142 * @param linuxButton The button code as defined in linux/input-event-codes.h
143 **/
144 void requestPointerButtonRelease(quint32 linuxButton);
145 /**
146 * Convenience overload.
147 * @see requestPointerButtonClick(quint32)
148 **/
149 void requestPointerButtonClick(Qt::MouseButton button);
150 /**
151 * Requests a pointer button click, that is a press directly followed by a release.
152 * @param linuxButton The button code as defined in linux/input-event-codes.h
153 **/
154 void requestPointerButtonClick(quint32 linuxButton);
155 /**
156 * Request a scroll of the pointer @p axis with @p delta.
157 **/
158 void requestPointerAxis(Qt::Orientation axis, qreal delta);
159 /**
160 * Request a touch down at @p pos in global coordinates.
161 *
162 * If this is the first touch down it starts a touch sequence.
163 * @param id The id to identify the touch point
164 * @param pos The global position of the touch point
165 * @see requestTouchMotion
166 * @see requestTouchUp
167 * @since 5.23
168 **/
169 void requestTouchDown(quint32 id, const QPointF &pos);
170 /**
171 * Request a move of the touch point identified by @p id to new global @p pos.
172 * @param id The id to identify the touch point
173 * @param pos The global position of the touch point
174 * @see requestTouchDown
175 * @since 5.23
176 **/
177 void requestTouchMotion(quint32 id, const QPointF &pos);
178 /**
179 * Requests a touch up of the touch point identified by @p id.
180 * @param id The id to identify the touch point
181 * @since 5.23
182 **/
183 void requestTouchUp(quint32 id);
184 /**
185 * Requests to cancel the current touch event sequence.
186 * @since 5.23
187 **/
188 void requestTouchCancel();
189 /**
190 * Requests a touch frame. This allows to manipulate multiple touch points in one
191 * event and notify that the set of touch events for the current frame are finished.
192 * @since 5.23
193 **/
194 void requestTouchFrame();
195
196 /**
197 * Request a keyboard key press.
198 * @param linuxButton The button code as defined in linux/input-event-codes.h
199 *
200 * @since 5.63
201 **/
202 void requestKeyboardKeyPress(quint32 linuxKey);
203 /**
204 * Request a keyboard button release.
205 * @param linuxButton The button code as defined in linux/input-event-codes.h
206 *
207 * @since 5.63
208 **/
209 void requestKeyboardKeyRelease(quint32 linuxKey);
210
211 operator org_kde_kwin_fake_input *();
212 operator org_kde_kwin_fake_input *() const;
213
214Q_SIGNALS:
215 /**
216 * The corresponding global for this interface on the Registry got removed.
217 *
218 * This signal gets only emitted if the Compositor got created by
219 * Registry::createFakeInput
220 *
221 * @since 5.5
222 **/
223 void removed();
224
225private:
226 class Private;
227 QScopedPointer<Private> d;
228};
229
230}
231}
232
233#endif
234

source code of kwayland/src/client/fakeinput.h