KWayland

fakeinput.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "fakeinput.h"
7 #include "event_queue.h"
8 #include "seat.h"
9 #include "wayland_pointer_p.h"
10 #include <QPointF>
11 #include <QSizeF>
12 
13 #include <linux/input.h>
14 
15 #include <wayland-fake-input-client-protocol.h>
16 
17 namespace KWayland
18 {
19 namespace Client
20 {
21 class Q_DECL_HIDDEN FakeInput::Private
22 {
23 public:
24  WaylandPointer<org_kde_kwin_fake_input, org_kde_kwin_fake_input_destroy> manager;
25  EventQueue *queue = nullptr;
26 
27  void sendPointerButtonState(Qt::MouseButton button, quint32 state);
28 };
29 
31  : QObject(parent)
32  , d(new Private)
33 {
34 }
35 
36 FakeInput::~FakeInput()
37 {
38  release();
39 }
40 
42 {
43  d->manager.release();
44 }
45 
47 {
48  d->manager.destroy();
49 }
50 
51 bool FakeInput::isValid() const
52 {
53  return d->manager.isValid();
54 }
55 
56 void FakeInput::setup(org_kde_kwin_fake_input *manager)
57 {
58  Q_ASSERT(manager);
59  Q_ASSERT(!d->manager.isValid());
60  d->manager.setup(manager);
61 }
62 
64 {
65  return d->queue;
66 }
67 
69 {
70  d->queue = queue;
71 }
72 
73 void FakeInput::authenticate(const QString &applicationName, const QString &reason)
74 {
75  Q_ASSERT(d->manager.isValid());
76  org_kde_kwin_fake_input_authenticate(d->manager, applicationName.toUtf8().constData(), reason.toUtf8().constData());
77 }
78 
80 {
81  Q_ASSERT(d->manager.isValid());
82  org_kde_kwin_fake_input_pointer_motion(d->manager, wl_fixed_from_double(delta.width()), wl_fixed_from_double(delta.height()));
83 }
84 
86 {
87  Q_ASSERT(d->manager.isValid());
88  if (wl_proxy_get_version(d->manager) < ORG_KDE_KWIN_FAKE_INPUT_POINTER_MOTION_ABSOLUTE_SINCE_VERSION) {
89  return;
90  }
91 
92  org_kde_kwin_fake_input_pointer_motion_absolute(d->manager, wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
93 }
94 
95 void FakeInput::Private::sendPointerButtonState(Qt::MouseButton button, quint32 state)
96 {
97  Q_ASSERT(manager.isValid());
98  uint32_t b = 0;
99  switch (button) {
100  case Qt::LeftButton:
101  b = BTN_LEFT;
102  break;
103  case Qt::RightButton:
104  b = BTN_RIGHT;
105  break;
106  case Qt::MiddleButton:
107  b = BTN_MIDDLE;
108  break;
109  default:
110  // TODO: more buttons, check implementation in QtWayland
111  // unsupported button
112  return;
113  }
114  org_kde_kwin_fake_input_button(manager, b, state);
115 }
116 
118 {
119  d->sendPointerButtonState(button, WL_POINTER_BUTTON_STATE_PRESSED);
120 }
121 
122 void FakeInput::requestPointerButtonPress(quint32 linuxButton)
123 {
124  Q_ASSERT(d->manager.isValid());
125  org_kde_kwin_fake_input_button(d->manager, linuxButton, WL_POINTER_BUTTON_STATE_PRESSED);
126 }
127 
129 {
130  d->sendPointerButtonState(button, WL_POINTER_BUTTON_STATE_RELEASED);
131 }
132 
133 void FakeInput::requestPointerButtonRelease(quint32 linuxButton)
134 {
135  Q_ASSERT(d->manager.isValid());
136  org_kde_kwin_fake_input_button(d->manager, linuxButton, WL_POINTER_BUTTON_STATE_RELEASED);
137 }
138 
140 {
143 }
144 
145 void FakeInput::requestPointerButtonClick(quint32 linuxButton)
146 {
147  requestPointerButtonPress(linuxButton);
148  requestPointerButtonRelease(linuxButton);
149 }
150 
152 {
153  Q_ASSERT(d->manager.isValid());
154  uint32_t a;
155  switch (axis) {
156  case Qt::Horizontal:
157  a = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
158  break;
159  case Qt::Vertical:
160  a = WL_POINTER_AXIS_VERTICAL_SCROLL;
161  break;
162  default:
163  Q_UNREACHABLE();
164  break;
165  }
166  org_kde_kwin_fake_input_axis(d->manager, a, wl_fixed_from_double(delta));
167 }
168 
169 void FakeInput::requestTouchDown(quint32 id, const QPointF &pos)
170 {
171  Q_ASSERT(d->manager.isValid());
172  org_kde_kwin_fake_input_touch_down(d->manager, id, wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
173 }
174 
175 void FakeInput::requestTouchMotion(quint32 id, const QPointF &pos)
176 {
177  Q_ASSERT(d->manager.isValid());
178  org_kde_kwin_fake_input_touch_motion(d->manager, id, wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
179 }
180 
182 {
183  Q_ASSERT(d->manager.isValid());
184  org_kde_kwin_fake_input_touch_up(d->manager, id);
185 }
186 
188 {
189  Q_ASSERT(d->manager.isValid());
190  org_kde_kwin_fake_input_touch_cancel(d->manager);
191 }
192 
194 {
195  Q_ASSERT(d->manager.isValid());
196  org_kde_kwin_fake_input_touch_frame(d->manager);
197 }
198 
200 {
201  Q_ASSERT(d->manager.isValid());
202  if (wl_proxy_get_version(d->manager) < ORG_KDE_KWIN_FAKE_INPUT_KEYBOARD_KEY_SINCE_VERSION) {
203  return;
204  }
205 
206  org_kde_kwin_fake_input_keyboard_key(d->manager, linuxKey, WL_KEYBOARD_KEY_STATE_PRESSED);
207 }
208 
210 {
211  Q_ASSERT(d->manager.isValid());
212  if (wl_proxy_get_version(d->manager) < ORG_KDE_KWIN_FAKE_INPUT_KEYBOARD_KEY_SINCE_VERSION) {
213  return;
214  }
215 
216  org_kde_kwin_fake_input_keyboard_key(d->manager, linuxKey, WL_KEYBOARD_KEY_STATE_RELEASED);
217 }
218 
219 FakeInput::operator org_kde_kwin_fake_input *() const
220 {
221  return d->manager;
222 }
223 
224 FakeInput::operator org_kde_kwin_fake_input *()
225 {
226  return d->manager;
227 }
228 
229 }
230 }
void requestKeyboardKeyPress(quint32 linuxKey)
Request a keyboard key press.
Definition: fakeinput.cpp:199
void authenticate(const QString &applicationName, const QString &reason)
Authenticate with the Wayland server in order to request sending fake input events.
Definition: fakeinput.cpp:73
qreal height() const const
void setEventQueue(EventQueue *queue)
Sets the queue to use for bound proxies.
Definition: fakeinput.cpp:68
void requestTouchUp(quint32 id)
Requests a touch up of the touch point identified by id.
Definition: fakeinput.cpp:181
void requestPointerButtonRelease(Qt::MouseButton button)
Convenience overload.
Definition: fakeinput.cpp:128
MouseButton
void destroy()
Destroys the data held by this FakeInput.
Definition: fakeinput.cpp:46
EventQueue * eventQueue()
Definition: fakeinput.cpp:63
void requestKeyboardKeyRelease(quint32 linuxKey)
Request a keyboard button release.
Definition: fakeinput.cpp:209
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
Orientation
QByteArray toUtf8() const const
void requestTouchDown(quint32 id, const QPointF &pos)
Request a touch down at pos in global coordinates.
Definition: fakeinput.cpp:169
void requestPointerMoveAbsolute(const QPointF &pos)
Request an absolute pointer motion to pos position.
Definition: fakeinput.cpp:85
void setup(org_kde_kwin_fake_input *manager)
Setup this FakeInput to manage the manager.
Definition: fakeinput.cpp:56
void requestPointerButtonPress(Qt::MouseButton button)
Convenience overload.
Definition: fakeinput.cpp:117
qreal x() const const
qreal y() const const
const char * constData() const const
void release()
Releases the org_kde_kwin_fake_input interface.
Definition: fakeinput.cpp:41
void requestPointerAxis(Qt::Orientation axis, qreal delta)
Request a scroll of the pointer axis with delta.
Definition: fakeinput.cpp:151
void requestTouchCancel()
Requests to cancel the current touch event sequence.
Definition: fakeinput.cpp:187
FakeInput(QObject *parent=nullptr)
Creates a new FakeInput.
Definition: fakeinput.cpp:30
void requestPointerButtonClick(Qt::MouseButton button)
Convenience overload.
Definition: fakeinput.cpp:139
void requestPointerMove(const QSizeF &delta)
Request a relative pointer motion of delta pixels.
Definition: fakeinput.cpp:79
void requestTouchFrame()
Requests a touch frame.
Definition: fakeinput.cpp:193
void requestTouchMotion(quint32 id, const QPointF &pos)
Request a move of the touch point identified by id to new global pos.
Definition: fakeinput.cpp:175
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.