1 /*
2 * Original code posted to comp.sources.x
3 * Modifications by Russ Cox <rsc@swtch.com>.
4 */
5
6 /*
7 Path: uunet!wyse!mikew
8 From: mikew@wyse.wyse.com (Mike Wexler)
9 Newsgroups: comp.sources.x
10 Subject: v02i056: subroutine to print events in human readable form, Part01/01
11 Message-ID: <1935@wyse.wyse.com>
12 Date: 22 Dec 88 19:28:25 GMT
13 Organization: Wyse Technology, San Jose
14 Lines: 1093
15 Approved: mikew@wyse.com
16
17 Submitted-by: richsun!darkstar!ken
18 Posting-number: Volume 2, Issue 56
19 Archive-name: showevent/part01
20
21
22 There are times during debugging when it would be real useful to be able to
23 print the fields of an event in a human readable form. Too many times I found
24 myself scrounging around in section 8 of the Xlib manual looking for the valid
25 fields for the events I wanted to see, then adding printf's to display the
26 numeric values of the fields, and then scanning through X.h trying to decode
27 the cryptic detail and state fields. After playing with xev, I decided to
28 write a couple of standard functions that I could keep in a library and call
29 on whenever I needed a little debugging verbosity. The first function,
30 GetType(), is useful for returning the string representation of the type of
31 an event. The second function, ShowEvent(), is used to display all the fields
32 of an event in a readable format. The functions are not complicated, in fact,
33 they are mind-numbingly boring - but that's just the point nobody wants to
34 spend the time writing functions like this, they just want to have them when
35 they need them.
36
37 A simple, sample program is included which does little else but to demonstrate
38 the use of these two functions. These functions have saved me many an hour
39 during debugging and I hope you find some benefit to these. If you have any
40 comments, suggestions, improvements, or if you find any blithering errors you
41 can get it touch with me at the following location:
42
43 ken@richsun.UUCP
44 */
45
46 #include <stdio.h>
47 #include <X11/Intrinsic.h>
48 #include <X11/Xproto.h>
49 #include "printevent.h"
50
51 static char* sep = " ";
52
53 /******************************************************************************/
54 /**** Miscellaneous routines to convert values to their string equivalents ****/
55 /******************************************************************************/
56
57 /* Returns the string equivalent of a boolean parameter */
58 static char*
TorF(int bool)59 TorF(int bool)
60 {
61 switch (bool) {
62 case True:
63 return ("True");
64
65 case False:
66 return ("False");
67
68 default:
69 return ("?");
70 }
71 }
72
73 /* Returns the string equivalent of a property notify state */
74 static char*
PropertyState(int state)75 PropertyState(int state)
76 {
77 switch (state) {
78 case PropertyNewValue:
79 return ("PropertyNewValue");
80
81 case PropertyDelete:
82 return ("PropertyDelete");
83
84 default:
85 return ("?");
86 }
87 }
88
89 /* Returns the string equivalent of a visibility notify state */
90 static char*
VisibilityState(int state)91 VisibilityState(int state)
92 {
93 switch (state) {
94 case VisibilityUnobscured:
95 return ("VisibilityUnobscured");
96
97 case VisibilityPartiallyObscured:
98 return ("VisibilityPartiallyObscured");
99
100 case VisibilityFullyObscured:
101 return ("VisibilityFullyObscured");
102
103 default:
104 return ("?");
105 }
106 }
107
108 /* Returns the string equivalent of a timestamp */
109 static char*
ServerTime(Time time)110 ServerTime(Time time)
111 {
112 unsigned long msec;
113 unsigned long sec;
114 unsigned long min;
115 unsigned long hr;
116 unsigned long day;
117 static char buffer[32];
118
119 msec = time % 1000;
120 time /= 1000;
121 sec = time % 60;
122 time /= 60;
123 min = time % 60;
124 time /= 60;
125 hr = time % 24;
126 time /= 24;
127 day = time;
128
129 if(0)
130 sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu",
131 day, day == 1 ? "" : "(s)", hr, min, sec, msec);
132
133 sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec);
134 return (buffer);
135 }
136
137 /* Simple structure to ease the interpretation of masks */
138 typedef struct MaskType MaskType;
139 struct MaskType
140 {
141 unsigned int value;
142 char *string;
143 };
144
145 /* Returns the string equivalent of a mask of buttons and/or modifier keys */
146 static char*
ButtonAndOrModifierState(unsigned int state)147 ButtonAndOrModifierState(unsigned int state)
148 {
149 static char buffer[256];
150 static MaskType masks[] = {
151 {Button1Mask, "Button1Mask"},
152 {Button2Mask, "Button2Mask"},
153 {Button3Mask, "Button3Mask"},
154 {Button4Mask, "Button4Mask"},
155 {Button5Mask, "Button5Mask"},
156 {ShiftMask, "ShiftMask"},
157 {LockMask, "LockMask"},
158 {ControlMask, "ControlMask"},
159 {Mod1Mask, "Mod1Mask"},
160 {Mod2Mask, "Mod2Mask"},
161 {Mod3Mask, "Mod3Mask"},
162 {Mod4Mask, "Mod4Mask"},
163 {Mod5Mask, "Mod5Mask"},
164 };
165 int num_masks = sizeof(masks) / sizeof(MaskType);
166 int i;
167 Boolean first = True;
168
169 buffer[0] = 0;
170
171 for (i = 0; i < num_masks; i++)
172 if (state & masks[i].value)
173 if (first) {
174 first = False;
175 strcpy(buffer, masks[i].string);
176 } else {
177 strcat(buffer, " | ");
178 strcat(buffer, masks[i].string);
179 }
180 return (buffer);
181 }
182
183 /* Returns the string equivalent of a mask of configure window values */
184 static char*
ConfigureValueMask(unsigned int valuemask)185 ConfigureValueMask(unsigned int valuemask)
186 {
187 static char buffer[256];
188 static MaskType masks[] = {
189 {CWX, "CWX"},
190 {CWY, "CWY"},
191 {CWWidth, "CWWidth"},
192 {CWHeight, "CWHeight"},
193 {CWBorderWidth, "CWBorderWidth"},
194 {CWSibling, "CWSibling"},
195 {CWStackMode, "CWStackMode"},
196 };
197 int num_masks = sizeof(masks) / sizeof(MaskType);
198 int i;
199 Boolean first = True;
200
201 buffer[0] = 0;
202
203 for (i = 0; i < num_masks; i++)
204 if (valuemask & masks[i].value)
205 if (first) {
206 first = False;
207 strcpy(buffer, masks[i].string);
208 } else {
209 strcat(buffer, " | ");
210 strcat(buffer, masks[i].string);
211 }
212
213 return (buffer);
214 }
215
216 /* Returns the string equivalent of a motion hint */
217 static char*
IsHint(char is_hint)218 IsHint(char is_hint)
219 {
220 switch (is_hint) {
221 case NotifyNormal:
222 return ("NotifyNormal");
223
224 case NotifyHint:
225 return ("NotifyHint");
226
227 default:
228 return ("?");
229 }
230 }
231
232 /* Returns the string equivalent of an id or the value "None" */
233 static char*
MaybeNone(int value)234 MaybeNone(int value)
235 {
236 static char buffer[16];
237
238 if (value == None)
239 return ("None");
240 else {
241 sprintf(buffer, "0x%x", value);
242 return (buffer);
243 }
244 }
245
246 /* Returns the string equivalent of a colormap state */
247 static char*
ColormapState(int state)248 ColormapState(int state)
249 {
250 switch (state) {
251 case ColormapInstalled:
252 return ("ColormapInstalled");
253
254 case ColormapUninstalled:
255 return ("ColormapUninstalled");
256
257 default:
258 return ("?");
259 }
260 }
261
262 /* Returns the string equivalent of a crossing detail */
263 static char*
CrossingDetail(int detail)264 CrossingDetail(int detail)
265 {
266 switch (detail) {
267 case NotifyAncestor:
268 return ("NotifyAncestor");
269
270 case NotifyInferior:
271 return ("NotifyInferior");
272
273 case NotifyVirtual:
274 return ("NotifyVirtual");
275
276 case NotifyNonlinear:
277 return ("NotifyNonlinear");
278
279 case NotifyNonlinearVirtual:
280 return ("NotifyNonlinearVirtual");
281
282 default:
283 return ("?");
284 }
285 }
286
287 /* Returns the string equivalent of a focus change detail */
288 static char*
FocusChangeDetail(int detail)289 FocusChangeDetail(int detail)
290 {
291 switch (detail) {
292 case NotifyAncestor:
293 return ("NotifyAncestor");
294
295 case NotifyInferior:
296 return ("NotifyInferior");
297
298 case NotifyVirtual:
299 return ("NotifyVirtual");
300
301 case NotifyNonlinear:
302 return ("NotifyNonlinear");
303
304 case NotifyNonlinearVirtual:
305 return ("NotifyNonlinearVirtual");
306
307 case NotifyPointer:
308 return ("NotifyPointer");
309
310 case NotifyPointerRoot:
311 return ("NotifyPointerRoot");
312
313 case NotifyDetailNone:
314 return ("NotifyDetailNone");
315
316 default:
317 return ("?");
318 }
319 }
320
321 /* Returns the string equivalent of a configure detail */
322 static char*
ConfigureDetail(int detail)323 ConfigureDetail(int detail)
324 {
325 switch (detail) {
326 case Above:
327 return ("Above");
328
329 case Below:
330 return ("Below");
331
332 case TopIf:
333 return ("TopIf");
334
335 case BottomIf:
336 return ("BottomIf");
337
338 case Opposite:
339 return ("Opposite");
340
341 default:
342 return ("?");
343 }
344 }
345
346 /* Returns the string equivalent of a grab mode */
347 static char*
GrabMode(int mode)348 GrabMode(int mode)
349 {
350 switch (mode) {
351 case NotifyNormal:
352 return ("NotifyNormal");
353
354 case NotifyGrab:
355 return ("NotifyGrab");
356
357 case NotifyUngrab:
358 return ("NotifyUngrab");
359
360 case NotifyWhileGrabbed:
361 return ("NotifyWhileGrabbed");
362
363 default:
364 return ("?");
365 }
366 }
367
368 /* Returns the string equivalent of a mapping request */
369 static char*
MappingRequest(int request)370 MappingRequest(int request)
371 {
372 switch (request) {
373 case MappingModifier:
374 return ("MappingModifier");
375
376 case MappingKeyboard:
377 return ("MappingKeyboard");
378
379 case MappingPointer:
380 return ("MappingPointer");
381
382 default:
383 return ("?");
384 }
385 }
386
387 /* Returns the string equivalent of a stacking order place */
388 static char*
Place(int place)389 Place(int place)
390 {
391 switch (place) {
392 case PlaceOnTop:
393 return ("PlaceOnTop");
394
395 case PlaceOnBottom:
396 return ("PlaceOnBottom");
397
398 default:
399 return ("?");
400 }
401 }
402
403 /* Returns the string equivalent of a major code */
404 static char*
MajorCode(int code)405 MajorCode(int code)
406 {
407 static char buffer[32];
408
409 switch (code) {
410 case X_CopyArea:
411 return ("X_CopyArea");
412
413 case X_CopyPlane:
414 return ("X_CopyPlane");
415
416 default:
417 sprintf(buffer, "0x%x", code);
418 return (buffer);
419 }
420 }
421
422 /* Returns the string equivalent the keycode contained in the key event */
423 static char*
Keycode(XKeyEvent * ev)424 Keycode(XKeyEvent *ev)
425 {
426 static char buffer[256];
427 KeySym keysym_str;
428 char *keysym_name;
429 char string[256];
430
431 XLookupString(ev, string, 64, &keysym_str, NULL);
432
433 if (keysym_str == NoSymbol)
434 keysym_name = "NoSymbol";
435 else if (!(keysym_name = XKeysymToString(keysym_str)))
436 keysym_name = "(no name)";
437 sprintf(buffer, "%u (keysym 0x%x \"%s\")",
438 (int)ev->keycode, (int)keysym_str, keysym_name);
439 return (buffer);
440 }
441
442 /* Returns the string equivalent of an atom or "None"*/
443 static char*
AtomName(Display * dpy,Atom atom)444 AtomName(Display *dpy, Atom atom)
445 {
446 static char buffer[256];
447 char *atom_name;
448
449 if (atom == None)
450 return ("None");
451
452 atom_name = XGetAtomName(dpy, atom);
453 strncpy(buffer, atom_name, 256);
454 XFree(atom_name);
455 return (buffer);
456 }
457
458 /******************************************************************************/
459 /**** Routines to print out readable values for the field of various events ***/
460 /******************************************************************************/
461
462 static void
VerbMotion(XMotionEvent * ev)463 VerbMotion(XMotionEvent *ev)
464 {
465 printf("window=0x%x%s", (int)ev->window, sep);
466 printf("root=0x%x%s", (int)ev->root, sep);
467 printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
468 printf("time=%s%s", ServerTime(ev->time), sep);
469 printf("x=%d y=%d%s", ev->x, ev->y, sep);
470 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
471 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
472 printf("is_hint=%s%s", IsHint(ev->is_hint), sep);
473 printf("same_screen=%s\n", TorF(ev->same_screen));
474 }
475
476 static void
VerbButton(XButtonEvent * ev)477 VerbButton(XButtonEvent *ev)
478 {
479 printf("window=0x%x%s", (int)ev->window, sep);
480 printf("root=0x%x%s", (int)ev->root, sep);
481 printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
482 printf("time=%s%s", ServerTime(ev->time), sep);
483 printf("x=%d y=%d%s", ev->x, ev->y, sep);
484 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
485 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
486 printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep);
487 printf("same_screen=%s\n", TorF(ev->same_screen));
488 }
489
490 static void
VerbColormap(XColormapEvent * ev)491 VerbColormap(XColormapEvent *ev)
492 {
493 printf("window=0x%x%s", (int)ev->window, sep);
494 printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
495 printf("new=%s%s", TorF(ev->new), sep);
496 printf("state=%s\n", ColormapState(ev->state));
497 }
498
499 static void
VerbCrossing(XCrossingEvent * ev)500 VerbCrossing(XCrossingEvent *ev)
501 {
502 printf("window=0x%x%s", (int)ev->window, sep);
503 printf("root=0x%x%s", (int)ev->root, sep);
504 printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
505 printf("time=%s%s", ServerTime(ev->time), sep);
506 printf("x=%d y=%d%s", ev->x, ev->y, sep);
507 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
508 printf("mode=%s%s", GrabMode(ev->mode), sep);
509 printf("detail=%s%s", CrossingDetail(ev->detail), sep);
510 printf("same_screen=%s%s", TorF(ev->same_screen), sep);
511 printf("focus=%s%s", TorF(ev->focus), sep);
512 printf("state=%s\n", ButtonAndOrModifierState(ev->state));
513 }
514
515 static void
VerbExpose(XExposeEvent * ev)516 VerbExpose(XExposeEvent *ev)
517 {
518 printf("window=0x%x%s", (int)ev->window, sep);
519 printf("x=%d y=%d%s", ev->x, ev->y, sep);
520 printf("width=%d height=%d%s", ev->width, ev->height, sep);
521 printf("count=%d\n", ev->count);
522 }
523
524 static void
VerbGraphicsExpose(XGraphicsExposeEvent * ev)525 VerbGraphicsExpose(XGraphicsExposeEvent *ev)
526 {
527 printf("drawable=0x%x%s", (int)ev->drawable, sep);
528 printf("x=%d y=%d%s", ev->x, ev->y, sep);
529 printf("width=%d height=%d%s", ev->width, ev->height, sep);
530 printf("major_code=%s%s", MajorCode(ev->major_code), sep);
531 printf("minor_code=%d\n", ev->minor_code);
532 }
533
534 static void
VerbNoExpose(XNoExposeEvent * ev)535 VerbNoExpose(XNoExposeEvent *ev)
536 {
537 printf("drawable=0x%x%s", (int)ev->drawable, sep);
538 printf("major_code=%s%s", MajorCode(ev->major_code), sep);
539 printf("minor_code=%d\n", ev->minor_code);
540 }
541
542 static void
VerbFocus(XFocusChangeEvent * ev)543 VerbFocus(XFocusChangeEvent *ev)
544 {
545 printf("window=0x%x%s", (int)ev->window, sep);
546 printf("mode=%s%s", GrabMode(ev->mode), sep);
547 printf("detail=%s\n", FocusChangeDetail(ev->detail));
548 }
549
550 static void
VerbKeymap(XKeymapEvent * ev)551 VerbKeymap(XKeymapEvent *ev)
552 {
553 int i;
554
555 printf("window=0x%x%s", (int)ev->window, sep);
556 printf("key_vector=");
557 for (i = 0; i < 32; i++)
558 printf("%02x", ev->key_vector[i]);
559 printf("\n");
560 }
561
562 static void
VerbKey(XKeyEvent * ev)563 VerbKey(XKeyEvent *ev)
564 {
565 printf("window=0x%x%s", (int)ev->window, sep);
566 printf("root=0x%x%s", (int)ev->root, sep);
567 if(ev->subwindow)
568 printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
569 printf("time=%s%s", ServerTime(ev->time), sep);
570 printf("[%d,%d]%s", ev->x, ev->y, sep);
571 printf("root=[%d,%d]%s", ev->x_root, ev->y_root, sep);
572 if(ev->state)
573 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
574 printf("keycode=%s%s", Keycode(ev), sep);
575 if(!ev->same_screen)
576 printf("!same_screen", TorF(ev->same_screen));
577 printf("\n");
578 return;
579
580 printf("window=0x%x%s", (int)ev->window, sep);
581 printf("root=0x%x%s", (int)ev->root, sep);
582 printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
583 printf("time=%s%s", ServerTime(ev->time), sep);
584 printf("x=%d y=%d%s", ev->x, ev->y, sep);
585 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
586 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
587 printf("keycode=%s%s", Keycode(ev), sep);
588 printf("same_screen=%s\n", TorF(ev->same_screen));
589 }
590
591 static void
VerbProperty(XPropertyEvent * ev)592 VerbProperty(XPropertyEvent *ev)
593 {
594 printf("window=0x%x%s", (int)ev->window, sep);
595 printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
596 printf("time=%s%s", ServerTime(ev->time), sep);
597 printf("state=%s\n", PropertyState(ev->state));
598 }
599
600 static void
VerbResizeRequest(XResizeRequestEvent * ev)601 VerbResizeRequest(XResizeRequestEvent *ev)
602 {
603 printf("window=0x%x%s", (int)ev->window, sep);
604 printf("width=%d height=%d\n", ev->width, ev->height);
605 }
606
607 static void
VerbCirculate(XCirculateEvent * ev)608 VerbCirculate(XCirculateEvent *ev)
609 {
610 printf("event=0x%x%s", (int)ev->event, sep);
611 printf("window=0x%x%s", (int)ev->window, sep);
612 printf("place=%s\n", Place(ev->place));
613 }
614
615 static void
VerbConfigure(XConfigureEvent * ev)616 VerbConfigure(XConfigureEvent *ev)
617 {
618 printf("event=0x%x%s", (int)ev->event, sep);
619 printf("window=0x%x%s", (int)ev->window, sep);
620 printf("x=%d y=%d%s", ev->x, ev->y, sep);
621 printf("width=%d height=%d%s", ev->width, ev->height, sep);
622 printf("border_width=%d%s", ev->border_width, sep);
623 printf("above=%s%s", MaybeNone(ev->above), sep);
624 printf("override_redirect=%s\n", TorF(ev->override_redirect));
625 }
626
627 static void
VerbCreateWindow(XCreateWindowEvent * ev)628 VerbCreateWindow(XCreateWindowEvent *ev)
629 {
630 printf("parent=0x%x%s", (int)ev->parent, sep);
631 printf("window=0x%x%s", (int)ev->window, sep);
632 printf("x=%d y=%d%s", ev->x, ev->y, sep);
633 printf("width=%d height=%d%s", ev->width, ev->height, sep);
634 printf("border_width=%d%s", ev->border_width, sep);
635 printf("override_redirect=%s\n", TorF(ev->override_redirect));
636 }
637
638 static void
VerbDestroyWindow(XDestroyWindowEvent * ev)639 VerbDestroyWindow(XDestroyWindowEvent *ev)
640 {
641 printf("event=0x%x%s", (int)ev->event, sep);
642 printf("window=0x%x\n", (int)ev->window);
643 }
644
645 static void
VerbGravity(XGravityEvent * ev)646 VerbGravity(XGravityEvent *ev)
647 {
648 printf("event=0x%x%s", (int)ev->event, sep);
649 printf("window=0x%x%s", (int)ev->window, sep);
650 printf("x=%d y=%d\n", ev->x, ev->y);
651 }
652
653 static void
VerbMap(XMapEvent * ev)654 VerbMap(XMapEvent *ev)
655 {
656 printf("event=0x%x%s", (int)ev->event, sep);
657 printf("window=0x%x%s", (int)ev->window, sep);
658 printf("override_redirect=%s\n", TorF(ev->override_redirect));
659 }
660
661 static void
VerbReparent(XReparentEvent * ev)662 VerbReparent(XReparentEvent *ev)
663 {
664 printf("event=0x%x%s", (int)ev->event, sep);
665 printf("window=0x%x%s", (int)ev->window, sep);
666 printf("parent=0x%x%s", (int)ev->parent, sep);
667 printf("x=%d y=%d%s", ev->x, ev->y, sep);
668 printf("override_redirect=%s\n", TorF(ev->override_redirect));
669 }
670
671 static void
VerbUnmap(XUnmapEvent * ev)672 VerbUnmap(XUnmapEvent *ev)
673 {
674 printf("event=0x%x%s", (int)ev->event, sep);
675 printf("window=0x%x%s", (int)ev->window, sep);
676 printf("from_configure=%s\n", TorF(ev->from_configure));
677 }
678
679 static void
VerbCirculateRequest(XCirculateRequestEvent * ev)680 VerbCirculateRequest(XCirculateRequestEvent *ev)
681 {
682 printf("parent=0x%x%s", (int)ev->parent, sep);
683 printf("window=0x%x%s", (int)ev->window, sep);
684 printf("place=%s\n", Place(ev->place));
685 }
686
687 static void
VerbConfigureRequest(XConfigureRequestEvent * ev)688 VerbConfigureRequest(XConfigureRequestEvent *ev)
689 {
690 printf("parent=0x%x%s", (int)ev->parent, sep);
691 printf("window=0x%x%s", (int)ev->window, sep);
692 printf("x=%d y=%d%s", ev->x, ev->y, sep);
693 printf("width=%d height=%d%s", ev->width, ev->height, sep);
694 printf("border_width=%d%s", ev->border_width, sep);
695 printf("above=%s%s", MaybeNone(ev->above), sep);
696 printf("detail=%s%s", ConfigureDetail(ev->detail), sep);
697 printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask));
698 }
699
700 static void
VerbMapRequest(XMapRequestEvent * ev)701 VerbMapRequest(XMapRequestEvent *ev)
702 {
703 printf("parent=0x%x%s", (int)ev->parent, sep);
704 printf("window=0x%x\n", (int)ev->window);
705 }
706
707 static void
VerbClient(XClientMessageEvent * ev)708 VerbClient(XClientMessageEvent *ev)
709 {
710 int i;
711
712 printf("window=0x%x%s", (int)ev->window, sep);
713 printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
714 printf("format=%d\n", ev->format);
715 printf("data (shown as longs)=");
716 for (i = 0; i < 5; i++)
717 printf(" 0x%08lx", ev->data.l[i]);
718 printf("\n");
719 }
720
721 static void
VerbMapping(XMappingEvent * ev)722 VerbMapping(XMappingEvent *ev)
723 {
724 printf("window=0x%x%s", (int)ev->window, sep);
725 printf("request=%s%s", MappingRequest(ev->request), sep);
726 printf("first_keycode=0x%x%s", ev->first_keycode, sep);
727 printf("count=0x%x\n", ev->count);
728 }
729
730 static void
VerbSelectionClear(XSelectionClearEvent * ev)731 VerbSelectionClear(XSelectionClearEvent *ev)
732 {
733 printf("window=0x%x%s", (int)ev->window, sep);
734 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
735 printf("time=%s\n", ServerTime(ev->time));
736 }
737
738 static void
VerbSelection(XSelectionEvent * ev)739 VerbSelection(XSelectionEvent *ev)
740 {
741 printf("requestor=0x%x%s", (int)ev->requestor, sep);
742 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
743 printf("target=%s%s", AtomName(ev->display, ev->target), sep);
744 printf("property=%s%s", AtomName(ev->display, ev->property), sep);
745 printf("time=%s\n", ServerTime(ev->time));
746 }
747
748 static void
VerbSelectionRequest(XSelectionRequestEvent * ev)749 VerbSelectionRequest(XSelectionRequestEvent *ev)
750 {
751 printf("owner=0x%x%s", (int)ev->owner, sep);
752 printf("requestor=0x%x%s", (int)ev->requestor, sep);
753 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
754 printf("target=%s%s", AtomName(ev->display, ev->target), sep);
755 printf("property=%s%s", AtomName(ev->display, ev->property), sep);
756 printf("time=%s\n", ServerTime(ev->time));
757 }
758
759 static void
VerbVisibility(XVisibilityEvent * ev)760 VerbVisibility(XVisibilityEvent *ev)
761 {
762 printf("window=0x%x%s", (int)ev->window, sep);
763 printf("state=%s\n", VisibilityState(ev->state));
764 }
765
766 /******************************************************************************/
767 /************ Return the string representation for type of an event ***********/
768 /******************************************************************************/
769
eventtype(XEvent * ev)770 char *eventtype(XEvent *ev)
771 {
772 static char buffer[20];
773
774 switch (ev->type) {
775 case KeyPress:
776 return ("KeyPress");
777 case KeyRelease:
778 return ("KeyRelease");
779 case ButtonPress:
780 return ("ButtonPress");
781 case ButtonRelease:
782 return ("ButtonRelease");
783 case MotionNotify:
784 return ("MotionNotify");
785 case EnterNotify:
786 return ("EnterNotify");
787 case LeaveNotify:
788 return ("LeaveNotify");
789 case FocusIn:
790 return ("FocusIn");
791 case FocusOut:
792 return ("FocusOut");
793 case KeymapNotify:
794 return ("KeymapNotify");
795 case Expose:
796 return ("Expose");
797 case GraphicsExpose:
798 return ("GraphicsExpose");
799 case NoExpose:
800 return ("NoExpose");
801 case VisibilityNotify:
802 return ("VisibilityNotify");
803 case CreateNotify:
804 return ("CreateNotify");
805 case DestroyNotify:
806 return ("DestroyNotify");
807 case UnmapNotify:
808 return ("UnmapNotify");
809 case MapNotify:
810 return ("MapNotify");
811 case MapRequest:
812 return ("MapRequest");
813 case ReparentNotify:
814 return ("ReparentNotify");
815 case ConfigureNotify:
816 return ("ConfigureNotify");
817 case ConfigureRequest:
818 return ("ConfigureRequest");
819 case GravityNotify:
820 return ("GravityNotify");
821 case ResizeRequest:
822 return ("ResizeRequest");
823 case CirculateNotify:
824 return ("CirculateNotify");
825 case CirculateRequest:
826 return ("CirculateRequest");
827 case PropertyNotify:
828 return ("PropertyNotify");
829 case SelectionClear:
830 return ("SelectionClear");
831 case SelectionRequest:
832 return ("SelectionRequest");
833 case SelectionNotify:
834 return ("SelectionNotify");
835 case ColormapNotify:
836 return ("ColormapNotify");
837 case ClientMessage:
838 return ("ClientMessage");
839 case MappingNotify:
840 return ("MappingNotify");
841 }
842 sprintf(buffer, "%d", ev->type);
843 return buffer;
844 }
845
846 /******************************************************************************/
847 /**************** Print the values of all fields for any event ****************/
848 /******************************************************************************/
849
printevent(XEvent * e)850 void printevent(XEvent *e)
851 {
852 XAnyEvent *ev = (void*)e;
853
854 printf("%3ld %-20s ", ev->serial, eventtype(e));
855 if(ev->send_event)
856 printf("(sendevent) ");
857 if(0){
858 printf("type=%s%s", eventtype(e), sep);
859 printf("serial=%lu%s", ev->serial, sep);
860 printf("send_event=%s%s", TorF(ev->send_event), sep);
861 printf("display=0x%p%s", ev->display, sep);
862 }
863
864 switch (ev->type) {
865 case MotionNotify:
866 VerbMotion((void*)ev);
867 break;
868
869 case ButtonPress:
870 case ButtonRelease:
871 VerbButton((void*)ev);
872 break;
873
874 case ColormapNotify:
875 VerbColormap((void*)ev);
876 break;
877
878 case EnterNotify:
879 case LeaveNotify:
880 VerbCrossing((void*)ev);
881 break;
882
883 case Expose:
884 VerbExpose((void*)ev);
885 break;
886
887 case GraphicsExpose:
888 VerbGraphicsExpose((void*)ev);
889 break;
890
891 case NoExpose:
892 VerbNoExpose((void*)ev);
893 break;
894
895 case FocusIn:
896 case FocusOut:
897 VerbFocus((void*)ev);
898 break;
899
900 case KeymapNotify:
901 VerbKeymap((void*)ev);
902 break;
903
904 case KeyPress:
905 case KeyRelease:
906 VerbKey((void*)ev);
907 break;
908
909 case PropertyNotify:
910 VerbProperty((void*)ev);
911 break;
912
913 case ResizeRequest:
914 VerbResizeRequest((void*)ev);
915 break;
916
917 case CirculateNotify:
918 VerbCirculate((void*)ev);
919 break;
920
921 case ConfigureNotify:
922 VerbConfigure((void*)ev);
923 break;
924
925 case CreateNotify:
926 VerbCreateWindow((void*)ev);
927 break;
928
929 case DestroyNotify:
930 VerbDestroyWindow((void*)ev);
931 break;
932
933 case GravityNotify:
934 VerbGravity((void*)ev);
935 break;
936
937 case MapNotify:
938 VerbMap((void*)ev);
939 break;
940
941 case ReparentNotify:
942 VerbReparent((void*)ev);
943 break;
944
945 case UnmapNotify:
946 VerbUnmap((void*)ev);
947 break;
948
949 case CirculateRequest:
950 VerbCirculateRequest((void*)ev);
951 break;
952
953 case ConfigureRequest:
954 VerbConfigureRequest((void*)ev);
955 break;
956
957 case MapRequest:
958 VerbMapRequest((void*)ev);
959 break;
960
961 case ClientMessage:
962 VerbClient((void*)ev);
963 break;
964
965 case MappingNotify:
966 VerbMapping((void*)ev);
967 break;
968
969 case SelectionClear:
970 VerbSelectionClear((void*)ev);
971 break;
972
973 case SelectionNotify:
974 VerbSelection((void*)ev);
975 break;
976
977 case SelectionRequest:
978 VerbSelectionRequest((void*)ev);
979 break;
980
981 case VisibilityNotify:
982 VerbVisibility((void*)ev);
983 break;
984 }
985 }
986