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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */
#include <string.h>
#include "Ecore.h"
#include "ecore_x_private.h"
#include "Ecore_X.h"
#ifdef ECORE_XI2
#include "Ecore_Input.h"
#endif /* ifdef ECORE_XI2 */
int _ecore_x_xi2_opcode = -1;
#ifndef XIPointerEmulated
#define XIPointerEmulated (1 << 16)
#endif
#ifdef ECORE_XI2
static XIDeviceInfo *_ecore_x_xi2_devs = NULL;
static int _ecore_x_xi2_num = 0;
#endif /* ifdef ECORE_XI2 */
void
_ecore_x_input_init(void)
{
#ifdef ECORE_XI2
int event, error;
int major = 2, minor = 0;
if (!XQueryExtension(_ecore_x_disp, "XInputExtension",
&_ecore_x_xi2_opcode, &event, &error))
{
_ecore_x_xi2_opcode = -1;
return;
}
if (XIQueryVersion(_ecore_x_disp, &major, &minor) == BadRequest)
{
_ecore_x_xi2_opcode = -1;
return;
}
_ecore_x_xi2_devs = XIQueryDevice(_ecore_x_disp, XIAllDevices,
&_ecore_x_xi2_num);
#endif /* ifdef ECORE_XI2 */
} /* _ecore_x_input_init */
void
_ecore_x_input_shutdown(void)
{
#ifdef ECORE_XI2
if (_ecore_x_xi2_devs)
{
XIFreeDeviceInfo(_ecore_x_xi2_devs);
_ecore_x_xi2_devs = NULL;
}
_ecore_x_xi2_num = 0;
_ecore_x_xi2_opcode = -1;
#endif /* ifdef ECORE_XI2 */
} /* _ecore_x_input_shutdown */
void
_ecore_x_input_handler(XEvent *xevent)
{
#ifdef ECORE_XI2
XIDeviceEvent *evd = (XIDeviceEvent *)(xevent->xcookie.data);
int devid = evd->deviceid;
int i;
if (_ecore_x_xi2_devs)
{
for (i = 0; i < _ecore_x_xi2_num; i++)
{
XIDeviceInfo *dev = &(_ecore_x_xi2_devs[i]);
if (devid == dev->deviceid)
{
if (dev->use == XIMasterPointer) return;
if ((dev->use == XISlavePointer) &&
(evd->flags & XIPointerEmulated)) return;
}
}
}
switch (xevent->xcookie.evtype)
{
case XI_Motion:
_ecore_mouse_move
(evd->time,
0, // state
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
case XI_ButtonPress:
_ecore_mouse_button
(ECORE_EVENT_MOUSE_BUTTON_DOWN,
evd->time,
0, // state
0, // button
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
case XI_ButtonRelease:
_ecore_mouse_button
(ECORE_EVENT_MOUSE_BUTTON_UP,
evd->time,
0, // state
0, // button
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
#ifdef XI_TouchUpdate
case XI_TouchUpdate:
_ecore_mouse_move
(evd->time,
0, // state
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
#endif
#ifdef XI_TouchBegin
case XI_TouchBegin:
_ecore_mouse_button
(ECORE_EVENT_MOUSE_BUTTON_DOWN,
evd->time,
0, // state
0, // button
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
#endif
#ifdef XI_TouchEnd
case XI_TouchEnd:
_ecore_mouse_button
(ECORE_EVENT_MOUSE_BUTTON_UP,
evd->time,
0, // state
0, // button
evd->event_x, evd->event_y,
evd->root_x, evd->root_y,
evd->event,
(evd->child ? evd->child : evd->event),
evd->root,
1, // same_screen
devid, 1, 1,
1.0, // pressure
0.0, // angle
evd->event_x, evd->event_y,
evd->root_x, evd->root_y);
break;
#endif
default:
break;
} /* switch */
#endif /* ifdef ECORE_XI2 */
} /* _ecore_x_input_handler */
EAPI Eina_Bool
ecore_x_input_multi_select(Ecore_X_Window win)
{
#ifdef ECORE_XI2
int i;
Eina_Bool find = EINA_FALSE;
if (!_ecore_x_xi2_devs)
return 0;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
for (i = 0; i < _ecore_x_xi2_num; i++)
{
XIDeviceInfo *dev = &(_ecore_x_xi2_devs[i]);
if (dev->use == XIFloatingSlave)
{
XIEventMask eventmask;
unsigned char mask[4] = { 0 };
eventmask.deviceid = dev->deviceid;
eventmask.mask_len = sizeof(mask);
eventmask.mask = mask;
XISetMask(mask, XI_ButtonPress);
XISetMask(mask, XI_ButtonRelease);
XISetMask(mask, XI_Motion);
XISelectEvents(_ecore_x_disp, win, &eventmask, 1);
find = EINA_TRUE;
}
else if (dev->use == XISlavePointer)
{
XIDeviceInfo *atdev = NULL;
int j;
for (j = 0; j < _ecore_x_xi2_num; j++)
{
if (_ecore_x_xi2_devs[j].deviceid == dev->attachment)
atdev = &(_ecore_x_xi2_devs[j]);
}
if (((atdev) && (atdev->use != XIMasterPointer)) ||
(!atdev))
{
XIEventMask eventmask;
unsigned char mask[4] = { 0 };
eventmask.deviceid = dev->deviceid;
eventmask.mask_len = sizeof(mask);
eventmask.mask = mask;
XISetMask(mask, XI_ButtonPress);
XISetMask(mask, XI_ButtonRelease);
XISetMask(mask, XI_Motion);
# ifdef XI_TouchUpdate
XISetMask(mask, XI_TouchUpdate);
# endif
# ifdef XI_TouchBegin
XISetMask(mask, XI_TouchBegin);
# endif
# ifdef XI_TouchEnd
XISetMask(mask, XI_TouchEnd);
# endif
XISelectEvents(_ecore_x_disp, win, &eventmask, 1);
find = EINA_TRUE;
}
}
}
return find;
#else /* ifdef ECORE_XI2 */
return EINA_FALSE;
#endif /* ifdef ECORE_XI2 */
} /* ecore_x_input_multi_select */
|