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

KDE's Doxygen guidelines are available online.