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

KDE's Doxygen guidelines are available online.