Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_xinput.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
41 #include <unistd.h>
42 #include <stdarg.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45
46 #include <dix.h>
47 #define XREGISTRY
48 #include <registry.h>
49 #include <xace.h>
50 #include <xacestr.h>
51 #include <X11/Xatom.h>
52 #include <X11/Xlib.h>
53 #include <windowstr.h>
54
55 #include <X11/extensions/XI.h>
56 #include <X11/extensions/XInput.h>
57 #include <X11/Xlibint.h>
58 #include <X11/extensions/XIproto.h>
59 #include <X11/extensions/XI2proto.h>
60
61 #include "xdbg_types.h"
62 #include "xdbg_evlog_xinput.h"
63 #include "xdbg_evlog.h"
64
65 static char *
66 _getMode(CARD8 mode, char *reply, int *len)
67 {
68     const char* buf;
69     char dbuf[10];
70
71     switch (mode)
72     {
73         case XIGrabModeSync:  buf = "XIGrabModeSync"; break;
74         case XIGrabModeAsync:  buf = "XIGrabModeAsync"; break;
75         case XIGrabModeTouch:  buf = "XIGrabModeTouch"; break;
76         default:  buf = dbuf; snprintf (dbuf, 10, "%d", mode); break;
77     }
78
79     REPLY ("%s", buf);
80
81     return reply;
82 }
83
84 static char *
85 _EvlogRequestXinput (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
86 {
87     xReq *req = evinfo->req.ptr;
88
89     switch (req->data)
90     {
91     case X_GrabDevice:
92         {
93             xGrabDeviceReq *stuff = (xGrabDeviceReq *)req;
94             REPLY (": XID(0x%lx) device_ID(%d)",
95                 stuff->grabWindow,
96                 stuff->deviceid);
97
98             if (detail_level >= EVLOG_PRINT_DETAIL)
99             {
100                 REPLY (" this_dev_mode");
101                 REPLY ("(");
102                 reply = _getMode(stuff->this_device_mode, reply, len);
103                 REPLY (")");
104
105                 REPLY (" other_dev_mode");
106                 REPLY ("(");
107                 reply = _getMode(stuff->other_devices_mode, reply, len);
108                 REPLY (")");
109
110                 REPLY (" time(%lums) evt_cnt(%d)  owner_events(%s)",
111                     stuff->time,
112                     stuff->event_count,
113                     stuff->ownerEvents ? "YES" : "NO");
114             }
115
116             return reply;
117         }
118
119     case X_UngrabDevice:
120         {
121             xUngrabDeviceReq *stuff = (xUngrabDeviceReq *)req;
122             REPLY (": device_ID(%d)",
123                 stuff->deviceid);
124
125             if (detail_level >= EVLOG_PRINT_DETAIL)
126             {
127                 REPLY (" time(%lums)",
128                     stuff->time);
129             }
130
131             return reply;
132         }
133
134     case X_GrabDeviceKey:
135         {
136             xGrabDeviceKeyReq *stuff = (xGrabDeviceKeyReq *)req;
137             REPLY (": XID(0x%lx)",
138                 stuff->grabWindow);
139
140             if (detail_level >= EVLOG_PRINT_DETAIL)
141             {
142                 REPLY (" evt_cnt(%d) modifiers(%d) mod_dev(%d) grab_dev(%d) key(%d)",
143                     stuff->event_count,
144                     stuff->modifiers,
145                     stuff->modifier_device,
146                     stuff->grabbed_device,
147                     stuff->key);
148
149                 REPLY ("\n");
150                 REPLY ("%67s this_dev_mode",
151                     " ");
152
153                 REPLY ("(");
154                 reply = _getMode(stuff->this_device_mode, reply, len);
155                 REPLY (")");
156
157                 REPLY (" other_dev_mode");
158                 REPLY ("(");
159                 reply = _getMode(stuff->other_devices_mode, reply, len);
160                 REPLY (")");
161
162                 REPLY (" owner_events(%s)",
163                     stuff->ownerEvents ? "YES" : "NO");
164             }
165
166             return reply;
167         }
168
169     case X_UngrabDeviceKey:
170         {
171             xUngrabDeviceKeyReq *stuff = (xUngrabDeviceKeyReq *)req;
172             REPLY (": XID(0x%lx)",
173                 stuff->grabWindow);
174
175             if (detail_level >= EVLOG_PRINT_DETAIL)
176             {
177                 REPLY (" modifiers(%d) mod_dev(%d) grab_dev(%d) key(%d)",
178                     stuff->modifiers,
179                     stuff->modifier_device,
180                     stuff->grabbed_device,
181                     stuff->key);
182             }
183
184             return reply;
185         }
186
187     case X_GrabDeviceButton:
188         {
189             xGrabDeviceButtonReq *stuff = (xGrabDeviceButtonReq *)req;
190             REPLY (": XID(0x%lx))",
191                 stuff->grabWindow);
192
193             if (detail_level >= EVLOG_PRINT_DETAIL)
194             {
195                 REPLY (" grab_dev(%d) mod_dev(%d) evt_cnt(%d) modifiers(%d) button(%d)",
196                     stuff->grabbed_device,
197                     stuff->modifier_device,
198                     stuff->event_count,
199                     stuff->modifiers,
200                     stuff->button);
201
202                 REPLY ("\n");
203                 REPLY ("%67s this_dev_mode",
204                     " ");
205                 REPLY ("(");
206                 reply = _getMode(stuff->this_device_mode, reply, len);
207                 REPLY (")");
208
209                 REPLY (" other_dev_mode");
210                 REPLY ("(");
211                 reply = _getMode(stuff->other_devices_mode, reply, len);
212                 REPLY (")");
213
214                 REPLY (" owner_events(%s)",
215                     stuff->ownerEvents ? "YES" : "NO");
216             }
217
218             return reply;
219         }
220
221     case X_UngrabDeviceButton:
222         {
223             xUngrabDeviceButtonReq *stuff = (xUngrabDeviceButtonReq *)req;
224             REPLY (": XID(0x%lx)",
225                 stuff->grabWindow);
226
227             if (detail_level >= EVLOG_PRINT_DETAIL)
228             {
229                 REPLY (" modifiers(%d) modDev(%d) grabDev(%d) button(%d)",
230                     stuff->modifiers,
231                     stuff->modifier_device,
232                     stuff->grabbed_device,
233                     stuff->button);
234             }
235
236             return reply;
237         }
238
239     case X_AllowDeviceEvents:
240         {
241             xAllowDeviceEventsReq *stuff = (xAllowDeviceEventsReq *)req;
242             REPLY (": device_ID(%d)",
243                 stuff->deviceid);
244
245             if (detail_level >= EVLOG_PRINT_DETAIL)
246             {
247                 REPLY (" time(%lums) mode(%d)",
248                 stuff->time,
249                 stuff->mode);
250             }
251
252             return reply;
253         }
254
255     case X_GetDeviceFocus:
256         {
257             xGetDeviceFocusReq *stuff = (xGetDeviceFocusReq *)req;
258             REPLY (": devID(%d)",
259                 stuff->deviceid);
260
261             return reply;
262         }
263
264     case X_SetDeviceFocus:
265         {
266             xSetDeviceFocusReq *stuff = (xSetDeviceFocusReq *)req;
267             REPLY (": XID(0x%lx) dev_ID(%d)",
268                 stuff->focus,
269                 stuff->device);
270
271             if (detail_level >= EVLOG_PRINT_DETAIL)
272             {
273                 REPLY (" time(%lums) revertTo(%d)",
274                 stuff->time,
275                 stuff->revertTo);
276             }
277
278             return reply;
279         }
280
281     case X_XIQueryPointer:
282         {
283             xXIQueryPointerReq *stuff = (xXIQueryPointerReq *)req;
284             REPLY (": XID(0x%x) devID(%d)",
285                 stuff->win,
286                 stuff->deviceid);
287
288             return reply;
289         }
290
291     case X_XIWarpPointer:
292         {
293             xXIWarpPointerReq *stuff = (xXIWarpPointerReq *)req;
294             REPLY (": srcWIN(0x%x) dstWin(0x%x) src(%d,%d %dx%d) dst(%d,%d) device_ID(%d)",
295                 stuff->src_win,
296                 stuff->dst_win,
297                 stuff->src_x,
298                 stuff->src_y,
299                 stuff->src_width,
300                 stuff->src_height,
301                 stuff->dst_x,
302                 stuff->dst_y,
303                 stuff->deviceid);
304
305             return reply;
306         }
307
308     case X_XIChangeCursor:
309         {
310             xXIChangeCursorReq *stuff = (xXIChangeCursorReq *)req;
311             REPLY (": XID(0x%x) Cursor(0x%x) devID(%d)",
312                 stuff->win,
313                 stuff->cursor,
314                 stuff->deviceid);
315
316             return reply;
317         }
318
319     case X_XIChangeHierarchy:
320         {
321             xXIChangeHierarchyReq *stuff = (xXIChangeHierarchyReq *)req;
322             REPLY (": numChange(%d)",
323                 stuff->num_changes);
324
325             return reply;
326         }
327
328     case X_XISetClientPointer:
329         {
330             xXISetClientPointerReq *stuff = (xXISetClientPointerReq *)req;
331             REPLY (": XID(0x%x) device_ID(%d)",
332                 stuff->win,
333                 stuff->deviceid);
334
335             return reply;
336         }
337
338     case X_XIGetClientPointer:
339         {
340             xXIGetClientPointerReq *stuff = (xXIGetClientPointerReq *)req;
341             REPLY (": XID(0x%x)",
342                 stuff->win);
343
344             return reply;
345         }
346
347     case X_XISelectEvents:
348         {
349             xXISelectEventsReq *stuff = (xXISelectEventsReq *)req;
350             REPLY (": XID(0x%x)",
351                 stuff->win);
352
353             if (detail_level >= EVLOG_PRINT_DETAIL)
354             {
355                 REPLY (" num_masks(%d)",
356                 stuff->num_masks);
357             }
358
359             return reply;
360         }
361
362     case X_XIQueryVersion:
363         {
364             xXIQueryVersionReq *stuff = (xXIQueryVersionReq *)req;
365             REPLY (": major_vesion(%d) minor_vesion(%d)",
366                 stuff->major_version,
367                 stuff->minor_version);
368
369             return reply;
370         }
371
372     case X_XIQueryDevice:
373         {
374             xXIQueryDeviceReq *stuff = (xXIQueryDeviceReq *)req;
375             REPLY (": device_ID(%d)",
376                 stuff->deviceid);
377
378             return reply;
379         }
380
381     case X_XISetFocus:
382         {
383             xXISetFocusReq *stuff = (xXISetFocusReq *)req;
384             REPLY (": XID(0x%x) device_ID(%d)",
385                 stuff->focus,
386                 stuff->deviceid);
387
388             if (detail_level >= EVLOG_PRINT_DETAIL)
389             {
390                 REPLY (" time(%ums)",
391                     stuff->time);
392             }
393
394             return reply;
395         }
396
397     case X_XIGetFocus:
398         {
399             xXIGetFocusReq *stuff = (xXIGetFocusReq *)req;
400             REPLY (": devID(%d)",
401                 stuff->deviceid);
402
403             return reply;
404         }
405
406     case X_XIGrabDevice:
407         {
408             xXIGrabDeviceReq *stuff = (xXIGrabDeviceReq *)req;
409             REPLY (": XID(0x%x) Cursor(0x%x) device_ID(%d)",
410                 stuff->grab_window,
411                 stuff->cursor,
412                 stuff->deviceid);
413
414             if (detail_level >= EVLOG_PRINT_DETAIL)
415             {
416                 REPLY ("\n");
417                 REPLY ("%67s grab_mode",
418                     " ");
419                 REPLY ("(");
420                 reply = _getMode(stuff->grab_mode, reply, len);
421                 REPLY (")");
422
423                 REPLY (" paired_device_mode");
424                 REPLY ("(");
425                 reply = _getMode(stuff->paired_device_mode, reply, len);
426                 REPLY (")");
427
428                 REPLY (" time(%ums) owner_events(%s)",
429                 stuff->time,
430                 stuff->owner_events ? "YES" : "NO");
431             }
432
433             return reply;
434         }
435
436     case X_XIUngrabDevice:
437         {
438             xXIUngrabDeviceReq *stuff = (xXIUngrabDeviceReq *)req;
439             REPLY (": devID(%d)",
440                 stuff->deviceid);
441
442             if (detail_level >= EVLOG_PRINT_DETAIL)
443             {
444                 REPLY (" time(%ums)",
445                 stuff->time);
446             }
447
448             return reply;
449         }
450
451     case X_XIAllowEvents:
452         {
453             xXIAllowEventsReq *stuff = (xXIAllowEventsReq *)req;
454             REPLY (": devID(%d)",
455                 stuff->deviceid);
456
457             if (detail_level >= EVLOG_PRINT_DETAIL)
458             {
459                 REPLY (" time(%ums) mode(%d)",
460                 stuff->time,
461                 stuff->mode);
462             }
463
464             return reply;
465         }
466
467     case X_XIPassiveGrabDevice:
468         {
469             xXIPassiveGrabDeviceReq *stuff = (xXIPassiveGrabDeviceReq *)req;
470             REPLY (": XID(0x%x) Cursor(0x%x) device_ID(%d)",
471                 stuff->grab_window,
472                 stuff->cursor,
473                 stuff->deviceid);
474
475             if (detail_level >= EVLOG_PRINT_DETAIL)
476             {
477                 const char * type;
478                 char dtype[10];
479
480                 switch(stuff->grab_type)
481                 {
482                     case XIGrabtypeButton:  type = "XIGrabtypeButton"; break;
483                     case XIGrabtypeKeycode:  type = "XIGrabtypeKeycode"; break;
484                     case XIGrabtypeEnter:  type = "XIGrabtypeEnter"; break;
485                     case XIGrabtypeFocusIn:  type = "XIGrabtypeFocusIn"; break;
486                     case XIGrabtypeTouchBegin:  type = "XIGrabtypeTouchBegin"; break;
487                     default:  type = dtype; snprintf (dtype, 10, "%d", stuff->grab_type); break;
488                 }
489
490                 REPLY (" time(%ums) detail(%d) grab_type(%s)",
491                 stuff->time,
492                 stuff->detail,
493                 type);
494
495                 REPLY ("\n");
496                 REPLY ("%67s", " ");
497
498                 REPLY (" grab_mode");
499                 REPLY ("(");
500                 reply = _getMode(stuff->grab_mode, reply, len);
501                 REPLY (")");
502
503                 REPLY (" paired_device_mode");
504                 REPLY ("(");
505                 reply = _getMode(stuff->paired_device_mode, reply, len);
506                 REPLY (")");
507
508                 REPLY (" num_modifier(%d) owner_events(%s)",
509                     stuff->num_modifiers,
510                     stuff->owner_events ? "YES" : "NO");
511
512             }
513
514             return reply;
515         }
516
517     case X_XIPassiveUngrabDevice:
518         {
519             xXIPassiveUngrabDeviceReq *stuff = (xXIPassiveUngrabDeviceReq *)req;
520             REPLY (": XID(0x%x) device_ID(%d)",
521                 stuff->grab_window,
522                 stuff->deviceid);
523
524             if (detail_level >= EVLOG_PRINT_DETAIL)
525             {
526                 const char * type;
527                 char dtype[10];
528
529                 switch(stuff->grab_type)
530                 {
531                     case XIGrabtypeButton:  type = "XIGrabtypeButton"; break;
532                     case XIGrabtypeKeycode:  type = "XIGrabtypeKeycode"; break;
533                     case XIGrabtypeEnter:  type = "XIGrabtypeEnter"; break;
534                     case XIGrabtypeFocusIn:  type = "XIGrabtypeFocusIn"; break;
535                     case XIGrabtypeTouchBegin:  type = "XIGrabtypeTouchBegin"; break;
536                     default:  type = dtype; snprintf (dtype, 10, "%d", stuff->grab_type); break;
537                 }
538
539                 REPLY (" detail(%d) grab_type(%s) num_modifiers(%d)",
540                 stuff->detail,
541                 type,
542                 stuff->num_modifiers);
543             }
544
545             return reply;
546         }
547
548     case X_XIListProperties:
549         {
550             xXIListPropertiesReq *stuff = (xXIListPropertiesReq *)req;
551             REPLY (": devID(%d)",
552                 stuff->deviceid);
553
554             return reply;
555         }
556
557     case X_XIChangeProperty:
558         {
559             xXIChangePropertyReq *stuff = (xXIChangePropertyReq *)req;
560             REPLY (": devID(%d)",
561                 stuff->deviceid);
562
563             REPLY (" Property");
564             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
565             REPLY (" Type");
566             reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
567
568             if (detail_level >= EVLOG_PRINT_DETAIL)
569             {
570                 const char * mode;
571                 char dmode[10];
572
573                 switch(stuff->mode)
574                 {
575                     case XIPropModeReplace:  mode = "XIPropModeReplace"; break;
576                     case XIPropModePrepend:  mode = "XIPropModePrepend"; break;
577                     case XIPropModeAppend:  mode = "XIPropModeAppend"; break;
578                     default:  mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
579                 }
580
581                 REPLY (" mode(%s) format(%d) num_items(%d)",
582                 mode,
583                 stuff->format,
584                 stuff->num_items);
585             }
586
587             return reply;
588         }
589
590     case X_XIDeleteProperty:
591         {
592             xXIDeletePropertyReq *stuff = (xXIDeletePropertyReq *)req;
593             REPLY (": devID(%d)",
594                 stuff->deviceid);
595
596             REPLY (" Property");
597             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
598
599             return reply;
600         }
601
602     case X_XIGetProperty:
603         {
604             xXIGetPropertyReq *stuff = (xXIGetPropertyReq *)req;
605             REPLY (": devID(%d)",
606                 stuff->deviceid);
607
608             REPLY (" Property");
609             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
610             REPLY (" Type");
611             reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
612
613             if (detail_level >= EVLOG_PRINT_DETAIL)
614             {
615                 REPLY (" delete(%s) offset(%u) length(%u)",
616                 stuff->delete ? "YES" : "NO",
617                 stuff->offset,
618                 stuff->len);
619             }
620
621             return reply;
622         }
623
624     case X_XIGetSelectedEvents:
625         {
626             xXIGetSelectedEventsReq *stuff = (xXIGetSelectedEventsReq *)req;
627             REPLY (": XID(0x%x)",
628                 stuff->win);
629
630             return reply;
631         }
632
633     default:
634             break;
635     }
636
637     return reply;
638 }
639
640 static char *
641 _EvlogEventXinput (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
642 {
643     xEvent *evt = evinfo->evt.ptr;
644
645     switch ((evt->u.u.type & 0x7F) - first_base)
646     {
647     case XI_DeviceValuator:
648         {
649             deviceValuator *stuff = (deviceValuator *) evt;
650             REPLY (": device_ID(%d) numValuator(%d) fstnumValuator(%d)",
651                 stuff->deviceid,
652                 stuff->num_valuators,
653                 stuff->first_valuator);
654
655             if (detail_level >= EVLOG_PRINT_DETAIL)
656             {
657                 int i;
658
659                 REPLY (" sequence_num(%d) device_state(0x%x)\n",
660                     stuff->sequenceNumber,
661                     stuff->device_state);
662
663                 REPLY ("%67s", " ");
664                 for (i = 0 ; i < stuff->num_valuators ; i++)
665                 {
666                     REPLY (" valuator%d(%ld)",
667                         i,
668                         *(&stuff->valuator0 + i));
669                 }
670             }
671
672             return reply;
673         }
674
675     case XI_DeviceKeyPress:
676         {
677             XDeviceKeyPressedEvent *stuff = (XDeviceKeyPressedEvent *) evt;
678             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
679                 stuff->deviceid,
680                 stuff->window,
681                 stuff->x,
682                 stuff->y,
683                 stuff->root,
684                 stuff->x_root,
685                 stuff->y_root,
686                 stuff->subwindow);
687
688             if (detail_level >= EVLOG_PRINT_DETAIL)
689             {
690                 REPLY ("\n");
691                 REPLY ("%67s time(%lums) state(%d) key_code(%d) same_screen(%s) device_state(%d) first_axis(%d)",
692                     " ",
693                     stuff->time,
694                     stuff->state,
695                     stuff->keycode,
696                     stuff->same_screen ? "YES" : "NO",
697                     stuff->device_state,
698                     stuff->first_axis);
699             }
700
701             return reply;
702         }
703
704     case XI_DeviceKeyRelease:
705         {
706             XDeviceKeyReleasedEvent *stuff = (XDeviceKeyReleasedEvent *) evt;
707             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
708                 stuff->deviceid,
709                 stuff->window,
710                 stuff->x,
711                 stuff->y,
712                 stuff->root,
713                 stuff->x_root,
714                 stuff->y_root,
715                 stuff->subwindow);
716
717             if (detail_level >= EVLOG_PRINT_DETAIL)
718             {
719                 REPLY ("\n");
720                 REPLY ("%67s time(%lums) state(%d) key_code(%d) same_screen(%s) device_state(%d) first_axis(%d)",
721                     " ",
722                     stuff->time,
723                     stuff->state,
724                     stuff->keycode,
725                     stuff->same_screen ? "YES" : "NO",
726                     stuff->device_state,
727                     stuff->first_axis);
728             }
729
730             return reply;
731         }
732
733     case XI_DeviceButtonPress:
734         {
735             XDeviceButtonPressedEvent *stuff = (XDeviceButtonPressedEvent *) evt;
736             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
737                 stuff->deviceid,
738                 stuff->window,
739                 stuff->x,
740                 stuff->y,
741                 stuff->root,
742                 stuff->x_root,
743                 stuff->y_root,
744                 stuff->subwindow);
745
746             if (detail_level >= EVLOG_PRINT_DETAIL)
747             {
748                 REPLY ("\n");
749                 REPLY ("%67s time(%lums) state(%d) button(%d) same_screen(%s) device_state(%d) first_axis(%d)",
750                     " ",
751                     stuff->time,
752                     stuff->state,
753                     stuff->button,
754                     stuff->same_screen ? "YES" : "NO",
755                     stuff->device_state,
756                     stuff->first_axis);
757             }
758
759             return reply;
760         }
761
762     case XI_DeviceButtonRelease:
763         {
764             XDeviceButtonReleasedEvent *stuff = (XDeviceButtonReleasedEvent *) evt;
765             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
766                 stuff->deviceid,
767                 stuff->window,
768                 stuff->x,
769                 stuff->y,
770                 stuff->root,
771                 stuff->x_root,
772                 stuff->y_root,
773                 stuff->subwindow);
774
775             if (detail_level >= EVLOG_PRINT_DETAIL)
776             {
777                 REPLY ("\n");
778                 REPLY ("%67s time(%lums) state(%d) button(%d) same_screen(%s) device_state(%d) first_axis(%d)",
779                     " ",
780                     stuff->time,
781                     stuff->state,
782                     stuff->button,
783                     stuff->same_screen ? "YES" : "NO",
784                     stuff->device_state,
785                     stuff->first_axis);
786             }
787
788             return reply;
789         }
790
791     case XI_DeviceMotionNotify:
792         {
793             XDeviceMotionEvent *stuff = (XDeviceMotionEvent *) evt;
794             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
795                 stuff->deviceid,
796                 stuff->window,
797                 stuff->x,
798                 stuff->y,
799                 stuff->root,
800                 stuff->x_root,
801                 stuff->y_root,
802                 stuff->subwindow);
803
804             if (detail_level >= EVLOG_PRINT_DETAIL)
805             {
806                 REPLY ("\n");
807                 REPLY ("%67s time(%lums) state(%d) is_hint(%d) same_screen(%s) device_state(%d) first_axis(%d)",
808                     " ",
809                     stuff->time,
810                     stuff->state,
811                     stuff->is_hint,
812                     stuff->same_screen ? "YES" : "NO",
813                     stuff->device_state,
814                     stuff->first_axis);
815             }
816
817             return reply;
818         }
819
820     case XI_DeviceFocusIn:
821         {
822             XDeviceFocusInEvent *stuff = (XDeviceFocusInEvent *) evt;
823             REPLY (": XID(0x%lx) Window(0x%lx)",
824                 stuff->deviceid,
825                 stuff->window);
826
827             if (detail_level >= EVLOG_PRINT_DETAIL)
828             {
829                 const char *mode, *detail;
830                 char dmode[10], ddetail[10];
831
832                 switch(stuff->mode)
833                 {
834                     case NotifyNormal:  mode = "NotifyNormal"; break;
835                     case NotifyGrab:  mode = "NotifyGrab"; break;
836                     case NotifyUngrab:  mode = "NotifyUngrab"; break;
837                     case NotifyWhileGrabbed:  mode = "NotifyWhileGrabbed"; break;
838                     default:  mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
839                 }
840
841                 switch(stuff->detail)
842                 {
843                     case NotifyAncestor:  detail = "NotifyAncestor"; break;
844                     case NotifyVirtual:  detail = "NotifyVirtual"; break;
845                     case NotifyInferior:  detail = "NotifyInferior"; break;
846                     case NotifyNonlinear:  detail = "NotifyNonlinear"; break;
847                     case NotifyNonlinearVirtual:  detail = "NotifyNonlinearVirtual"; break;
848                     case NotifyPointer:  detail = "NotifyPointer"; break;
849                     case NotifyPointerRoot:  detail = "NotifyPointerRoot"; break;
850                     case NotifyDetailNone:  detail = "NotifyDetailNone"; break;
851                     default:  detail = ddetail; snprintf (ddetail, 10, "%d", stuff->detail); break;
852                 }
853
854                 REPLY (" mode(%s) detail(%s) time(%lums)",
855                     mode,
856                     detail,
857                     stuff->time);
858             }
859
860             return reply;
861         }
862
863     case XI_DeviceFocusOut:
864         {
865             XDeviceFocusOutEvent *stuff = (XDeviceFocusOutEvent *) evt;
866             REPLY (": XID(0x%lx) Window(0x%lx)",
867                 stuff->deviceid,
868                 stuff->window);
869
870             if (detail_level >= EVLOG_PRINT_DETAIL)
871             {
872                 const char *mode, *detail;
873                 char dmode[10], ddetail[10];
874
875                 switch(stuff->mode)
876                 {
877                     case NotifyNormal:  mode = "NotifyNormal"; break;
878                     case NotifyGrab:  mode = "NotifyGrab"; break;
879                     case NotifyUngrab:  mode = "NotifyUngrab"; break;
880                     case NotifyWhileGrabbed:  mode = "NotifyWhileGrabbed"; break;
881                     default:  mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
882                 }
883
884                 switch(stuff->detail)
885                 {
886                     case NotifyAncestor:  detail = "NotifyAncestor"; break;
887                     case NotifyVirtual:  detail = "NotifyVirtual"; break;
888                     case NotifyInferior:  detail = "NotifyInferior"; break;
889                     case NotifyNonlinear:  detail = "NotifyNonlinear"; break;
890                     case NotifyNonlinearVirtual:  detail = "NotifyNonlinearVirtual"; break;
891                     case NotifyPointer:  detail = "NotifyPointer"; break;
892                     case NotifyPointerRoot:  detail = "NotifyPointerRoot"; break;
893                     case NotifyDetailNone:  detail = "NotifyDetailNone"; break;
894                     default:  detail = ddetail; snprintf (ddetail, 10, "%d", stuff->detail); break;
895                 }
896
897                 REPLY (" mode(%s) detail(%s) time(%lums)",
898                     mode,
899                     detail,
900                     stuff->time);
901             }
902
903             return reply;
904         }
905
906     case XI_ProximityIn:
907         {
908             XProximityInEvent *stuff = (XProximityInEvent *) evt;
909             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
910                 stuff->deviceid,
911                 stuff->window,
912                 stuff->x,
913                 stuff->y,
914                 stuff->root,
915                 stuff->x_root,
916                 stuff->y_root,
917                 stuff->subwindow);
918
919             if (detail_level >= EVLOG_PRINT_DETAIL)
920             {
921                 REPLY ("\n");
922                 REPLY ("%67s time(%lums) state(%d) same_screen(%s) device_state(%d) first_axis(%d)",
923                     " ",
924                     stuff->time,
925                     stuff->state,
926                     stuff->same_screen ? "YES" : "NO",
927                     stuff->device_state,
928                     stuff->first_axis);
929             }
930
931             return reply;
932         }
933
934     case XI_ProximityOut:
935         {
936             XProximityOutEvent *stuff = (XProximityOutEvent *) evt;
937             REPLY (": XID(0x%lx) Window(0x%lx %d,%d) Root(0x%lx %d,%d) subWindow(0x%lx)",
938                 stuff->deviceid,
939                 stuff->window,
940                 stuff->x,
941                 stuff->y,
942                 stuff->root,
943                 stuff->x_root,
944                 stuff->y_root,
945                 stuff->subwindow);
946
947             if (detail_level >= EVLOG_PRINT_DETAIL)
948             {
949                 REPLY ("\n");
950                 REPLY ("%67s time(%lums) state(%d) same_screen(%s) device_state(%d) first_axis(%d)",
951                     " ",
952                     stuff->time,
953                     stuff->state,
954                     stuff->same_screen ? "YES" : "NO",
955                     stuff->device_state,
956                     stuff->first_axis);
957             }
958
959             return reply;
960         }
961
962     case XI_DeviceStateNotify:
963         {
964             XDeviceStateNotifyEvent *stuff = (XDeviceStateNotifyEvent *) evt;
965             REPLY (": XID(0x%lx) Window(0x%lx)",
966                 stuff->deviceid,
967                 stuff->window);
968
969             if (detail_level >= EVLOG_PRINT_DETAIL)
970             {
971                 REPLY (" time(%lums) num_classes(%d)",
972                     stuff->time,
973                     stuff->num_classes);
974             }
975
976             return reply;
977         }
978
979     case XI_DeviceMappingNotify:
980         {
981             XDeviceMappingEvent *stuff = (XDeviceMappingEvent *) evt;
982             REPLY (": XID(0x%lx) Window(0x%lx)",
983                 stuff->deviceid,
984                 stuff->window);
985
986             if (detail_level >= EVLOG_PRINT_DETAIL)
987             {
988                 const char *request;
989                 char drequest[10];
990
991                 switch(stuff->request)
992                 {
993                     case MappingModifier:  request = "MappingModifier"; break;
994                     case MappingKeyboard:  request = "MappingKeyboard"; break;
995                     case MappingPointer:  request = "MappingPointer"; break;
996                     default:  request = drequest; snprintf (drequest, 10, "%d", stuff->request); break;
997                 }
998
999                 REPLY (" time(%lums) request(%s) first_keycode(%d) count(%d)",
1000                     stuff->time,
1001                     request,
1002                     stuff->first_keycode,
1003                     stuff->count);
1004             }
1005
1006             return reply;
1007         }
1008
1009     case XI_ChangeDeviceNotify:
1010         {
1011             XChangeDeviceNotifyEvent *stuff = (XChangeDeviceNotifyEvent *) evt;
1012             REPLY (": XID(0x%lx) Window(0x%lx)",
1013                 stuff->deviceid,
1014                 stuff->window);
1015
1016             if (detail_level >= EVLOG_PRINT_DETAIL)
1017             {
1018                 const char *request;
1019                 char drequest[10];
1020
1021                 switch(stuff->request)
1022                 {
1023                     case NewPointer:  request = "NewPointer"; break;
1024                     case NewKeyboard:  request = "NewKeyboard"; break;
1025                     default:  request = drequest; snprintf (drequest, 10, "%d", stuff->request); break;
1026                 }
1027
1028                 REPLY (" time(%lums) request(%s)",
1029                     stuff->time,
1030                     request);
1031             }
1032
1033             return reply;
1034         }
1035
1036     case XI_DeviceKeystateNotify:
1037         {
1038             deviceKeyStateNotify *stuff = (deviceKeyStateNotify *) evt;
1039             REPLY (": deviceid(%d)",
1040                 stuff->deviceid);
1041
1042             if (detail_level >= EVLOG_PRINT_DETAIL)
1043             {
1044                 REPLY (" sequence_num(%d)",
1045                     stuff->sequenceNumber);
1046             }
1047
1048             return reply;
1049         }
1050
1051     case XI_DeviceButtonstateNotify:
1052         {
1053             deviceButtonStateNotify *stuff = (deviceButtonStateNotify *) evt;
1054             REPLY (": deviceid(%d)",
1055                 stuff->deviceid);
1056
1057             if (detail_level >= EVLOG_PRINT_DETAIL)
1058             {
1059                 REPLY (" sequence_num(%d)",
1060                     stuff->sequenceNumber);
1061             }
1062
1063             return reply;
1064         }
1065
1066     case XI_DevicePresenceNotify:
1067         {
1068             devicePresenceNotify *stuff = (devicePresenceNotify *) evt;
1069             REPLY (": deviceid(%d)",
1070                 stuff->deviceid);
1071
1072             if (detail_level >= EVLOG_PRINT_DETAIL)
1073             {
1074                 REPLY (" time(%lums) device_change(%d) control(%d) sequence_num(%d)",
1075                     stuff->time,
1076                     stuff->devchange,
1077                     stuff->control,
1078                     stuff->sequenceNumber);
1079             }
1080
1081             return reply;
1082         }
1083
1084     case XI_DevicePropertyNotify:
1085         {
1086             devicePropertyNotify *stuff = (devicePropertyNotify *) evt;
1087             REPLY (": deviceid(%d)",
1088                 stuff->deviceid);
1089
1090             REPLY (" Atom");
1091             reply = xDbgGetAtom(stuff->atom, evinfo, reply, len);
1092
1093             if (detail_level >= EVLOG_PRINT_DETAIL)
1094             {
1095                 REPLY (" time(%lums) state(%d) sequence_num(%d)",
1096                     stuff->time,
1097                     stuff->state,
1098                     stuff->sequenceNumber);
1099             }
1100
1101             return reply;
1102         }
1103
1104     default:
1105             break;
1106     }
1107
1108     return reply;
1109 }
1110
1111 static char *
1112 _EvlogReplyXinput (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
1113 {
1114     xGenericReply *rep = evinfo->rep.ptr;
1115
1116     switch (evinfo->rep.reqData)
1117     {
1118     case X_ListInputDevices:
1119         {
1120             if (evinfo->rep.isStart)
1121             {
1122                 xListInputDevicesReply *stuff = (xListInputDevicesReply *) rep;
1123                 REPLY (": nDevices(%d)",
1124                     stuff->ndevices);
1125             }
1126             else
1127             {
1128                 return reply;
1129             }
1130
1131             return reply;
1132         }
1133
1134     case X_GrabDevice:
1135         {
1136             if (evinfo->rep.isStart)
1137             {
1138                 xGrabDeviceReply *stuff = (xGrabDeviceReply *) rep;
1139                 REPLY (": status(%d)",
1140                     stuff->status);
1141             }
1142             else
1143             {
1144                 return reply;
1145             }
1146
1147             return reply;
1148         }
1149
1150     case X_GetDeviceFocus:
1151         {
1152             if (evinfo->rep.isStart)
1153             {
1154                 xGetDeviceFocusReply *stuff = (xGetDeviceFocusReply *) rep;
1155                 REPLY (": XID(0x%lx) Time(0x%lx)",
1156                     stuff->focus,
1157                     stuff->time);
1158             }
1159             else
1160             {
1161                 return reply;
1162             }
1163
1164             return reply;
1165         }
1166
1167     case X_XIQueryVersion:
1168         {
1169             if (evinfo->rep.isStart)
1170             {
1171                 xXIQueryVersionReply *stuff = (xXIQueryVersionReply *) rep;
1172                 REPLY (": majorVersion(%d) minorVersion(%d)",
1173                     stuff->major_version,
1174                     stuff->minor_version);
1175             }
1176             else
1177             {
1178                 return reply;
1179             }
1180
1181             return reply;
1182         }
1183
1184     case X_XIQueryDevice:
1185         {
1186             if (evinfo->rep.isStart)
1187             {
1188                 xXIQueryDeviceReply *stuff = (xXIQueryDeviceReply *) rep;
1189                 REPLY (": numDevices(%d)",
1190                     stuff->num_devices);
1191             }
1192             else
1193             {
1194                 return reply;
1195             }
1196
1197             return reply;
1198         }
1199
1200     case X_XIGetSelectedEvents:
1201         {
1202             if (evinfo->rep.isStart)
1203             {
1204                 xXIGetSelectedEventsReply *stuff = (xXIGetSelectedEventsReply *) rep;
1205                 REPLY (": numMasks(%d)",
1206                     stuff->num_masks);
1207             }
1208             else
1209             {
1210                 return reply;
1211             }
1212
1213             return reply;
1214         }
1215
1216     case X_XIQueryPointer:
1217         {
1218             if (evinfo->rep.isStart)
1219             {
1220                 xXIQueryPointerReply *stuff = (xXIQueryPointerReply *) rep;
1221                 REPLY (": XID(0x%x) Child(0x%x) root(%d,%d) win(%d,%d)",
1222                     stuff->root,
1223                     stuff->child,
1224                     stuff->root_x,
1225                     stuff->root_y,
1226                     stuff->win_x,
1227                     stuff->win_y);
1228             }
1229             else
1230             {
1231                 return reply;
1232             }
1233
1234             return reply;
1235         }
1236
1237     case X_XIGetClientPointer:
1238         {
1239             if (evinfo->rep.isStart)
1240             {
1241                 xXIGetClientPointerReply *stuff = (xXIGetClientPointerReply *) rep;
1242                 REPLY (": Set(%s) deviceid(%d)",
1243                     (stuff->set) ? "true":"false",
1244                     stuff->deviceid);
1245             }
1246             else
1247             {
1248                 return reply;
1249             }
1250
1251             return reply;
1252         }
1253
1254     case X_XIGetFocus:
1255         {
1256             if (evinfo->rep.isStart)
1257             {
1258                 xXIGetFocusReply *stuff = (xXIGetFocusReply *) rep;
1259                 REPLY (": XID(0x%x)",
1260                     stuff->focus);
1261             }
1262             else
1263             {
1264                 return reply;
1265             }
1266
1267             return reply;
1268         }
1269
1270     case X_XIGrabDevice:
1271         {
1272             if (evinfo->rep.isStart)
1273             {
1274                 xXIGrabDeviceReply *stuff = (xXIGrabDeviceReply *) rep;
1275                 REPLY (": status(%d)",
1276                     stuff->status);
1277             }
1278             else
1279             {
1280                 return reply;
1281             }
1282
1283             return reply;
1284         }
1285
1286     case X_XIPassiveGrabDevice:
1287         {
1288             if (evinfo->rep.isStart)
1289             {
1290                 xXIPassiveGrabDeviceReply *stuff = (xXIPassiveGrabDeviceReply *) rep;
1291                 REPLY (": numModifiers(%d)",
1292                     stuff->num_modifiers);
1293             }
1294             else
1295             {
1296                 return reply;
1297             }
1298
1299             return reply;
1300         }
1301
1302     case X_XIListProperties:
1303         {
1304             if (evinfo->rep.isStart)
1305             {
1306                 xXIListPropertiesReply *stuff = (xXIListPropertiesReply *) rep;
1307                 REPLY (": numProperties(%d)",
1308                     stuff->num_properties);
1309             }
1310             else
1311             {
1312                 Atom *stuff = (Atom *)rep;
1313                 int i;
1314
1315                 REPLY ("Properties(");
1316                 for (i = 0 ; i < evinfo->rep.size / sizeof(Atom) ; i ++)
1317                 {
1318                     reply = xDbgGetAtom(stuff[i], evinfo, reply, len);
1319                     if(i != evinfo->rep.size / sizeof(Atom) - 1)
1320                         REPLY (", ");
1321                 }
1322                 REPLY (")");
1323             }
1324
1325             return reply;
1326         }
1327
1328     case X_XIGetProperty:
1329         {
1330             if (evinfo->rep.isStart)
1331             {
1332                 xXIGetPropertyReply *stuff = (xXIGetPropertyReply *) rep;
1333
1334                 REPLY (": Type");
1335                 xDbgGetAtom(stuff->type, evinfo, reply, len);
1336
1337                 REPLY (" numItems(%d) format(%d)",
1338                     stuff->num_items,
1339                     stuff->format);
1340             }
1341             else
1342             {
1343                 return reply;
1344             }
1345
1346             return reply;
1347         }
1348
1349     default:
1350             break;
1351     }
1352
1353     return reply;
1354 }
1355
1356 void
1357 xDbgEvlogXinputGetBase (ExtensionInfo *extinfo)
1358 {
1359 #ifdef XDBG_CLIENT
1360     RETURN_IF_FAIL (extinfo != NULL);
1361
1362     extinfo->req_func = _EvlogRequestXinput;
1363     extinfo->evt_func = _EvlogEventXinput;
1364     extinfo->rep_func = _EvlogReplyXinput;
1365 #else
1366     ExtensionEntry *xext = CheckExtension (INAME);
1367     RETURN_IF_FAIL (xext != NULL);
1368     RETURN_IF_FAIL (extinfo != NULL);
1369
1370     extinfo->opcode = xext->base;
1371     extinfo->evt_base = xext->eventBase;
1372     extinfo->err_base = xext->errorBase;
1373     extinfo->req_func = _EvlogRequestXinput;
1374     extinfo->evt_func = _EvlogEventXinput;
1375     extinfo->rep_func = _EvlogReplyXinput;
1376 #endif
1377 }