1 /************************************************************
3 Copyright 1989, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Hewlett-Packard not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ********************************************************/
47 /****************************************************************
49 * XExtToWire.c - reformat an XEvent into a wire event.
56 #include <X11/extensions/XIproto.h>
57 #include <X11/Xlibint.h>
58 #include <X11/extensions/XInput.h>
59 #include <X11/extensions/extutil.h>
60 #include <X11/extensions/Xge.h>
61 #include <X11/extensions/geproto.h>
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 if ((re->type & 0x7f) != GenericEvent) {
75 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;
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;
114 vev->valuator5 = ev->axis_data[5];
116 vev->valuator4 = ev->axis_data[4];
118 vev->valuator3 = ev->axis_data[3];
120 vev->valuator2 = ev->axis_data[2];
122 vev->valuator1 = ev->axis_data[1];
124 vev->valuator0 = ev->axis_data[0];
129 case XI_ProximityOut:
131 register XProximityNotifyEvent *ev = (XProximityNotifyEvent *) re;
132 register deviceKeyButtonPointer *pev;
133 register deviceValuator *vev;
136 pev = (deviceKeyButtonPointer *) Xmalloc(*count * sizeof(xEvent));
138 return (_XUnknownNativeEvent(dpy, re, *event));
139 *event = (xEvent *) pev;
141 pev->type = ev->type;
142 pev->root = ev->root;
143 pev->event = ev->window;
144 pev->child = ev->subwindow;
145 pev->time = ev->time;
146 pev->event_x = ev->x;
147 pev->event_y = ev->y;
148 pev->root_x = ev->x_root;
149 pev->root_y = ev->y_root;
150 pev->state = ev->state;
151 pev->same_screen = ev->same_screen;
152 pev->deviceid = ev->deviceid | MORE_EVENTS;
154 vev = (deviceValuator *)++ pev;
155 vev->type = info->codes->first_event + XI_DeviceValuator;
156 vev->deviceid = ev->deviceid;
157 vev->device_state = ev->device_state;
158 vev->first_valuator = ev->first_axis;
159 vev->num_valuators = ev->axes_count;
161 i = vev->num_valuators;
166 vev->valuator5 = ev->axis_data[5];
168 vev->valuator4 = ev->axis_data[4];
170 vev->valuator3 = ev->axis_data[3];
172 vev->valuator2 = ev->axis_data[2];
174 vev->valuator1 = ev->axis_data[1];
176 vev->valuator0 = ev->axis_data[0];
180 case XI_DeviceButtonPress:
181 case XI_DeviceButtonRelease:
183 register XDeviceButtonEvent *ev = (XDeviceButtonEvent *) re;
184 register deviceKeyButtonPointer *bev;
185 register deviceValuator *vev;
188 bev = (deviceKeyButtonPointer *) Xmalloc(*count * sizeof(xEvent));
190 return (_XUnknownNativeEvent(dpy, re, *event));
191 *event = (xEvent *) bev;
193 bev->type = ev->type;
194 bev->root = ev->root;
195 bev->event = ev->window;
196 bev->child = ev->subwindow;
197 bev->time = ev->time;
198 bev->event_x = ev->x;
199 bev->event_y = ev->y;
200 bev->root_x = ev->x_root;
201 bev->root_y = ev->y_root;
202 bev->state = ev->state;
203 bev->same_screen = ev->same_screen;
204 bev->detail = ev->button;
205 bev->deviceid = ev->deviceid | MORE_EVENTS;
207 vev = (deviceValuator *)++ bev;
208 vev->type = info->codes->first_event + XI_DeviceValuator;
209 vev->deviceid = ev->deviceid;
210 vev->device_state = ev->device_state;
211 vev->first_valuator = ev->first_axis;
212 vev->num_valuators = ev->axes_count;
214 i = vev->num_valuators;
219 vev->valuator5 = ev->axis_data[5];
221 vev->valuator4 = ev->axis_data[4];
223 vev->valuator3 = ev->axis_data[3];
225 vev->valuator2 = ev->axis_data[2];
227 vev->valuator1 = ev->axis_data[1];
229 vev->valuator0 = ev->axis_data[0];
233 case XI_DeviceMotionNotify:
235 register XDeviceMotionEvent *ev = (XDeviceMotionEvent *) re;
236 register deviceKeyButtonPointer *mev;
237 register deviceValuator *vev;
240 mev = (deviceKeyButtonPointer *) Xmalloc(*count * sizeof(xEvent));
242 return (_XUnknownNativeEvent(dpy, re, *event));
243 *event = (xEvent *) mev;
245 mev->type = ev->type;
246 mev->root = ev->root;
247 mev->event = ev->window;
248 mev->child = ev->subwindow;
249 mev->time = ev->time;
250 mev->event_x = ev->x;
251 mev->event_y = ev->y;
252 mev->root_x = ev->x_root;
253 mev->root_y = ev->y_root;
254 mev->state = ev->state;
255 mev->same_screen = ev->same_screen;
256 mev->detail = ev->is_hint;
257 mev->deviceid = ev->deviceid | MORE_EVENTS;
259 vev = (deviceValuator *)++ mev;
260 vev->type = info->codes->first_event + XI_DeviceValuator;
261 vev->deviceid = ev->deviceid;
262 vev->device_state = ev->device_state;
263 vev->first_valuator = ev->first_axis;
264 vev->num_valuators = ev->axes_count;
266 i = vev->num_valuators;
271 vev->valuator5 = ev->axis_data[5];
273 vev->valuator4 = ev->axis_data[4];
275 vev->valuator3 = ev->axis_data[3];
277 vev->valuator2 = ev->axis_data[2];
279 vev->valuator1 = ev->axis_data[1];
281 vev->valuator0 = ev->axis_data[0];
285 case XI_DeviceFocusIn:
286 case XI_DeviceFocusOut:
288 register XDeviceFocusChangeEvent *ev = (XDeviceFocusChangeEvent *) re;
289 register deviceFocus *fev;
292 fev = (deviceFocus *) Xmalloc(*count * sizeof(xEvent));
294 return (_XUnknownNativeEvent(dpy, re, *event));
295 *event = (xEvent *) fev;
297 fev->type = ev->type;
298 fev->window = ev->window;
299 fev->mode = ev->mode;
300 fev->detail = ev->detail;
301 fev->time = ev->time;
302 fev->deviceid = ev->deviceid;
305 case XI_DeviceMappingNotify:
307 register XDeviceMappingEvent *ev = (XDeviceMappingEvent *) re;
308 register deviceMappingNotify *mev;
311 mev = (deviceMappingNotify *) Xmalloc(*count * sizeof(xEvent));
313 return (_XUnknownNativeEvent(dpy, re, *event));
314 *event = (xEvent *) mev;
316 mev->type = ev->type;
317 mev->firstKeyCode = ev->first_keycode;
318 mev->request = ev->request;
319 mev->count = ev->count;
320 mev->time = ev->time;
321 mev->deviceid = ev->deviceid;
324 case XI_DeviceStateNotify:
326 register XDeviceStateNotifyEvent *ev = (XDeviceStateNotifyEvent *) re;
327 register deviceStateNotify *sev;
328 register xEvent *tev;
329 XInputClass *any = (XInputClass *) & ev->data[0];
330 unsigned char *sav_id;
334 for (i = 0; i < ev->num_classes; i++) {
335 if (any->class == KeyClass) {
336 XKeyStatus *k = (XKeyStatus *) any;
338 if (k->num_keys > 32)
340 } else if (any->class == ButtonClass) {
341 XButtonStatus *b = (XButtonStatus *) any;
343 if (b->num_buttons > 32)
345 } else if (any->class == ValuatorClass) {
346 XValuatorStatus *v = (XValuatorStatus *) any;
348 if (v->num_valuators > 3)
351 any = (XInputClass *) ((char *)any + any->length);
354 sev = (deviceStateNotify *) Xmalloc(*count * sizeof(xEvent));
356 return (_XUnknownNativeEvent(dpy, re, *event));
357 *event = (xEvent *) sev;
358 tev = (xEvent *) (sev + 1);
360 sev->type = ev->type;
361 sev->deviceid = ev->deviceid;
362 sav_id = &(sev->deviceid);
363 sev->time = ev->time;
364 sev->classes_reported = 0;
366 any = (XInputClass *) & ev->data[0];
367 for (i = 0; i < ev->num_classes; i++) {
368 if (any->class == KeyClass) {
369 XKeyStatus *k = (XKeyStatus *) any;
370 register deviceKeyStateNotify *kev;
372 sev->classes_reported |= (1 << KeyClass);
373 sev->num_keys = k->num_keys;
374 memcpy((char *)(sev->keys), (char *)(k->keys), 4);
375 if (k->num_keys > 32) {
376 kev = (deviceKeyStateNotify *) tev++;
377 kev->type = info->codes->first_event +
378 XI_DeviceKeystateNotify;
379 kev->deviceid = ev->deviceid;
380 *sav_id |= MORE_EVENTS;
381 sav_id = &(kev->deviceid);
382 memcpy((char *)(kev->keys), (char *)(&k->keys[4]), 28);
384 } else if (any->class == ButtonClass) {
385 XButtonStatus *b = (XButtonStatus *) any;
386 register deviceButtonStateNotify *bev;
388 sev->classes_reported |= (1 << ButtonClass);
389 sev->num_buttons = b->num_buttons;
390 memcpy((char *)(sev->buttons), (char *)(b->buttons), 4);
391 if (b->num_buttons > 32) {
392 bev = (deviceButtonStateNotify *) tev++;
393 bev->type = info->codes->first_event +
394 XI_DeviceButtonstateNotify;
395 bev->deviceid = ev->deviceid;
396 *sav_id |= MORE_EVENTS;
397 sav_id = &(bev->deviceid);
398 memcpy((char *)(bev->buttons), (char *)(&b->buttons[4]),
401 } else if (any->class == ValuatorClass) {
402 XValuatorStatus *val = (XValuatorStatus *) any;
403 register deviceValuator *vev;
405 sev->classes_reported |= (1 << ValuatorClass);
406 sev->num_valuators = val->num_valuators < 3 ?
407 val->num_valuators : 3;
408 switch (sev->num_valuators) {
410 sev->valuator2 = val->valuators[2];
412 sev->valuator1 = val->valuators[1];
414 sev->valuator0 = val->valuators[0];
416 if (val->num_valuators > 3) {
417 vev = (deviceValuator *) tev++;
418 vev->type = info->codes->first_event + XI_DeviceValuator;
419 vev->deviceid = ev->deviceid;
420 vev->first_valuator = 3;
421 vev->num_valuators = val->num_valuators - 3;
422 *sav_id |= MORE_EVENTS;
423 sav_id = &(vev->deviceid);
424 i = val->num_valuators;
429 vev->valuator2 = val->valuators[5];
431 vev->valuator1 = val->valuators[4];
433 vev->valuator0 = val->valuators[3];
437 any = (XInputClass *) ((char *)any + any->length);
441 case XI_ChangeDeviceNotify:
443 register XChangeDeviceNotifyEvent *ev = (XChangeDeviceNotifyEvent *) re;
444 register changeDeviceNotify *cev;
447 cev = (changeDeviceNotify *) Xmalloc(*count * sizeof(xEvent));
449 return (_XUnknownNativeEvent(dpy, re, *event));
450 *event = (xEvent *) cev;
452 cev->type = ev->type;
453 cev->request = ev->request;
454 cev->time = ev->time;
455 cev->deviceid = ev->deviceid;
459 return (_XUnknownNativeEvent(dpy, re, *event));
461 } else /* if type != GenericEvent */
464 switch (((XGenericEvent*)re)->evtype)
466 case XI_HierarchyChangedNotify:
468 XDeviceHierarchyChangedEvent *ev =
469 (XDeviceHierarchyChangedEvent*)re;
470 XIDeviceHierarchyEvent *dhcev;
472 dhcev = (XIDeviceHierarchyEvent *)Xmalloc(*count * sizeof(xEvent));
474 return (_XUnknownNativeEvent(dpy, re, *event));
476 *event = (xEvent *) dhcev;
477 dhcev->type = ev->type;
478 dhcev->time = ev->time;
482 return (_XUnknownNativeEvent(dpy, re, *event));