1
#include "gtest_grail_backend.h"
5
Check that when a direct device (e.g. a touchscreen) is being used, the
6
position of a GeisTouch will be in window coordinates instead of input
9
This means that the x an y values of a GeisTouch should come from
10
XIDeviceEvent::event_x and XIDeviceEvent::event_y and not from
11
XIDeviceEvent::valuators.values[0] and XIDeviceEvent::valuators.values[1],
12
like it's the case for indirect devices (such as trackpads).
14
Regression test for https://bugs.launchpad.net/bugs/984069
17
class Geis2GrailBackend : public Geis2GrailBackendBase
20
Geis2GrailBackend() : _subscription(nullptr) {}
22
void SendXInput2Events();
24
virtual void OnEventInitComplete(GeisEvent event);
25
virtual void OnEventGestureBegin(GeisEvent event);
27
GeisSubscription _subscription;
30
void Geis2GrailBackend::SendXInput2Events()
33
XGenericEventCookie *xcookie = 0;
34
XIDeviceEvent *device_event = 0;
35
XITouchOwnershipEvent *ownership_event = 0;
38
event.type = GenericEvent;
39
device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
40
device_event->serial = serial++;
41
device_event->display = xmock_display;
42
device_event->extension = xmock_xi2_opcode;
43
device_event->evtype = XI_TouchBegin;
44
device_event->time = xmock_server_time;
45
device_event->deviceid = 0;
46
/* The source device that originally generated the event. */
47
device_event->sourceid = device_event->deviceid;
48
device_event->detail = 0; /* touch id */
49
device_event->root = DefaultRootWindow(xmock_display);
50
device_event->event = DefaultRootWindow(xmock_display);
51
device_event->child = 0;
52
device_event->root_x = 123.0f;
53
device_event->root_y = 456.0f;
54
device_event->event_x = device_event->root_x;
55
device_event->event_y = device_event->root_y;
56
device_event->valuators.mask_len = 2; /* two bytes */
57
device_event->valuators.mask = (unsigned char*) malloc(2);
58
XISetMask(device_event->valuators.mask, 0); /* X axis is present */
59
XISetMask(device_event->valuators.mask, 1); /* Y axis is present */
60
device_event->valuators.values = (double*) malloc(sizeof(double)*2);
61
device_event->valuators.values[0] = -200.0;
62
device_event->valuators.values[1] = -100.0;
63
xcookie = &event.xcookie;
64
xcookie->extension = xmock_xi2_opcode;
65
xcookie->evtype = XI_TouchBegin;
66
xcookie->data = device_event;
67
xmock_add_to_event_queue(&event);
69
event.type = GenericEvent;
70
device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
71
device_event->serial = serial++;
72
device_event->display = xmock_display;
73
device_event->extension = xmock_xi2_opcode;
74
device_event->evtype = XI_TouchBegin;
75
device_event->time = xmock_server_time;
76
device_event->deviceid = 0;
77
device_event->sourceid = device_event->deviceid;
78
device_event->detail = 1; /* touch id */
79
device_event->root = DefaultRootWindow(xmock_display);
80
device_event->event = DefaultRootWindow(xmock_display);
81
device_event->child = 0;
82
device_event->root_x = 222.0f;
83
device_event->root_y = 456.0f;
84
device_event->event_x = device_event->root_x;
85
device_event->event_y = device_event->root_y;
86
device_event->valuators.mask_len = 2;
87
device_event->valuators.mask = (unsigned char*) malloc(2);
88
XISetMask(device_event->valuators.mask, 0);
89
XISetMask(device_event->valuators.mask, 1);
90
device_event->valuators.values = (double*) malloc(sizeof(double)*2);
91
device_event->valuators.values[0] = -150.0;
92
device_event->valuators.values[1] = -100.0;
93
xcookie = &event.xcookie;
94
xcookie->extension = xmock_xi2_opcode;
95
xcookie->evtype = XI_TouchBegin;
96
xcookie->data = device_event;
97
xmock_add_to_event_queue(&event);
99
xmock_server_time += 5;
101
event.type = GenericEvent;
102
ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
103
ownership_event->type = GenericEvent;
104
ownership_event->serial = serial++;
105
ownership_event->display = xmock_display;
106
ownership_event->extension = xmock_xi2_opcode;
107
ownership_event->evtype = XI_TouchOwnership;
108
ownership_event->time = xmock_server_time;
109
ownership_event->deviceid = 0;
110
ownership_event->sourceid = ownership_event->deviceid;
111
ownership_event->touchid = 0;
112
ownership_event->root = DefaultRootWindow(xmock_display);
113
ownership_event->event = DefaultRootWindow(xmock_display);
114
ownership_event->child = 0;
115
xcookie = &event.xcookie;
116
xcookie->extension = xmock_xi2_opcode;
117
xcookie->evtype = XI_TouchOwnership;
118
xcookie->data = ownership_event;
119
xmock_add_to_event_queue(&event);
121
event.type = GenericEvent;
122
ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
123
ownership_event->type = GenericEvent;
124
ownership_event->serial = serial++;
125
ownership_event->display = xmock_display;
126
ownership_event->extension = xmock_xi2_opcode;
127
ownership_event->evtype = XI_TouchOwnership;
128
ownership_event->time = xmock_server_time;
129
ownership_event->deviceid = 0;
130
ownership_event->sourceid = ownership_event->deviceid;
131
ownership_event->touchid = 1;
132
ownership_event->root = DefaultRootWindow(xmock_display);
133
ownership_event->event = DefaultRootWindow(xmock_display);
134
ownership_event->child = 0;
135
xcookie = &event.xcookie;
136
xcookie->extension = xmock_xi2_opcode;
137
xcookie->evtype = XI_TouchOwnership;
138
xcookie->data = ownership_event;
139
xmock_add_to_event_queue(&event);
141
event.type = GenericEvent;
142
device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
143
device_event->serial = serial++;
144
device_event->display = xmock_display;
145
device_event->extension = xmock_xi2_opcode;
146
device_event->evtype = XI_TouchUpdate;
147
device_event->time = xmock_server_time;
148
device_event->deviceid = 0;
149
device_event->sourceid = device_event->deviceid;
150
device_event->detail = 0;
151
device_event->root = DefaultRootWindow(xmock_display);
152
device_event->event = DefaultRootWindow(xmock_display);
153
device_event->child = 0;
154
device_event->root_x = 123.0f;
155
device_event->root_y = 466.0f;
156
device_event->event_x = device_event->root_x;
157
device_event->event_y = device_event->root_y;
158
device_event->valuators.mask_len = 2; /* two bytes */
159
device_event->valuators.mask = (unsigned char*) malloc(2);
160
XISetMask(device_event->valuators.mask, 0);
161
XISetMask(device_event->valuators.mask, 1);
162
device_event->valuators.values = (double*) malloc(sizeof(double)*2);
163
device_event->valuators.values[0] = -200.0;
164
device_event->valuators.values[1] = -90.0;
165
xcookie = &event.xcookie;
166
xcookie->extension = xmock_xi2_opcode;
167
xcookie->evtype = XI_TouchUpdate;
168
xcookie->data = device_event;
169
xmock_add_to_event_queue(&event);
171
event.type = GenericEvent;
172
device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
173
device_event->serial = serial++;
174
device_event->display = xmock_display;
175
device_event->extension = xmock_xi2_opcode;
176
device_event->evtype = XI_TouchUpdate;
177
device_event->time = xmock_server_time;
178
device_event->deviceid = 0;
179
device_event->sourceid = device_event->deviceid;
180
device_event->detail = 1; /* touch id */
181
device_event->root = DefaultRootWindow(xmock_display);
182
device_event->event = DefaultRootWindow(xmock_display);
183
device_event->child = 0;
184
device_event->root_x = 222.0f;
185
device_event->root_y = 466.0f;
186
device_event->event_x = device_event->root_x;
187
device_event->event_y = device_event->root_y;
188
device_event->valuators.mask_len = 2;
189
device_event->valuators.mask = (unsigned char*) malloc(2);
190
XISetMask(device_event->valuators.mask, 0);
191
XISetMask(device_event->valuators.mask, 1);
192
device_event->valuators.values = (double*) malloc(sizeof(double)*2);
193
device_event->valuators.values[0] = -150.0;
194
device_event->valuators.values[1] = -90.0;
195
xcookie = &event.xcookie;
196
xcookie->extension = xmock_xi2_opcode;
197
xcookie->evtype = XI_TouchUpdate;
198
xcookie->data = device_event;
199
xmock_add_to_event_queue(&event);
202
void Geis2GrailBackend::OnEventInitComplete(GeisEvent event)
204
_subscription = CreateFilteredSubscription(
205
"My 2-touches Touch", 2, GEIS_GESTURE_TOUCH);
206
ASSERT_NE(nullptr, _subscription);
211
void Geis2GrailBackend::OnEventGestureBegin(GeisEvent event)
213
GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_TOUCHSET);
214
GeisTouchSet geis_touch_set = (GeisTouchSet) geis_attr_value_to_pointer(attr);
216
TouchSet touch_set(geis_touch_set);
218
/* check that there are two touch points and that they are in window coordinates
219
(instead of input device coordinates) */
220
ASSERT_EQ(2, touch_set.size());
221
ASSERT_TRUE(touch_set.contains(123.0f, 456.0f));
222
ASSERT_TRUE(touch_set.contains(222.0f, 456.0f));
225
TEST_F(Geis2GrailBackend, DirectDeviceTouchCoords)
227
CreateXMockTouchScreenDevice();
229
_geis = geis_new(GEIS_INIT_GRAIL_BACKEND,
231
ASSERT_NE(nullptr, _geis);
236
geis_subscription_delete(_subscription);
239
DestroyXMockDevices();