-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputMethodKeyboardGrabV2.cpp
57 lines (46 loc) · 1.46 KB
/
InputMethodKeyboardGrabV2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "InputMethodKeyboardGrabV2.h"
#include "X11KeyboardGrabber.h"
#include "qwayland-server-input-method-unstable-v2.h"
#include <QDateTime>
#include <QDebug>
class InputMethodKeyboardGrabV2Private : public QtWaylandServer::zwp_input_method_keyboard_grab_v2
{
public:
InputMethodKeyboardGrabV2Private(InputMethodKeyboardGrabV2 *q)
: q(q)
{
}
~InputMethodKeyboardGrabV2Private() { }
void sendKey(uint32_t key, uint32_t state)
{
uint32_t ts = QDateTime::currentSecsSinceEpoch();
const auto resources = resourceMap();
for (auto r : resources) {
send_key(r->handle, nextSerial(), ts, key, state);
}
}
protected:
virtual void zwp_input_method_keyboard_grab_v2_release(Resource *resource) override
{
wl_resource_destroy(resource->handle);
}
private:
InputMethodKeyboardGrabV2 *q;
};
InputMethodKeyboardGrabV2::InputMethodKeyboardGrabV2(struct ::wl_resource *seat, QObject *parent)
: QObject(parent)
, d(new InputMethodKeyboardGrabV2Private(this))
, m_seat(seat)
, m_grabber(new X11KeyboardGrabber(this))
{
connect(m_grabber,
&X11KeyboardGrabber::keyEvent,
this,
&InputMethodKeyboardGrabV2::onX11KeyEvent);
}
InputMethodKeyboardGrabV2::~InputMethodKeyboardGrabV2() { }
INIT_FUNCS(InputMethodKeyboardGrabV2)
void InputMethodKeyboardGrabV2::onX11KeyEvent(int keycode, bool isRelease)
{
d->sendKey(keycode, isRelease);
}