tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_core.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 #include <X11/Xproto.h>
55 #include <X11/extensions/XI2proto.h>
56
57 #include "xdbg_types.h"
58 #include "xdbg_evlog_core.h"
59 #include "xdbg_evlog.h"
60
61
62 static char*
63 _getWindowAttributeMask (CARD32 mask, char *reply, int *len)
64 {
65     int i;
66     int init = 0;
67
68     for (i = 0 ; i < sizeof(mask) * 4 ; i++)
69     {
70         if(mask & (1 << i))
71         {
72             if (init)
73                 REPLY(" ");
74             else
75                 init = 1;
76
77             switch (1 << i)
78             {
79                 case CWBackPixmap: REPLY("CWBackPixmap"); break;
80                 case CWBackPixel: REPLY("CWBackPixel"); break;
81                 case CWBorderPixmap: REPLY("CWBorderPixmap"); break;
82                 case CWBorderPixel: REPLY("CWBorderPixel"); break;
83                 case CWBitGravity: REPLY("CWBitGravity"); break;
84                 case CWWinGravity: REPLY("CWWinGravity"); break;
85                 case CWBackingStore: REPLY("CWBackingStore"); break;
86                 case CWBackingPlanes: REPLY("CWBackingPlanes"); break;
87                 case CWBackingPixel: REPLY("CWBackingPixel"); break;
88                 case CWOverrideRedirect: REPLY("CWOverrideRedirect"); break;
89                 case CWSaveUnder: REPLY("CWSaveUnder"); break;
90                 case CWEventMask: REPLY("CWEventMask"); break;
91                 case CWDontPropagate: REPLY("CWDontPropagate"); break;
92                 case CWColormap: REPLY("CWColormap"); break;
93                 case CWCursor: REPLY("CWCursor"); break;
94             }
95         }
96     }
97
98     return reply;
99 }
100
101 #define GET_INT16(m, f) \
102         if (m & mask) \
103           { \
104              f = (INT16) *pVlist;\
105             pVlist++; \
106          }
107 #define GET_CARD16(m, f) \
108         if (m & mask) \
109          { \
110             f = (CARD16) *pVlist;\
111             pVlist++;\
112          }
113
114 #define GET_CARD8(m, f) \
115         if (m & mask) \
116          { \
117             f = (CARD8) *pVlist;\
118             pVlist++;\
119          }
120
121 static char*
122 _getConfigureWindowMask (CARD16 mask, char *reply, int *len, XID *vlist)
123 {
124     int i;
125     int init = 0;
126     short x=0, y=0;
127     unsigned short w=0, h=0;
128     XID *pVlist;
129
130     if(vlist)
131     {
132         pVlist = vlist;
133         
134         if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) {
135             GET_INT16(CWX, x);
136             GET_INT16(CWY, y);
137         }
138         /* or should be resized */
139         else if (mask & (CWX | CWY | CWWidth | CWHeight)) {
140             GET_INT16(CWX, x);
141             GET_INT16(CWY, y);
142             GET_CARD16(CWWidth, w);
143             GET_CARD16(CWHeight, h);
144         }
145     }
146     
147     for (i = 0 ; i < sizeof(mask) * 4 ; i++)
148     {
149         if(mask & (1 << i))
150         {
151             if (init)
152                 REPLY(" ");
153             else
154                 init = 1;
155
156             if (vlist)
157             {
158                 switch (1 << i)
159                 {
160                     case CWX: REPLY("CWX:%d",x); break;
161                     case CWY: REPLY("CWY:%d",y); break;
162                     case CWWidth: REPLY("CWWidth:%d",w); break;
163                     case CWHeight: REPLY("CWHeight:%d",h); break;
164                     case CWBorderWidth: REPLY("CWBorderWidth"); break;
165                     case CWSibling: REPLY("CWSibling"); break;
166                     case CWStackMode: REPLY("CWStackMode"); break;
167                 }
168             }
169             else
170             {
171                 switch (1 << i)
172                 {
173                     case CWX: REPLY("CWX"); break;
174                     case CWY: REPLY("CWY"); break;
175                     case CWWidth: REPLY("CWWidth"); break;
176                     case CWHeight: REPLY("CWHeight"); break;
177                     case CWBorderWidth: REPLY("CWBorderWidth"); break;
178                     case CWSibling: REPLY("CWSibling"); break;
179                     case CWStackMode: REPLY("CWStackMode"); break;
180                 }
181             }
182         }
183     }
184
185     return reply;
186 }
187
188 static char*
189 _getKeyMask (CARD16 mask, char *reply, int *len)
190 {
191     int i;
192     int init = 0;
193
194     for (i = 0 ; i < sizeof(mask) * 4 ; i++)
195     {
196         if(mask & (1 << i))
197         {
198             if (init)
199                 REPLY(" ");
200             else
201                 init = 1;
202
203             switch (1 << i)
204             {
205                 case ShiftMask: REPLY("ShiftMask"); break;
206                 case LockMask: REPLY("LockMask"); break;
207                 case ControlMask: REPLY("ControlMask"); break;
208                 case Mod1Mask: REPLY("Mod1Mask"); break;
209                 case Mod2Mask: REPLY("Mod2Mask"); break;
210                 case Mod3Mask: REPLY("Mod3Mask"); break;
211                 case Mod4Mask: REPLY("Mod4Mask"); break;
212                 case Mod5Mask: REPLY("Mod5Mask"); break;
213                 case Button1Mask: REPLY("Button1Mask"); break;
214                 case Button2Mask: REPLY("Button2Mask"); break;
215                 case Button3Mask: REPLY("Button3Mask"); break;
216                 case Button4Mask: REPLY("Button4Mask"); break;
217                 case Button5Mask: REPLY("Button5Mask"); break;
218                 case AnyModifier: REPLY("AnyModifier"); break;
219             }
220         }
221     }
222
223     return reply;
224 }
225
226 static char*
227 _getEventMask (CARD32 mask, char *reply, int *len)
228 {
229     int i;
230     int init = 0;
231
232     for (i = 0 ; i < sizeof(mask) * 4 ; i++)
233     {
234         if(mask & (1 << i))
235         {
236             if (init)
237                 REPLY(" ");
238             else
239                 init = 1;
240
241             switch (1 << i)
242             {
243                 case NoEventMask: REPLY("NoEventMask"); break;
244                 case KeyPressMask: REPLY("KeyPressMask"); break;
245                 case KeyReleaseMask: REPLY("KeyReleaseMask"); break;
246                 case ButtonPressMask: REPLY("ButtonPressMask"); break;
247                 case ButtonReleaseMask: REPLY("ButtonReleaseMask"); break;
248                 case EnterWindowMask: REPLY("EnterWindowMask"); break;
249                 case LeaveWindowMask: REPLY("LeaveWindowMask"); break;
250                 case PointerMotionMask: REPLY("PointerMotionMask"); break;
251                 case PointerMotionHintMask: REPLY("PointerMotionHintMask"); break;
252                 case Button1MotionMask: REPLY("Button1MotionMask"); break;
253                 case Button2MotionMask: REPLY("Button2MotionMask"); break;
254                 case Button3MotionMask: REPLY("Button3MotionMask"); break;
255                 case Button4MotionMask: REPLY("Button4MotionMask"); break;
256                 case Button5MotionMask: REPLY("Button5MotionMask"); break;
257                 case ButtonMotionMask: REPLY("ButtonMotionMask"); break;
258                 case KeymapStateMask: REPLY("KeymapStateMask"); break;
259                 case ExposureMask: REPLY("ExposureMask"); break;
260                 case VisibilityChangeMask: REPLY("VisibilityChangeMask"); break;
261                 case StructureNotifyMask: REPLY("StructureNotifyMask"); break;
262                 case ResizeRedirectMask: REPLY("ResizeRedirectMask"); break;
263                 case SubstructureNotifyMask: REPLY("SubstructureNotifyMask"); break;
264                 case SubstructureRedirectMask: REPLY("SubstructureRedirectMask"); break;
265                 case FocusChangeMask: REPLY("FocusChangeMask"); break;
266                 case PropertyChangeMask: REPLY("PropertyChangeMask"); break;
267                 case ColormapChangeMask: REPLY("ColormapChangeMask"); break;
268                 case OwnerGrabButtonMask: REPLY("OwnerGrabButtonMask"); break;
269             }
270         }
271     }
272
273     return reply;
274 }
275
276 char * xDbgEvlogRequestCore (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
277 {
278     xReq *req = evinfo->req.ptr;
279
280     switch (req->reqType)
281     {
282     case X_CreateWindow:
283         {
284             xCreateWindowReq *stuff = (xCreateWindowReq *)req;
285
286             REPLY (": Window(0x%x) Parent(0x%x) size(%dx%d) boaderWid(%d) coordinate(%d,%d)",
287                 (unsigned int)stuff->wid,
288                 (unsigned int)stuff->parent,
289                 stuff->width,
290                 stuff->height,
291                 stuff->borderWidth,
292                 stuff->x,
293                 stuff->y);
294
295             if (detail_level >= EVLOG_PRINT_DETAIL)
296             {
297                 const char *visual, *class;
298                 char dvisual[10], dclass[10];
299
300                 switch (stuff->visual)
301                 {
302                     case CopyFromParent:  visual = "CopyFromParent"; break;
303                     default:  visual = dvisual; snprintf (dvisual, 10, "0x%x", (unsigned int)stuff->visual); break;
304                 }
305
306                 switch (stuff->class)
307                 {
308                     case CopyFromParent:  class = "CopyFromParent"; break;
309                     case InputOutput:  class = "InputOutput"; break;
310                     case InputOnly:  class = "InputOnly"; break;
311                     default:  class = dclass; snprintf (dclass, 10, "0x%x", stuff->class); break;
312                 }
313
314                 REPLY ("\n");
315                 REPLY ("%67s depth(%d) visual_ID(%s) class(%s)\n",
316                     " ",
317                     stuff->depth,
318                     visual,
319                     class);
320
321     \r           REPLY ("%67s mask", " ");
322     \r           REPLY ("(");
323                 reply = _getWindowAttributeMask(stuff->mask, reply, len);
324     \r           REPLY (")");
325             }
326
327             return reply;
328         }
329
330     case X_ChangeWindowAttributes:
331         {
332             xChangeWindowAttributesReq *stuff = (xChangeWindowAttributesReq *)req;
333             REPLY (": XID(0x%x)", (unsigned int)stuff->window);
334
335             if (detail_level >= EVLOG_PRINT_DETAIL)
336             {
337     \r           REPLY (" detail");
338     \r           REPLY ("(");
339                 reply = _getWindowAttributeMask(stuff->valueMask, reply, len);
340                 if (stuff->valueMask == CWEventMask)
341         
342            REPLY (", mask(%x)", (unsigned int)*((XID *)&stuff[1]));
343     \r           REPLY (")");
344             }
345
346             return reply;
347         }
348
349     case X_ChangeSaveSet:
350         {
351             xChangeSaveSetReq *stuff = (xChangeSaveSetReq *)req;
352
353             REPLY (": XID(0x%x)",
354                 (unsigned int)stuff->window);
355
356             if (detail_level >= EVLOG_PRINT_DETAIL)
357             {
358                 const char *mode;
359                 char dmode[10];
360
361                 switch (stuff->mode)
362                 {
363                     case SetModeInsert:  mode = "SetModeInsert"; break;
364                     case SetModeDelete:  mode = "SetModeDelete"; break;
365                     default:  mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
366                 }
367
368                 REPLY (" mode(%s)",
369                     mode);
370             }
371
372             return reply;
373         }
374
375     case X_ReparentWindow:
376         {
377             xReparentWindowReq *stuff = (xReparentWindowReq *)req;
378             REPLY (": Window(0x%x) Parent(0x%x) coord(%d,%d)",
379                 (unsigned int)stuff->window,
380                 (unsigned int)stuff->parent,
381                 stuff->x,
382                 stuff->y);
383
384             return reply;
385         }
386
387     case X_ConfigureWindow:
388         {
389             xConfigureWindowReq *stuff = (xConfigureWindowReq *)req;
390             REPLY (": XID(0x%x)",
391                 (unsigned int)stuff->window);
392
393             if (detail_level >= EVLOG_PRINT_DETAIL)
394             {
395                 REPLY (" mask");
396                 REPLY ("(");
397                 reply = _getConfigureWindowMask(stuff->mask, reply, len, (XID *)&stuff[1]);
398                 REPLY (")");
399             }
400
401             return reply;
402         }
403
404     case X_CirculateWindow:
405         {
406             xCirculateWindowReq *stuff = (xCirculateWindowReq *)req;
407
408             REPLY (": XID(0x%x)",
409                 (unsigned int)stuff->window);
410
411             if (detail_level >= EVLOG_PRINT_DETAIL)
412             {
413                 const char *direction;
414                 char ddirection[10];
415
416                 switch (stuff->direction)
417                 {
418                     case RaiseLowest:  direction = "RaiseLowest"; break;
419                     case LowerHighest:  direction = "LowerHighest"; break;
420                     default:  direction = ddirection; snprintf (ddirection, 10, "%d", stuff->direction); break;
421                 }
422
423                 REPLY (" direction(%s)",
424                     direction);
425             }
426
427             return reply;
428         }
429
430     case X_ChangeProperty:
431         {
432             xChangePropertyReq *stuff = (xChangePropertyReq *)req;
433
434             REPLY (": XID(0x%x)",
435                 (unsigned int)stuff->window);
436
437             REPLY (" Property");
438             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
439
440             REPLY (" Type");
441             reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
442
443             if (detail_level >= EVLOG_PRINT_DETAIL)
444             {
445                 const char *mode;
446                 char dmode[10];
447
448                 switch (stuff->mode)
449                 {
450                     case PropModeReplace:  mode = "PropModeReplace"; break;
451                     case PropModePrepend:  mode = "PropModePrepend"; break;
452                     case PropModeAppend:  mode = "PropModeAppend"; break;
453                     default:  mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
454                 }
455
456                 REPLY ("\n");
457                 REPLY ("%67s mode(%s) format(%d) nUnits(%ld)",
458                     " ",
459                     mode,
460                     stuff->format,
461                     (long int)stuff->nUnits);
462             }
463
464             return reply;
465         }
466
467     case X_DeleteProperty:
468         {
469             xDeletePropertyReq *stuff = (xDeletePropertyReq *)req;
470             REPLY (": XID(0x%x)",
471                 (unsigned int)stuff->window);
472
473             REPLY (" Property");
474             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
475
476             return reply;
477         }
478
479     case X_GetProperty:
480         {
481             xGetPropertyReq *stuff = (xGetPropertyReq *)req;
482
483             REPLY (": XID(0x%x)",
484                 (unsigned int)stuff->window);
485
486             REPLY (" Property");
487             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
488             REPLY (" Type");
489             reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
490
491             if (detail_level >= EVLOG_PRINT_DETAIL)
492             {
493                 REPLY ("\n");
494                 REPLY ("%67s delete(%s) longOffset(%ld) longLength(%ld)",
495                     " ",
496                     stuff->delete ? "YES" : "NO",
497                     (long int)stuff->longOffset,
498                     (long int)stuff->longLength);
499             }
500
501             return reply;
502         }
503
504     case X_SetSelectionOwner:
505         {
506             xSetSelectionOwnerReq *stuff = (xSetSelectionOwnerReq *)req;
507             REPLY (": XID(0x%x)",
508                 (unsigned int)stuff->window);
509
510             REPLY (" Selection");
511             reply = xDbgGetAtom(stuff->selection, evinfo, reply, len);
512
513             if (detail_level >= EVLOG_PRINT_DETAIL)
514             {
515                 REPLY (" time(%lums)",
516                     (unsigned long)stuff->time);
517             }
518
519             return reply;
520         }
521
522     case X_ConvertSelection:
523         {
524             xConvertSelectionReq *stuff = (xConvertSelectionReq *)req;
525             REPLY (": XID(0x%x)",
526                 (unsigned int)stuff->requestor);
527
528             REPLY (" Selection");
529             reply = xDbgGetAtom(stuff->selection, evinfo, reply, len);
530             REPLY (" Target");
531             reply = xDbgGetAtom(stuff->target, evinfo, reply, len);
532             REPLY (" Property");
533             reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
534
535             if (detail_level >= EVLOG_PRINT_DETAIL)
536             {
537                 REPLY (" time(%lums)",
538                     (unsigned long)stuff->time);
539             }
540
541             return reply;
542         }
543
544     case X_SendEvent:
545         {
546             xSendEventReq *stuff = (xSendEventReq *)req;
547             REPLY (": XID(0x%x)",
548                 (unsigned int)stuff->destination);
549
550             if (detail_level >= EVLOG_PRINT_DETAIL)
551             {
552                 REPLY (" propagate(%s)",
553                     stuff->propagate ? "YES" : "NO");
554
555                 REPLY (" event_mask");
556                 REPLY ("(");
557                 reply = _getEventMask(stuff->eventMask, reply, len);
558                 REPLY (")");
559             }
560
561             return reply;
562         }
563
564     case X_GrabPointer:
565         {
566             xGrabPointerReq *stuff = (xGrabPointerReq *)req;
567
568             REPLY (": XID(0x%x) ConfineTo(0x%x) Cursor(0x%x)",
569                 (unsigned int)stuff->grabWindow,
570                 (unsigned int)stuff->confineTo,
571                 (unsigned int)stuff->cursor);
572
573             if (detail_level >= EVLOG_PRINT_DETAIL)
574             {
575                 const char *pointer_mode, *keyboard_mode;
576                 char dpointer_mode[10], dkeyboard_mode[10];
577
578                 switch (stuff->pointerMode)
579                 {
580                     case GrabModeSync:  pointer_mode = "GrabModeSync"; break;
581                     case GrabModeAsync:  pointer_mode = "GrabModeAsync"; break;
582                     default:  pointer_mode = dpointer_mode; snprintf (dpointer_mode, 10, "%d", stuff->pointerMode); break;
583                 }
584
585                 switch (stuff->keyboardMode)
586                 {
587                     case GrabModeSync:  keyboard_mode = "GrabModeSync"; break;
588                     case GrabModeAsync:  keyboard_mode = "GrabModeAsync"; break;
589                     default:  keyboard_mode = dkeyboard_mode; snprintf (dkeyboard_mode, 10, "%d", stuff->keyboardMode); break;
590                 }
591
592                 REPLY (" pointer_mode(%s) keyboard_mode(%s) time(%lums)\n",
593                     pointer_mode,
594                     keyboard_mode,
595                     (unsigned long)stuff->time);
596
597                 REPLY (" event_mask");
598                 REPLY ("(");
599                 reply = _getEventMask(stuff->eventMask, reply, len);
600                 REPLY (")");
601             }
602
603             return reply;
604         }
605
606     case X_GrabButton:
607         {
608             xGrabButtonReq *stuff = (xGrabButtonReq *)req;
609
610             REPLY (": XID(0x%x) ConfineTo(0x%x) Cursor(0x%x)",
611                 (unsigned int)stuff->grabWindow,
612                 (unsigned int)stuff->confineTo,
613                 (unsigned int)stuff->cursor);
614
615             if (detail_level >= EVLOG_PRINT_DETAIL)
616             {
617                 const char *pointer_mode, *keyboard_mode, *button;
618                 char dpointer_mode[10], dkeyboard_mode[10], dbutton[10];
619
620                 switch (stuff->pointerMode)
621                 {
622                     case GrabModeSync:  pointer_mode = "GrabModeSync"; break;
623                     case GrabModeAsync:  pointer_mode = "GrabModeAsync"; break;
624                     default:  pointer_mode = dpointer_mode; snprintf (dpointer_mode, 10, "%d", stuff->pointerMode); break;
625                 }
626
627                 switch (stuff->keyboardMode)
628                 {
629                     case GrabModeSync:  keyboard_mode = "GrabModeSync"; break;
630                     case GrabModeAsync:  keyboard_mode = "GrabModeAsync"; break;
631                     default:  keyboard_mode = dkeyboard_mode; snprintf (dkeyboard_mode, 10, "%d", stuff->keyboardMode); break;
632                 }
633
634                 switch (stuff->button)
635                 {
636                     case Button1:  button = "Button1"; break;
637                     case Button2:  button = "Button2"; break;
638                     case Button3:  button = "Button3"; break;
639                     case Button4:  button = "Button4"; break;
640                     case Button5:  button = "Button5"; break;
641                     default:  button = dbutton; snprintf (dbutton, 10, "%d", stuff->button); break;
642                 }
643
644                 REPLY ("\n");
645                 REPLY ("%67s event_mask(0x%x) pointer_mode(%s) keyboard_mode(%s) button(%s)",
646                     " ",
647                     stuff->eventMask,
648                     pointer_mode,
649                     keyboard_mode,
650                     button);
651
652                 REPLY (" modifiers");
653                 REPLY ("(");
654                 reply = _getKeyMask(stuff->modifiers, reply, len);
655                 REPLY (")");
656             }
657
658             return reply;
659         }
660
661     case X_UngrabButton:
662         {
663             xUngrabButtonReq *stuff = (xUngrabButtonReq *)req;
664             REPLY (": XID(0x%x)",
665                 (unsigned int)stuff->grabWindow);
666
667             if (detail_level >= EVLOG_PRINT_DETAIL)
668             {
669                 REPLY (" modifiers");
670                 REPLY ("(");
671                 reply = _getKeyMask(stuff->modifiers, reply, len);
672                 REPLY (")");
673             }
674
675             return reply;
676         }
677
678     case X_ChangeActivePointerGrab:
679         {
680             xChangeActivePointerGrabReq *stuff = (xChangeActivePointerGrabReq *)req;
681             REPLY (": Cursor(0x%x)",
682                 (unsigned int)stuff->cursor);
683
684             if (detail_level >= EVLOG_PRINT_DETAIL)
685             {
686                 REPLY (" time(%lums)",
687                     (unsigned long)stuff->time);
688
689                 REPLY (" event_mask");
690                 REPLY ("(");
691                 reply = _getEventMask(stuff->eventMask, reply, len);
692                 REPLY (")");
693             }
694
695             return reply;
696         }
697
698     case X_GrabKeyboard:
699         {
700             xGrabKeyboardReq *stuff = (xGrabKeyboardReq *)req;
701
702             REPLY (": XID(0x%x)",
703                 (unsigned int)stuff->grabWindow);
704
705             if (detail_level >= EVLOG_PRINT_DETAIL)
706             {
707                 const char *pointer_mode, *keyboard_mode;
708                 char dpointer_mode[10], dkeyboard_mode[10];
709
710                 switch (stuff->pointerMode)
711                 {
712                     case GrabModeSync:  pointer_mode = "GrabModeSync"; break;
713                     case GrabModeAsync:  pointer_mode = "GrabModeAsync"; break;
714                     default:  pointer_mode = dpointer_mode; snprintf (dpointer_mode, 10, "%d", stuff->pointerMode); break;
715                 }
716
717                 switch (stuff->keyboardMode)
718                 {
719                     case GrabModeSync:  keyboard_mode = "GrabModeSync"; break;
720                     case GrabModeAsync:  keyboard_mode = "GrabModeAsync"; break;
721                     default:  keyboard_mode = dkeyboard_mode; snprintf (dkeyboard_mode, 10, "%d", stuff->keyboardMode); break;
722                 }
723
724                 REPLY (" owner_events(%s) pointer_mode(%s) keyboard_mode(%s)",
725                     stuff->ownerEvents ? "YES" : "NO",
726                     pointer_mode,
727                     keyboard_mode);
728             }
729
730             return reply;
731         }
732
733     case X_GrabKey:
734         {
735             xGrabKeyReq *stuff = (xGrabKeyReq *)req;
736
737             REPLY (": XID(0x%x)",
738                 (unsigned int)stuff->grabWindow);
739
740             if (detail_level >= EVLOG_PRINT_DETAIL)
741             {
742                 const char *pointer_mode, *keyboard_mode;
743                 char dpointer_mode[10], dkeyboard_mode[10];
744
745                 switch (stuff->pointerMode)
746                 {
747                     case GrabModeSync:  pointer_mode = "GrabModeSync"; break;
748                     case GrabModeAsync:  pointer_mode = "GrabModeAsync"; break;
749                     default:  pointer_mode = dpointer_mode; snprintf (dpointer_mode, 10, "%d", stuff->pointerMode); break;
750                 }
751
752                 switch (stuff->keyboardMode)
753                 {
754                     case GrabModeSync:  keyboard_mode = "GrabModeSync"; break;
755                     case GrabModeAsync:  keyboard_mode = "GrabModeAsync"; break;
756                     default:  keyboard_mode = dkeyboard_mode; snprintf (dkeyboard_mode, 10, "%d", stuff->keyboardMode); break;
757                 }
758
759                 REPLY (" key(%d) pointer_mode(%s) keyboard_mode(%s)\n",
760                     stuff->key,
761                     pointer_mode,
762                     keyboard_mode);
763
764                 REPLY (" modifiers");
765                 REPLY ("(");
766                 reply = _getKeyMask(stuff->modifiers, reply, len);
767                 REPLY (")");
768             }
769
770             return reply;
771         }
772
773     case X_UngrabKey:
774         {
775             xUngrabKeyReq *stuff = (xUngrabKeyReq *)req;
776             REPLY (": XID(0x%x)",
777                 (unsigned int)stuff->grabWindow);
778
779             if (detail_level >= EVLOG_PRINT_DETAIL)
780             {
781                 REPLY (" key(%d)",
782                     stuff->key);
783
784                 REPLY (" modifiers");
785                 REPLY ("(");
786                 reply = _getKeyMask(stuff->modifiers, reply, len);
787                 REPLY (")");
788             }
789
790             return reply;
791         }
792
793     case X_SetInputFocus:
794         {
795             xSetInputFocusReq *stuff = (xSetInputFocusReq *)req;
796             REPLY (": XID(0x%x)",
797                 (unsigned int)stuff->focus);
798
799             if (detail_level >= EVLOG_PRINT_DETAIL)
800             {
801                 REPLY (" reverTo(%d) time(%lums)",
802                     stuff->revertTo,
803                     (unsigned long)stuff->time);
804             }
805
806             return reply;
807         }
808
809     case X_CreatePixmap:
810         {
811             xCreatePixmapReq *stuff = (xCreatePixmapReq *)req;
812             REPLY (": Pixmap(0x%x) Drawable(0x%x) size(%dx%d)",
813                 (unsigned int)stuff->pid,
814                 (unsigned int)stuff->drawable,
815                 stuff->width,
816                 stuff->height);
817
818             if (detail_level >= EVLOG_PRINT_DETAIL)
819             {
820                 REPLY (" depth(%d)",
821                     stuff->depth);
822             }
823
824             return reply;
825         }
826
827     case X_CreateGC:
828         {
829             xCreateGCReq *stuff = (xCreateGCReq *)req;
830             REPLY (": Gc(0x%x) Drawable(0x%x)",
831                 (unsigned int)stuff->gc,
832                 (unsigned int)stuff->drawable);
833
834             return reply;
835         }
836
837     case X_ClearArea:
838         {
839             xClearAreaReq *stuff = (xClearAreaReq *)req;
840             REPLY (": XID(0x%x) area(%d,%d %dx%d)",
841                 (unsigned int)stuff->window,
842                 stuff->x,
843                 stuff->y,
844                 stuff->width,
845                 stuff->height);
846
847             if (detail_level >= EVLOG_PRINT_DETAIL)
848             {
849                 REPLY (" exposures(%s)",
850                     stuff->exposures ? "YES" : "NO");
851             }
852
853         \r   return reply;
854         }
855
856     case X_CopyArea:
857         {
858             xCopyAreaReq *stuff = (xCopyAreaReq *)req;
859             REPLY (": srcXID(0x%x) dstXID(0x%x) gc(0x%x) size(%dx%d) src(%d,%d) dst(%d,%d)",
860                 (unsigned int)stuff->srcDrawable,
861                 (unsigned int)stuff->dstDrawable,
862                 (unsigned int)stuff->gc,
863                 stuff->width,
864                 stuff->height,
865                 stuff->srcX,
866                 stuff->srcY,
867                 stuff->dstX,
868                 stuff->dstY);
869
870             return reply;
871         }
872
873     case X_CopyPlane:
874         {
875             xCopyPlaneReq *stuff = (xCopyPlaneReq *)req;
876             REPLY (": srcXID(0x%x) dstXID(0x%x) gc(0x%x) size(%dx%d) src(%d,%d) dst(%d,%d)",
877                 (unsigned int)stuff->srcDrawable,
878                 (unsigned int)stuff->dstDrawable,
879                 (unsigned int)stuff->gc,
880                 stuff->width,
881                 stuff->height,
882                 stuff->srcX,
883                 stuff->srcY,
884                 stuff->dstX,
885                 stuff->dstY);
886
887             if (detail_level >= EVLOG_PRINT_DETAIL)
888             {
889                 REPLY (" bit_plane(0x%x)",
890                     (unsigned int)stuff->bitPlane);
891             }
892
893             return reply;
894         }
895
896     case X_PolyPoint:
897         {
898             xPolyPointReq *stuff = (xPolyPointReq *)req;
899             REPLY (": XID(0x%x) gc(0x%x)",
900                 (unsigned int)stuff->drawable,
901                 (unsigned int)stuff->gc);
902
903             if (detail_level >= EVLOG_PRINT_DETAIL)
904             {
905                 const char *coord_mode;
906                 char dcoord_mode[10];
907
908                 switch (stuff->coordMode)
909                 {
910                     case CoordModeOrigin:  coord_mode = "CoordModeOrigin"; break;
911                     case CoordModePrevious:  coord_mode = "CoordModePrevious"; break;
912                     default:  coord_mode = dcoord_mode; snprintf (dcoord_mode, 10, "%d", stuff->coordMode); break;
913                 }
914
915                 REPLY (" coord_mode(%s)",
916                     coord_mode);
917             }
918
919             return reply;
920         }
921
922     case X_PolyLine:
923         {
924             xPolyLineReq *stuff = (xPolyLineReq *)req;
925             REPLY (": XID(0x%x gc(0x%x)",
926                 (unsigned int)stuff->drawable,
927                 (unsigned int)stuff->gc);
928
929             if (detail_level >= EVLOG_PRINT_DETAIL)
930             {
931                 const char *coord_mode;
932                 char dcoord_mode[10];
933
934                 switch (stuff->coordMode)
935                 {
936                     case CoordModeOrigin:  coord_mode = "CoordModeOrigin"; break;
937                     case CoordModePrevious:  coord_mode = "CoordModePrevious"; break;
938                     default:  coord_mode = dcoord_mode; snprintf (dcoord_mode, 10, "%d", stuff->coordMode); break;
939                 }
940
941                 REPLY (" coord_mode(%s)",
942                     coord_mode);
943             }
944
945             return reply;
946         }
947
948     case X_PolySegment:
949         {
950             xPolySegmentReq *stuff = (xPolySegmentReq *)req;
951             REPLY (": XID(0x%x) gc(0x%x)",
952                 (unsigned int)stuff->drawable,
953                 (unsigned int)stuff->gc);
954
955             return reply;
956         }
957
958     case X_PolyRectangle:
959         {
960             xPolyRectangleReq *stuff = (xPolyRectangleReq *)req;
961             REPLY (": XID(0x%x) gc(0x%x)",
962                 (unsigned int)stuff->drawable,
963                 (unsigned int)stuff->gc);
964
965             return reply;
966         }
967
968     case X_PolyArc:
969         {
970             xPolyArcReq *stuff = (xPolyArcReq *)req;
971             REPLY (": XID(0x%x) gc(0x%x)",
972                 (unsigned int)stuff->drawable,
973                 (unsigned int)stuff->gc);
974
975             return reply;
976         }
977
978     case X_FillPoly:
979         {
980             xFillPolyReq *stuff = (xFillPolyReq *)req;
981             REPLY (": XID(0x%x) gc(0x%x)",
982                 (unsigned int)stuff->drawable,
983                 (unsigned int)stuff->gc);
984
985             if (detail_level >= EVLOG_PRINT_DETAIL)
986             {
987                 const char *shape, *coord_mode;
988                 char dshape[10], dcoord_mode[10];
989
990                 switch (stuff->shape)
991                 {
992                     case Complex:  shape = "Complex"; break;
993                     case Nonconvex:  shape = "Nonconvex"; break;
994                     case Convex:  shape = "Convex"; break;
995                     default:  shape = dshape; snprintf (dshape, 10, "%d", stuff->shape); break;
996                 }
997
998                 switch (stuff->coordMode)
999                 {
1000                     case CoordModeOrigin:  coord_mode = "CoordModeOrigin"; break;
1001                     case CoordModePrevious:  coord_mode = "CoordModePrevious"; break;
1002                     default:  coord_mode = dcoord_mode; snprintf (dcoord_mode, 10, "%d", stuff->coordMode); break;
1003                 }
1004
1005                 REPLY (" shape(%s) coord_mode(%s)",
1006                     shape,
1007                     coord_mode);
1008             }
1009
1010             return reply;
1011         }
1012
1013     case X_PolyFillRectangle:
1014         {
1015             xPolyFillRectangleReq *stuff = (xPolyFillRectangleReq *)req;
1016             REPLY (": XID(0x%x) gc(0x%x)",
1017                 (unsigned int)stuff->drawable,
1018                 (unsigned int)stuff->gc);
1019
1020             return reply;
1021         }
1022
1023     case X_PolyFillArc:
1024         {
1025             xPolyFillArcReq *stuff = (xPolyFillArcReq *)req;
1026             REPLY (": XID(0x%x) gc(0x%x)",
1027                 (unsigned int)stuff->drawable,
1028                 (unsigned int)stuff->gc);
1029
1030             return reply;
1031         }
1032
1033     case X_PutImage:
1034         {
1035             xPutImageReq *stuff = (xPutImageReq *)req;
1036             REPLY (": XID(0x%x) gc(0x%x) size(%dx%d) dst(%d,%d)",
1037                 (unsigned int)stuff->drawable,
1038                 (unsigned int)stuff->gc,
1039                 stuff->width,
1040                 stuff->height,
1041                 stuff->dstX,
1042                 stuff->dstY);
1043
1044             if (detail_level >= EVLOG_PRINT_DETAIL)
1045             {
1046                 const char *format;
1047                 char dformat[10];
1048
1049                 switch (stuff->format)
1050                 {
1051                     case XYBitmap:  format = "XYBitmap"; break;
1052                     case XYPixmap:  format = "XYPixmap"; break;
1053                     case ZPixmap:  format = "ZPixmap"; break;
1054                     default:  format = dformat; snprintf (dformat, 10, "%d", stuff->format); break;
1055                 }
1056
1057                 REPLY (" format(%s) depth(%d)",
1058                     format,
1059                     stuff->depth);
1060             }
1061
1062             return reply;
1063         }
1064
1065     case X_GetImage:
1066         {
1067             xGetImageReq *stuff = (xGetImageReq *)req;
1068             REPLY (": XID(0x%x) size(%dx%d) dst(%d,%d)",
1069                 (unsigned int)stuff->drawable,
1070                 stuff->width,
1071                 stuff->height,
1072                 stuff->x,
1073                 stuff->y);
1074
1075             if (detail_level >= EVLOG_PRINT_DETAIL)
1076             {
1077                 const char *format;
1078                 char dformat[10];
1079
1080                 switch (stuff->format)
1081                 {
1082                     case XYBitmap:  format = "XYBitmap"; break;
1083                     case XYPixmap:  format = "XYPixmap"; break;
1084                     case ZPixmap:  format = "ZPixmap"; break;
1085                     default:  format = dformat; snprintf (dformat, 10, "%d", stuff->format); break;
1086                 }
1087
1088                 REPLY (" format(%s) plane_mask(0x%x)",
1089                     format,
1090                     (unsigned int)stuff->planeMask);
1091             }
1092
1093             return reply;
1094         }
1095
1096     case X_PolyText8:
1097         {
1098             xPolyText8Req *stuff = (xPolyText8Req *)req;
1099             REPLY (": XID(0x%x) gc(0x%x) coord(%d,%d)",
1100                 (unsigned int)stuff->drawable,
1101                 (unsigned int)stuff->gc,
1102                 stuff->x,
1103                 stuff->y);
1104
1105             return reply;
1106         }
1107
1108     case X_PolyText16:
1109         {
1110             xPolyText16Req *stuff = (xPolyText16Req *)req;
1111             REPLY (": XID(0x%x) gc(0x%x) coord(%d,%d)",
1112                 (unsigned int)stuff->drawable,
1113                 (unsigned int)stuff->gc,
1114                 stuff->x,
1115                 stuff->y);
1116
1117             return reply;
1118         }
1119
1120     case X_ImageText8:
1121         {
1122             xImageText8Req *stuff = (xImageText8Req *)req;
1123             REPLY (": XID(0x%x) gc(0x%x) coord(%d,%d)",
1124                 (unsigned int)stuff->drawable,
1125                 (unsigned int)stuff->gc,
1126                 stuff->x,
1127                 stuff->y);
1128
1129             if (detail_level >= EVLOG_PRINT_DETAIL)
1130             {
1131                 REPLY (" nchars(%d)",
1132                     stuff->nChars);
1133             }
1134
1135             return reply;
1136         }
1137
1138     case X_ImageText16:
1139         {
1140             xImageText16Req *stuff = (xImageText16Req *)req;
1141             REPLY (": XID(0x%x) gc(0x%x) coord(%d,%d)",
1142                 (unsigned int)stuff->drawable,
1143                 (unsigned int)stuff->gc,
1144                 stuff->x,
1145                 stuff->y);
1146
1147             if (detail_level >= EVLOG_PRINT_DETAIL)
1148             {
1149                 REPLY (" nchars(%d)",
1150                     stuff->nChars);
1151             }
1152
1153             return reply;
1154         }
1155
1156     case X_ChangeKeyboardMapping:
1157         {
1158             xChangeKeyboardMappingReq *stuff = (xChangeKeyboardMappingReq *)req;
1159             REPLY (": first_key_code(%d) key_syms_per_key_code(%d)",
1160                 stuff->firstKeyCode,
1161                 stuff->keySymsPerKeyCode);
1162
1163             if (detail_level >= EVLOG_PRINT_DETAIL)
1164             {
1165                 REPLY (" key_codes(%d)",
1166                     stuff->keyCodes);
1167             }
1168
1169             return reply;
1170         }
1171
1172     case X_GetKeyboardMapping:
1173         {
1174             xGetKeyboardMappingReq *stuff = (xGetKeyboardMappingReq *)req;
1175             REPLY (": first_key_code(%d)",
1176                 stuff->firstKeyCode);
1177
1178             if (detail_level >= EVLOG_PRINT_DETAIL)
1179             {
1180                 REPLY (" count(%d)",
1181                     stuff->count);
1182             }
1183
1184             return reply;
1185         }
1186
1187     case X_ChangePointerControl:
1188         {
1189             xChangePointerControlReq *stuff = (xChangePointerControlReq *)req;
1190             REPLY (": accelNum(%d) accelDenum(%d) threshold(%d)",
1191                 stuff->accelNum,
1192                 stuff->accelDenum,
1193                 stuff->threshold);
1194
1195             if (detail_level >= EVLOG_PRINT_DETAIL)
1196             {
1197                 REPLY (" do_accel(%s) do_thresh(%s)",
1198                     stuff->doAccel ? "YES" : "NO",
1199                     stuff->doThresh ? "YES" : "NO");
1200             }
1201
1202             return reply;
1203         }
1204
1205     case X_SetPointerMapping:
1206         {
1207             xSetPointerMappingReq *stuff = (xSetPointerMappingReq *)req;
1208
1209             if (detail_level >= EVLOG_PRINT_DETAIL)
1210             {
1211                 REPLY (": Elts(%d)",
1212                     stuff->nElts);
1213             }
1214
1215             return reply;
1216         }
1217
1218     case X_SetModifierMapping:
1219         {
1220             xSetModifierMappingReq *stuff =(xSetModifierMappingReq *)req;
1221             REPLY (": num_key_per_modifier(%d)",
1222                 stuff->numKeyPerModifier);
1223
1224             return reply;
1225         }
1226
1227     case X_ListProperties:
1228     case X_DestroyWindow:
1229     case X_DestroySubwindows:
1230     case X_MapWindow:
1231     case X_MapSubwindows:
1232     case X_UnmapWindow:
1233     case X_UnmapSubwindows:
1234     case X_GetGeometry:
1235     case X_QueryTree:
1236     case X_UngrabPointer:
1237     case X_UngrabKeyboard:
1238     case X_FreePixmap:
1239     case X_KillClient:
1240     case X_FreeGC:
1241         {
1242             xResourceReq *stuff = (xResourceReq *)req;
1243             REPLY (": XID(0x%x)",
1244                 (unsigned int)stuff->id);
1245
1246             return reply;
1247         }
1248
1249     default:
1250             break;
1251     }
1252
1253     return reply;
1254 }
1255
1256 char * xDbgEvlogEventCore (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
1257 {
1258     xEvent *evt = evinfo->evt.ptr;
1259
1260     switch (evt->u.u.type & 0x7F)
1261     {
1262     case KeyPress:
1263     case KeyRelease:
1264     case ButtonPress:
1265     case ButtonRelease:
1266     case MotionNotify:
1267         {
1268             REPLY (": Root(0x%x %d,%d) Event(0x%x %d,%d) Child(0x%x)",
1269                 (unsigned int)evt->u.keyButtonPointer.root,
1270                 evt->u.keyButtonPointer.rootX,
1271                 evt->u.keyButtonPointer.rootY,
1272                 (unsigned int)evt->u.keyButtonPointer.event,
1273                 evt->u.keyButtonPointer.eventX,
1274                 evt->u.keyButtonPointer.eventY,
1275                 (unsigned int)evt->u.keyButtonPointer.child);
1276
1277             if (detail_level >= EVLOG_PRINT_DETAIL)
1278             {
1279                 REPLY ("\n");
1280                 REPLY ("%67s state(0x%x) same_screen(%s)",
1281                     " ",
1282                     evt->u.keyButtonPointer.state,
1283                     evt->u.keyButtonPointer.sameScreen ? "YES" : "NO");
1284             }
1285
1286             return reply;
1287         }
1288
1289     case EnterNotify:
1290     case LeaveNotify:
1291         {
1292             REPLY (": Root(0x%x %d,%d) Event(0x%x %d,%d) Child(0x%x)",
1293                 (unsigned int)evt->u.enterLeave.root,
1294                 evt->u.enterLeave.rootX,
1295                 evt->u.enterLeave.rootY,
1296                 (unsigned int)evt->u.enterLeave.event,
1297                 evt->u.enterLeave.eventX,
1298                 evt->u.enterLeave.eventY,
1299                 (unsigned int)evt->u.enterLeave.child);
1300
1301             if (detail_level >= EVLOG_PRINT_DETAIL)
1302             {
1303                 REPLY ("\n");
1304                 REPLY ("%67s time(%lums) state(0x%x) same_screen(%s) focus(%s)",
1305                     " ",
1306                     (unsigned long)evt->u.enterLeave.time,
1307                     evt->u.enterLeave.state,
1308                     evt->u.enterLeave.flags & ELFlagSameScreen ? "YES" : "NO",
1309                     evt->u.enterLeave.flags & ELFlagFocus ? "YES" : "NO");
1310             }
1311
1312             return reply;
1313         }
1314
1315     case FocusIn:
1316     case FocusOut:
1317     case KeymapNotify:
1318         {
1319             REPLY (": XID(0x%x)",
1320                 (unsigned int)evt->u.focus.window);
1321
1322             if (detail_level >= EVLOG_PRINT_DETAIL)
1323             {
1324                 const char* mode;
1325                 char dmode[10];
1326
1327                 switch (evt->u.focus.mode)
1328                 {
1329                     case NotifyNormal:  mode = "NotifyNormal"; break;
1330                     case NotifyGrab:  mode = "NotifyGrab"; break;
1331                     case NotifyUngrab:  mode = "NotifyUngrab"; break;
1332                     case NotifyWhileGrabbed:  mode = "NotifyWhileGrabbed"; break;
1333                     default:  mode = dmode, snprintf (dmode, 10, "%u", evt->u.focus.mode); break;
1334                 }
1335
1336                 REPLY (" mode(%s)",
1337                     mode);
1338             }
1339
1340             return reply;
1341         }
1342
1343     case Expose:
1344         {
1345             REPLY (": XID(0x%x) size(%dx%d) coord(%d,%d)",
1346                 (unsigned int)evt->u.expose.window,
1347                 evt->u.expose.width,
1348                 evt->u.expose.height,
1349                 evt->u.expose.x,
1350                 evt->u.expose.y);
1351
1352             if (detail_level >= EVLOG_PRINT_DETAIL)
1353             {
1354                 REPLY (" count(%d)",
1355                     evt->u.expose.count);
1356             }
1357
1358             return reply;
1359         }
1360
1361     case GraphicsExpose:
1362         {
1363             REPLY (": XID(0x%x) size(%dx%d) coord(%d,%d)",
1364                 (unsigned int)evt->u.graphicsExposure.drawable,
1365                 evt->u.graphicsExposure.width,
1366                 evt->u.graphicsExposure.height,
1367                 evt->u.graphicsExposure.x,
1368                 evt->u.graphicsExposure.y);
1369
1370             if (detail_level >= EVLOG_PRINT_DETAIL)
1371             {
1372                 const char *major;
1373                 char dmajor[10];
1374
1375                 switch (evt->u.graphicsExposure.majorEvent)
1376                 {
1377                     case X_CopyArea:  major = "CopyArea";  break;
1378                     case X_CopyPlane:  major = "CopyPlane";  break;
1379                     default: major = dmajor; snprintf (dmajor, 10, "%d", evt->u.graphicsExposure.majorEvent); break;
1380                 }
1381
1382                 REPLY (" major_event(%s) minor_event(%d) count(%d)",
1383                     major,
1384                     evt->u.graphicsExposure.minorEvent,
1385                     evt->u.graphicsExposure.count);
1386             }
1387
1388             return reply;
1389         }
1390
1391     case NoExpose:
1392         {
1393             REPLY (": XID(0x%x)",
1394                 (unsigned int)evt->u.noExposure.drawable);
1395
1396             if (detail_level >= EVLOG_PRINT_DETAIL)
1397             {
1398                 const char *major;
1399                 char dmajor[10];
1400
1401                 switch (evt->u.noExposure.majorEvent)
1402                 {
1403                     case X_CopyArea:  major = "CopyArea";  break;
1404                     case X_CopyPlane:  major = "CopyPlane";  break;
1405                     default:  major = dmajor; snprintf (dmajor, 10, "%d", evt->u.noExposure.majorEvent); break;
1406                 }
1407
1408                 REPLY (" major_event(%s) minor_event(%d)",
1409                     major,
1410                     evt->u.noExposure.minorEvent);
1411             }
1412
1413             return reply;
1414         }
1415
1416     case VisibilityNotify:
1417         {
1418             REPLY (": XID(0x%x)",
1419                 (unsigned int)evt->u.visibility.window);
1420
1421             if (detail_level >= EVLOG_PRINT_DETAIL)
1422             {
1423                 const char *state;
1424                 char dstate[10];
1425
1426                 switch (evt->u.visibility.state)
1427                 {
1428                     case VisibilityUnobscured:  state = "VisibilityUnobscured"; break;
1429                     case VisibilityPartiallyObscured:  state = "VisibilityPartiallyObscured"; break;
1430                     case VisibilityFullyObscured:  state = "VisibilityFullyObscured"; break;
1431                     default:  state = dstate; snprintf (dstate, 10, "%d", evt->u.visibility.state); break;
1432                 }
1433
1434                 REPLY (" state(%s)",
1435                     state);
1436             }
1437
1438             return reply;
1439         }
1440
1441     case CreateNotify:
1442         {
1443             REPLY (": Window(0x%x) Parent(0x%x) size(%dx%d) coord(%d,%d) borderWidth(%d)",
1444                 (unsigned int)evt->u.createNotify.window,
1445                 (unsigned int)evt->u.createNotify.parent,
1446                 evt->u.createNotify.width,
1447                 evt->u.createNotify.height,
1448                 evt->u.createNotify.x,
1449                 evt->u.createNotify.y,
1450                 evt->u.createNotify.borderWidth);
1451
1452             if (detail_level >= EVLOG_PRINT_DETAIL)
1453             {
1454                 REPLY (" override(%s)",
1455                     evt->u.createNotify.override ? "YES" : "NO");
1456             }
1457
1458             return reply;
1459         }
1460
1461     case DestroyNotify:
1462         {
1463             REPLY (": Window(0x%x) Event(0x%x)",
1464                 (unsigned int)evt->u.destroyNotify.window,
1465                 (unsigned int)evt->u.destroyNotify.event);
1466
1467             return reply;
1468                 }
1469
1470     case UnmapNotify:
1471         {
1472             REPLY (": Window(0x%x) Event(0x%x)",
1473                 (unsigned int)evt->u.unmapNotify.window,
1474                 (unsigned int)evt->u.unmapNotify.event);
1475
1476             if (detail_level >= EVLOG_PRINT_DETAIL)
1477             {
1478                 REPLY (" from_Configure(%s)",
1479                     evt->u.unmapNotify.fromConfigure ? "YES" : "NO");
1480             }
1481
1482             return reply;
1483         }
1484
1485     case MapNotify:
1486         {
1487             REPLY (": Window(0x%x) Event(0x%x)",
1488                 (unsigned int)evt->u.mapNotify.window,
1489                 (unsigned int)evt->u.mapNotify.event);
1490
1491             if (detail_level >= EVLOG_PRINT_DETAIL)
1492             {
1493                 REPLY (" override(%s)",
1494                     evt->u.mapNotify.override ? "YES" : "NO");
1495             }
1496
1497             return reply;
1498         }
1499
1500     case MapRequest:
1501         {
1502             REPLY (": Window(0x%x) Parent(0x%x)",
1503                 (unsigned int)evt->u.mapRequest.window,
1504                 (unsigned int)evt->u.mapRequest.parent);
1505
1506             return reply;
1507         }
1508
1509     case ReparentNotify:
1510         {
1511             REPLY (": Window(0x%x) Event(0x%x) Parent(0x%x) coord(%d,%d)",
1512                 (unsigned int)evt->u.reparent.window,
1513                 (unsigned int)evt->u.reparent.event,
1514                 (unsigned int)evt->u.reparent.parent,
1515                 evt->u.reparent.x,
1516                 evt->u.reparent.y);
1517
1518             if (detail_level >= EVLOG_PRINT_DETAIL)
1519             {
1520                 REPLY (" override(%s)",
1521                     evt->u.reparent.override ? "YES" : "NO");
1522             }
1523
1524             return reply;
1525         }
1526
1527     case ConfigureNotify:
1528         {
1529             REPLY (": Window(0x%x) Event(0x%x) AboveSibling(0x%x) size(%dx%d) coord(%d,%d) borderWidth(%d)",
1530                 (unsigned int)evt->u.configureNotify.window,
1531                 (unsigned int)evt->u.configureNotify.event,
1532                 (unsigned int)evt->u.configureNotify.aboveSibling,
1533                 evt->u.configureNotify.width,
1534                 evt->u.configureNotify.height,
1535                 evt->u.configureNotify.x,
1536                 evt->u.configureNotify.y,
1537                 evt->u.configureNotify.borderWidth);
1538
1539             if (detail_level >= EVLOG_PRINT_DETAIL)
1540             {
1541                 REPLY (" override(%s)",
1542                     evt->u.configureNotify.override ? "YES" : "NO");
1543             }
1544
1545             return reply;
1546         }
1547
1548     case ConfigureRequest:
1549         {
1550             REPLY (": Window(0x%x) Parent(0x%x) Sibling(0x%x) size(%dx%d) coord(%d,%d) borderWidth(%d)",
1551                 (unsigned int)evt->u.configureRequest.window,
1552                 (unsigned int)evt->u.configureRequest.parent,
1553                 (unsigned int)evt->u.configureRequest.sibling,
1554                 evt->u.configureRequest.width,
1555                 evt->u.configureRequest.height,
1556                 evt->u.configureRequest.x,
1557                 evt->u.configureRequest.y,
1558                 evt->u.configureRequest.borderWidth);
1559
1560             if (detail_level >= EVLOG_PRINT_DETAIL)
1561             {
1562                 REPLY ("\n");
1563                 REPLY ("%67s value_mask",
1564                     " ");
1565                 REPLY ("(");
1566                 reply = _getConfigureWindowMask(evt->u.configureRequest.valueMask, reply, len, NULL);
1567                 REPLY (")");
1568             }
1569
1570             return reply;
1571         }
1572
1573     case GravityNotify:
1574         {
1575             REPLY (": Window(0x%x) Event(0x%x) coord(%d,%d)",
1576                 (unsigned int)evt->u.gravity.window,
1577                 (unsigned int)evt->u.gravity.event,
1578                 evt->u.gravity.x,
1579                 evt->u.gravity.y);
1580
1581             return reply;
1582         }
1583
1584     case ResizeRequest:
1585         {
1586             REPLY (": Window(0x%x) size(%dx%d)",
1587                 (unsigned int)evt->u.resizeRequest.window,
1588                 evt->u.resizeRequest.width,
1589                 evt->u.resizeRequest.height);
1590
1591             return reply;
1592         }
1593
1594     case CirculateNotify:
1595     case CirculateRequest:
1596         {
1597             REPLY (": Window(0x%x) Event(0x%x) parent(0x%x)",
1598                 (unsigned int)evt->u.circulate.window,
1599                 (unsigned int)evt->u.circulate.event,
1600                 (unsigned int)evt->u.circulate.parent);
1601
1602             if (detail_level >= EVLOG_PRINT_DETAIL)
1603             {
1604                 const char *place;
1605                 char dplace[10];
1606
1607                 switch (evt->u.circulate.place)
1608                 {
1609                     case PlaceOnTop:  place = "PlaceOnTop"; break;
1610                     case PlaceOnBottom:  place = "PlaceOnBottom"; break;
1611                     default:  place = dplace; snprintf (dplace, 10, "%d", evt->u.circulate.place); break;
1612                 }
1613
1614                 REPLY (" place(%s)",
1615                     place);
1616             }
1617
1618             return reply;
1619         }
1620
1621     case PropertyNotify:
1622         {
1623             REPLY (": Window(0x%x)",
1624                 (unsigned int)evt->u.property.window);
1625
1626             REPLY (" Property");
1627             reply = xDbgGetAtom(evt->u.property.atom, evinfo, reply, len);
1628
1629             if (detail_level >= EVLOG_PRINT_DETAIL)
1630             {
1631                 const char *state;
1632                 char dstate[10];
1633
1634                 switch (evt->u.property.state)
1635                 {
1636                     case PropertyNewValue:  state = "PropertyNewValue"; break;
1637                     case PropertyDelete:  state = "PropertyDelete"; break;
1638                     default:  state = dstate; snprintf (dstate, 10, "%d", evt->u.property.state); break;
1639                 }
1640
1641                 REPLY ("\n");
1642                 REPLY ("%67s time(%lums) state(%s)",
1643                     " ",
1644                     (unsigned long)evt->u.property.time,
1645                     state);
1646             }
1647
1648             return reply;
1649         }
1650
1651     case SelectionClear:
1652         {
1653             REPLY (": Window(0x%x)",
1654                 (unsigned int)evt->u.selectionClear.window);
1655
1656             REPLY (" Atom");
1657             reply = xDbgGetAtom(evt->u.selectionClear.atom, evinfo, reply, len);
1658
1659             if (detail_level >= EVLOG_PRINT_DETAIL)
1660             {
1661                 REPLY (" time(%lums)",
1662                     (unsigned long)evt->u.selectionClear.time);
1663             }
1664
1665             return reply;
1666                 }
1667
1668     case SelectionRequest:
1669         {
1670             REPLY (": Owner(0x%x) Requestor(0x%x)",
1671                 (unsigned int)evt->u.selectionRequest.owner,
1672                 (unsigned int)evt->u.selectionRequest.requestor);
1673
1674             REPLY (" selection");
1675             reply = xDbgGetAtom(evt->u.selectionRequest.selection, evinfo, reply, len);
1676             REPLY (" Target");
1677             reply = xDbgGetAtom(evt->u.selectionRequest.target, evinfo, reply, len);
1678             REPLY (" Property");
1679             reply = xDbgGetAtom(evt->u.selectionRequest.property, evinfo, reply, len);
1680
1681             if (detail_level >= EVLOG_PRINT_DETAIL)
1682             {
1683                 REPLY (" time(%lums)",
1684                     (unsigned long)evt->u.selectionRequest.time);
1685             }
1686
1687             return reply;
1688         }
1689
1690     case SelectionNotify:
1691         {
1692             REPLY (": Requestor(0x%x)",
1693                 (unsigned int)evt->u.selectionNotify.requestor);
1694
1695             REPLY (" selection");
1696             reply = xDbgGetAtom(evt->u.selectionNotify.selection, evinfo, reply, len);
1697             REPLY (" Target");
1698             reply = xDbgGetAtom(evt->u.selectionNotify.target, evinfo, reply, len);
1699             REPLY (" Property");
1700             reply = xDbgGetAtom(evt->u.selectionNotify.property, evinfo, reply, len);
1701
1702             if (detail_level >= EVLOG_PRINT_DETAIL)
1703             {
1704                 REPLY (" time(%lums)",
1705                     (unsigned long)evt->u.selectionNotify.time);
1706             }
1707
1708             return reply;
1709         }
1710
1711     case ColormapNotify:
1712         {
1713             REPLY (": XID(0x%x) Colormap(0x%x)",
1714                 (unsigned int)evt->u.colormap.window,
1715                 (unsigned int)evt->u.colormap.colormap);
1716
1717             if (detail_level >= EVLOG_PRINT_DETAIL)
1718             {
1719                 const char *state;
1720                 char dstate[10];
1721
1722                 switch (evt->u.colormap.state)
1723                 {
1724                     case ColormapInstalled:  state = "ColormapInstalled"; break;
1725                     case ColormapUninstalled:  state = "ColormapUninstalled"; break;
1726                     default: state = dstate; snprintf (dstate, 10, "%d", evt->u.colormap.state); break;
1727                 }
1728
1729                 REPLY (" new(%s) state(%s)",
1730                     evt->u.colormap.new ? "YES" : "NO",
1731                     state);
1732             }
1733
1734             return reply;
1735         }
1736
1737     case ClientMessage:
1738         {
1739             REPLY (": XID(0x%x)",
1740                 (unsigned int)evt->u.clientMessage.window);
1741
1742             REPLY (" Type");
1743             reply = xDbgGetAtom(evt->u.clientMessage.u.b.type, evinfo, reply, len);
1744
1745             return reply;
1746                 }
1747
1748     case MappingNotify:
1749     case GenericEvent:
1750     default:
1751             break;
1752     }
1753
1754     return reply;
1755 }
1756
1757 char * xDbgEvlogReplyCore (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
1758 {
1759     xGenericReply *rep = evinfo->rep.ptr;
1760
1761     switch (evinfo->rep.reqType)
1762     {
1763     case X_GetGeometry:
1764         {
1765             if (evinfo->rep.isStart)
1766             {
1767                 xGetGeometryReply *stuff = (xGetGeometryReply *)rep;
1768
1769                 REPLY (": XID(0x%x) coord(%d,%d %dx%d) borderWidth(%d)",
1770                     (unsigned int)stuff->root,
1771                     stuff->x,
1772                     stuff->y,
1773                     stuff->width,
1774                     stuff->height,
1775                     stuff->borderWidth);
1776             }
1777             else
1778             {
1779                 return reply;
1780             }
1781
1782             return reply;
1783         }
1784
1785     case X_QueryTree:
1786         {
1787             if (evinfo->rep.isStart)
1788             {
1789                 xQueryTreeReply *stuff = (xQueryTreeReply *)rep;
1790
1791                 REPLY (": XID(0x%x) Parent(0x%x) ChildrenNum(%d)",
1792                     (unsigned int)stuff->root,
1793                     (unsigned int)stuff->parent,
1794                     stuff->nChildren);
1795             }
1796             else
1797             {
1798                 Window *stuff = (Window *)rep;
1799                 int i;
1800
1801                 REPLY ("childIDs");
1802                 REPLY ("(");
1803                 for (i = 0 ; i < evinfo->rep.size / sizeof(Window) ; i++)
1804                 {
1805                     REPLY("0x%x", (unsigned int)stuff[i]);
1806                     if(i != evinfo->rep.size / sizeof(Window) - 1)
1807                         REPLY (", ");
1808                 }
1809                 REPLY (")");
1810             }
1811
1812             return reply;
1813         }
1814
1815     case X_GetProperty:
1816         {
1817             if (evinfo->rep.isStart)
1818             {
1819                 xGetPropertyReply *stuff = (xGetPropertyReply *)rep;
1820
1821                 REPLY (": PropertyType");
1822                 reply = xDbgGetAtom(stuff->propertyType, evinfo, reply, len);
1823
1824                 REPLY (" bytesAfter(0x%x) format(%d) ItemNum(%ld)",
1825                     (unsigned int)stuff->bytesAfter,
1826                     stuff->format,
1827                     (long int)stuff->nItems);
1828             }
1829             else
1830             {
1831                 return reply;
1832             }
1833
1834             return reply;
1835         }
1836
1837     case X_ListProperties:
1838         {
1839             if (evinfo->rep.isStart)
1840             {
1841                 xListPropertiesReply *stuff = (xListPropertiesReply *)rep;
1842
1843                 REPLY (" PropertieNum(%d)",
1844                     stuff->nProperties);
1845             }
1846             else
1847             {
1848                 Atom *stuff = (Atom *)rep;
1849                 int i;
1850
1851                 REPLY ("Properties");
1852                 REPLY ("(");
1853                 for (i = 0 ; i < evinfo->rep.size / sizeof(Atom) ; i ++)
1854                 {
1855                     reply = xDbgGetAtom(stuff[i], evinfo, reply, len);
1856                     if(i != evinfo->rep.size / sizeof(Atom) - 1)
1857                         REPLY (", ");
1858                 }
1859                 REPLY (")");
1860             }
1861
1862             return reply;
1863         }
1864
1865     case X_GetImage:
1866         {
1867             if (evinfo->rep.isStart)
1868             {
1869                 xGetImageReply *stuff = (xGetImageReply *)rep;
1870
1871                 REPLY (": XID(0x%x)",
1872                     (unsigned int)stuff->visual);
1873             }
1874             else
1875             {
1876                 return reply;
1877             }
1878
1879             return reply;
1880         }
1881
1882     case X_GetKeyboardControl:
1883         {
1884             if (evinfo->rep.isStart)
1885             {
1886                 xGetKeyboardControlReply *stuff = (xGetKeyboardControlReply *)rep;
1887
1888                 REPLY (": keyClickPercent(%d) bellPercent(%d), bellPitch(%d) bellDuration(%d)",
1889                     stuff->keyClickPercent,
1890                     stuff->bellPercent,
1891                     stuff->bellPitch,
1892                     stuff->bellDuration);
1893             }
1894             else
1895             {
1896                 return reply;
1897             }
1898
1899             return reply;
1900         }
1901
1902     case X_GetPointerControl:
1903         {
1904             if (evinfo->rep.isStart)
1905             {
1906                 xGetPointerControlReply *stuff = (xGetPointerControlReply *)rep;
1907
1908                 REPLY (": accelNumerator(%d) accelDenominator(%d), threshold(%d)",
1909                     stuff->accelNumerator,
1910                     stuff->accelDenominator,
1911                     stuff->threshold);
1912             }
1913             else
1914             {
1915                 return reply;
1916             }
1917
1918             return reply;
1919         }
1920
1921     default:
1922         break;
1923     }
1924
1925     return reply;
1926 }