1
/* $Xorg: XExtToWire.c,v 1.4 2001/02/09 02:03:50 xorgcvs Exp $ */
3
/************************************************************
5
Copyright 1989, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
27
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Hewlett-Packard not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
********************************************************/
48
/* $XFree86: xc/lib/Xi/XExtToWire.c,v 3.6 2002/10/16 12:56:28 tsi Exp $ */
50
/****************************************************************
52
* XExtToWire.c - reformat an XEvent into a wire event.
58
#include <X11/extensions/XIproto.h>
59
#include <X11/Xlibint.h>
60
#include <X11/extensions/XInput.h>
61
#include <X11/extensions/extutil.h>
65
_XiEventToWire(dpy, re, event, count)
66
register Display *dpy; /* pointer to display structure */
67
register XEvent *re; /* pointer to client event */
68
register xEvent **event; /* wire protocol event */
71
XExtDisplayInfo *info = XInput_find_display (dpy);
74
switch ((re->type & 0x7f) - info->codes->first_event)
76
case XI_DeviceKeyPress:
77
case XI_DeviceKeyRelease:
79
register XDeviceKeyEvent *ev = (XDeviceKeyEvent*) re;
80
register deviceKeyButtonPointer *kev;
81
register deviceValuator *vev;
84
kev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
86
return(_XUnknownNativeEvent(dpy, re, *event));
87
*event = (xEvent *) kev;
91
kev->event = ev->window;
92
kev->child = ev->subwindow;
94
kev->event_x = ev->x ;
95
kev->event_y = ev->y ;
96
kev->root_x = ev->x_root;
97
kev->root_y = ev->y_root;
98
kev->state = ev->state;
99
kev->same_screen = ev->same_screen;
100
kev->detail = ev->keycode;
101
kev->deviceid = ev->deviceid | MORE_EVENTS;
103
vev = (deviceValuator *) ++kev;
104
vev->type = info->codes->first_event + XI_DeviceValuator;
105
vev->deviceid = ev->deviceid;
106
vev->device_state = ev->device_state;
107
vev->first_valuator = ev->first_axis;
108
vev->num_valuators = ev->axes_count;
109
i = vev->num_valuators;
113
case 6: vev->valuator5 = ev->axis_data[5];
114
case 5: vev->valuator4 = ev->axis_data[4];
115
case 4: vev->valuator3 = ev->axis_data[3];
116
case 3: vev->valuator2 = ev->axis_data[2];
117
case 2: vev->valuator1 = ev->axis_data[1];
118
case 1: vev->valuator0 = ev->axis_data[0];
123
case XI_ProximityOut:
125
register XProximityNotifyEvent *ev =
126
(XProximityNotifyEvent *) re;
127
register deviceKeyButtonPointer *pev;
128
register deviceValuator *vev;
131
pev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
133
return(_XUnknownNativeEvent(dpy, re, *event));
134
*event = (xEvent *) pev;
136
pev->type = ev->type;
137
pev->root = ev->root;
138
pev->event = ev->window;
139
pev->child = ev->subwindow;
140
pev->time = ev->time;
141
pev->event_x = ev->x ;
142
pev->event_y = ev->y ;
143
pev->root_x = ev->x_root;
144
pev->root_y = ev->y_root;
145
pev->state = ev->state;
146
pev->same_screen = ev->same_screen;
147
pev->deviceid = ev->deviceid | MORE_EVENTS;
149
vev = (deviceValuator *) ++pev;
150
vev->type = info->codes->first_event + XI_DeviceValuator;
151
vev->deviceid = ev->deviceid;
152
vev->device_state = ev->device_state;
153
vev->first_valuator = ev->first_axis;
154
vev->num_valuators = ev->axes_count;
156
i = vev->num_valuators;
160
case 6: vev->valuator5 = ev->axis_data[5];
161
case 5: vev->valuator4 = ev->axis_data[4];
162
case 4: vev->valuator3 = ev->axis_data[3];
163
case 3: vev->valuator2 = ev->axis_data[2];
164
case 2: vev->valuator1 = ev->axis_data[1];
165
case 1: vev->valuator0 = ev->axis_data[0];
169
case XI_DeviceButtonPress:
170
case XI_DeviceButtonRelease:
172
register XDeviceButtonEvent *ev =
173
(XDeviceButtonEvent *) re;
174
register deviceKeyButtonPointer *bev;
175
register deviceValuator *vev;
178
bev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
180
return(_XUnknownNativeEvent(dpy, re, *event));
181
*event = (xEvent *) bev;
183
bev->type = ev->type;
184
bev->root = ev->root;
185
bev->event = ev->window;
186
bev->child = ev->subwindow;
187
bev->time = ev->time;
188
bev->event_x = ev->x ;
189
bev->event_y = ev->y ;
190
bev->root_x = ev->x_root;
191
bev->root_y = ev->y_root;
192
bev->state = ev->state;
193
bev->same_screen = ev->same_screen;
194
bev->detail = ev->button;
195
bev->deviceid = ev->deviceid | MORE_EVENTS;
197
vev = (deviceValuator *) ++bev;
198
vev->type = info->codes->first_event + XI_DeviceValuator;
199
vev->deviceid = ev->deviceid;
200
vev->device_state = ev->device_state;
201
vev->first_valuator = ev->first_axis;
202
vev->num_valuators = ev->axes_count;
204
i = vev->num_valuators;
208
case 6: vev->valuator5 = ev->axis_data[5];
209
case 5: vev->valuator4 = ev->axis_data[4];
210
case 4: vev->valuator3 = ev->axis_data[3];
211
case 3: vev->valuator2 = ev->axis_data[2];
212
case 2: vev->valuator1 = ev->axis_data[1];
213
case 1: vev->valuator0 = ev->axis_data[0];
217
case XI_DeviceMotionNotify:
219
register XDeviceMotionEvent *ev =
220
(XDeviceMotionEvent *)re;
221
register deviceKeyButtonPointer *mev;
222
register deviceValuator *vev;
225
mev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
227
return(_XUnknownNativeEvent(dpy, re, *event));
228
*event = (xEvent *) mev;
230
mev->type = ev->type;
231
mev->root = ev->root;
232
mev->event = ev->window;
233
mev->child = ev->subwindow;
234
mev->time = ev->time;
235
mev->event_x = ev->x ;
236
mev->event_y = ev->y ;
237
mev->root_x = ev->x_root;
238
mev->root_y = ev->y_root;
239
mev->state = ev->state;
240
mev->same_screen = ev->same_screen;
241
mev->detail = ev->is_hint;
242
mev->deviceid = ev->deviceid | MORE_EVENTS;
244
vev = (deviceValuator *) ++mev;
245
vev->type = info->codes->first_event + XI_DeviceValuator;
246
vev->deviceid = ev->deviceid;
247
vev->device_state = ev->device_state;
248
vev->first_valuator = ev->first_axis;
249
vev->num_valuators = ev->axes_count;
251
i = vev->num_valuators;
255
case 6: vev->valuator5 = ev->axis_data[5];
256
case 5: vev->valuator4 = ev->axis_data[4];
257
case 4: vev->valuator3 = ev->axis_data[3];
258
case 3: vev->valuator2 = ev->axis_data[2];
259
case 2: vev->valuator1 = ev->axis_data[1];
260
case 1: vev->valuator0 = ev->axis_data[0];
264
case XI_DeviceFocusIn:
265
case XI_DeviceFocusOut:
267
register XDeviceFocusChangeEvent *ev =
268
(XDeviceFocusChangeEvent *) re;
269
register deviceFocus *fev;
272
fev = (deviceFocus *) Xmalloc (*count * sizeof (xEvent));
274
return(_XUnknownNativeEvent(dpy, re, *event));
275
*event = (xEvent *) fev;
277
fev->type = ev->type;
278
fev->window = ev->window;
279
fev->mode = ev->mode;
280
fev->detail = ev->detail;
281
fev->time = ev->time;
282
fev->deviceid = ev->deviceid;
285
case XI_DeviceMappingNotify:
287
register XDeviceMappingEvent *ev = (XDeviceMappingEvent *) re;
288
register deviceMappingNotify *mev;
291
mev = (deviceMappingNotify *) Xmalloc (*count * sizeof (xEvent));
293
return(_XUnknownNativeEvent(dpy, re, *event));
294
*event = (xEvent *) mev;
296
mev->type = ev->type;
297
mev->firstKeyCode = ev->first_keycode;
298
mev->request = ev->request;
299
mev->count = ev->count;
300
mev->time = ev->time;
301
mev->deviceid = ev->deviceid;
304
case XI_DeviceStateNotify:
306
register XDeviceStateNotifyEvent *ev =
307
(XDeviceStateNotifyEvent *) re;
308
register deviceStateNotify *sev;
309
register xEvent *tev;
310
XInputClass *any = (XInputClass *) &ev->data[0];
311
unsigned char *sav_id;
314
for (i=0; i<ev->num_classes; i++)
316
if (any->class == KeyClass)
318
XKeyStatus *k = (XKeyStatus *) any;
319
if (k->num_keys > 32)
322
else if (any->class == ButtonClass)
324
XButtonStatus *b = (XButtonStatus *) any;
325
if (b->num_buttons > 32)
328
else if (any->class == ValuatorClass)
330
XValuatorStatus *v = (XValuatorStatus *) any;
331
if (v->num_valuators > 3)
334
any = (XInputClass *) ((char *) any + any->length);
337
sev = (deviceStateNotify *) Xmalloc (*count * sizeof (xEvent));
339
return(_XUnknownNativeEvent(dpy, re, *event));
340
*event = (xEvent *) sev;
341
tev = (xEvent *) (sev+1);
343
sev->type = ev->type;
344
sev->deviceid = ev->deviceid;
345
sav_id = &(sev->deviceid);
346
sev->time = ev->time;
347
sev->classes_reported = 0;
349
any = (XInputClass *) &ev->data[0];
350
for (i=0; i<ev->num_classes; i++)
352
if (any->class == KeyClass)
354
XKeyStatus *k = (XKeyStatus *) any;
355
register deviceKeyStateNotify *kev;
357
sev->classes_reported |= (1 << KeyClass);
358
sev->num_keys = k->num_keys;
359
memcpy ((char *) (sev->keys), (char *) (k->keys), 4);
360
if (k->num_keys > 32)
362
kev = (deviceKeyStateNotify *) tev++;
363
kev->type = info->codes->first_event +
364
XI_DeviceKeystateNotify;
365
kev->deviceid = ev->deviceid;
366
*sav_id |= MORE_EVENTS;
367
sav_id = &(kev->deviceid);
368
memcpy ((char *) (kev->keys), (char *) (&k->keys[4]),
372
else if (any->class == ButtonClass)
374
XButtonStatus *b = (XButtonStatus *) any;
375
register deviceButtonStateNotify *bev;
377
sev->classes_reported |= (1 << ButtonClass);
378
sev->num_buttons = b->num_buttons;
379
memcpy ((char *) (sev->buttons), (char *) (b->buttons), 4);
380
if (b->num_buttons > 32)
382
bev = (deviceButtonStateNotify *) tev++;
383
bev->type = info->codes->first_event +
384
XI_DeviceButtonstateNotify;
385
bev->deviceid = ev->deviceid;
386
*sav_id |= MORE_EVENTS;
387
sav_id = &(bev->deviceid);
388
memcpy ((char *)(bev->buttons), (char *)(&b->buttons[4]),
392
else if (any->class == ValuatorClass)
394
XValuatorStatus *val = (XValuatorStatus *) any;
395
register deviceValuator *vev;
397
sev->classes_reported |= (1 << ValuatorClass);
398
sev->num_valuators = val->num_valuators < 3 ?
399
val->num_valuators : 3;
400
switch (sev->num_valuators)
402
case 3: sev->valuator2 = val->valuators[2];
403
case 2: sev->valuator1 = val->valuators[1];
404
case 1: sev->valuator0 = val->valuators[0];
406
if (val->num_valuators > 3)
408
vev = (deviceValuator *) tev++;
409
vev->type = info->codes->first_event +
411
vev->deviceid = ev->deviceid;
412
vev->first_valuator = 3;
413
vev->num_valuators = val->num_valuators - 3;
414
*sav_id |= MORE_EVENTS;
415
sav_id = &(vev->deviceid);
416
i = val->num_valuators;
420
case 6: vev->valuator2 = val->valuators[5];
421
case 5: vev->valuator1 = val->valuators[4];
422
case 4: vev->valuator0 = val->valuators[3];
426
any = (XInputClass *) ((char *) any + any->length);
430
case XI_ChangeDeviceNotify:
432
register XChangeDeviceNotifyEvent *ev =
433
(XChangeDeviceNotifyEvent *) re;
434
register changeDeviceNotify *cev;
437
cev = (changeDeviceNotify *) Xmalloc (*count * sizeof (xEvent));
439
return(_XUnknownNativeEvent(dpy, re, *event));
440
*event = (xEvent *) cev;
442
cev->type = ev->type;
443
cev->request = ev->request;
444
cev->time = ev->time;
445
cev->deviceid = ev->deviceid;
449
return(_XUnknownNativeEvent(dpy, re, *event));