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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include <QWindowSystemInterface>
#include "qwaylandintegration.h"
#include "qwaylandwindowsurface.h"
#include "qfontconfigdatabase.h"
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/QPlatformWindow>
#include <unistd.h>
#include <fcntl.h>
class QWaylandInputDevice {
public:
QWaylandInputDevice(struct wl_display *display, uint32_t id);
private:
struct wl_display *mDisplay;
struct wl_input_device *mInputDevice;
struct wl_surface *mPointerFocus;
struct wl_surface *mKeyboardFocus;
static const struct wl_input_device_listener inputDeviceListener;
Qt::MouseButtons mButtons;
QPoint mSurfacePos;
QPoint mGlobalPos;
static void inputHandleMotion(void *data,
struct wl_input_device *input_device,
uint32_t time,
int32_t x, int32_t y,
int32_t sx, int32_t sy);
static void inputHandleButton(void *data,
struct wl_input_device *input_device,
uint32_t time, uint32_t button, uint32_t state);
static void inputHandleKey(void *data,
struct wl_input_device *input_device,
uint32_t time, uint32_t key, uint32_t state);
static void inputHandlePointerFocus(void *data,
struct wl_input_device *input_device,
uint32_t time, struct wl_surface *surface,
int32_t x, int32_t y, int32_t sx, int32_t sy);
static void inputHandleKeyboardFocus(void *data,
struct wl_input_device *input_device,
uint32_t time,
struct wl_surface *surface,
struct wl_array *keys);
};
QWaylandInputDevice::QWaylandInputDevice(struct wl_display *display,
uint32_t id)
: mDisplay(display)
, mInputDevice(wl_input_device_create(display, id))
, mPointerFocus(NULL)
, mKeyboardFocus(NULL)
, mButtons(0)
{
wl_input_device_add_listener(mInputDevice,
&inputDeviceListener,
this);
wl_input_device_set_user_data(mInputDevice, this);
}
void QWaylandInputDevice::inputHandleMotion(void *data,
struct wl_input_device *input_device,
uint32_t time,
int32_t x, int32_t y,
int32_t surface_x, int32_t surface_y)
{
QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
QWaylandWindow *window =
(QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
inputDevice->mSurfacePos = QPoint(surface_x, surface_y);
inputDevice->mGlobalPos = QPoint(x, y);
QWindowSystemInterface::handleMouseEvent(window->widget(),
time,
inputDevice->mSurfacePos,
inputDevice->mGlobalPos,
inputDevice->mButtons);
}
void QWaylandInputDevice::inputHandleButton(void *data,
struct wl_input_device *input_device,
uint32_t time, uint32_t button, uint32_t state)
{
QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
QWaylandWindow *window =
(QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
Qt::MouseButton qt_button;
switch (button) {
case 272:
qt_button = Qt::LeftButton;
break;
case 273:
qt_button = Qt::RightButton;
break;
case 274:
qt_button = Qt::MidButton;
break;
default:
return;
}
if (state)
inputDevice->mButtons |= qt_button;
else
inputDevice->mButtons &= ~qt_button;
QWindowSystemInterface::handleMouseEvent(window->widget(),
time,
inputDevice->mSurfacePos,
inputDevice->mGlobalPos,
inputDevice->mButtons);
}
void QWaylandInputDevice::inputHandleKey(void *data,
struct wl_input_device *input_device,
uint32_t time, uint32_t key, uint32_t state)
{
}
void QWaylandInputDevice::inputHandlePointerFocus(void *data,
struct wl_input_device *input_device,
uint32_t time, struct wl_surface *surface,
int32_t x, int32_t y, int32_t sx, int32_t sy)
{
QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
QWaylandWindow *window;
if (inputDevice->mPointerFocus) {
window = (QWaylandWindow *)
wl_surface_get_user_data(inputDevice->mPointerFocus);
QWindowSystemInterface::handleLeaveEvent(window->widget());
inputDevice->mPointerFocus = NULL;
}
if (surface) {
window = (QWaylandWindow *) wl_surface_get_user_data(surface);
QWindowSystemInterface::handleEnterEvent(window->widget());
inputDevice->mPointerFocus = surface;
}
}
void QWaylandInputDevice::inputHandleKeyboardFocus(void *data,
struct wl_input_device *input_device,
uint32_t time,
struct wl_surface *surface,
struct wl_array *keys)
{
QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
QWaylandWindow *window;
if (inputDevice->mKeyboardFocus) {
window = (QWaylandWindow *)
wl_surface_get_user_data(inputDevice->mKeyboardFocus);
inputDevice->mKeyboardFocus = NULL;
}
if (surface) {
window = (QWaylandWindow *) wl_surface_get_user_data(surface);
inputDevice->mKeyboardFocus = surface;
}
}
const struct wl_input_device_listener QWaylandInputDevice::inputDeviceListener = {
QWaylandInputDevice::inputHandleMotion,
QWaylandInputDevice::inputHandleButton,
QWaylandInputDevice::inputHandleKey,
QWaylandInputDevice::inputHandlePointerFocus,
QWaylandInputDevice::inputHandleKeyboardFocus,
};
QWaylandInputDevice *
waylandInputDeviceCreate(struct wl_display *display, uint32_t id)
{
return new QWaylandInputDevice(display, id);
}
|