1 #include <X11/Intrinsic.h>
2 #include <X11/Xproto.h>
4 Boolean use_separate_lines = True;
7 /******************************************************************************/
8 /**** Miscellaneous routines to convert values to their string equivalents ****/
9 /******************************************************************************/
11 /* Returns the string equivalent of a boolean parameter */
12 static char *TorF(bool)
27 /* Returns the string equivalent of a property notify state */
28 static char *PropertyState(state)
32 case PropertyNewValue:
33 return ("PropertyNewValue");
36 return ("PropertyDelete");
43 /* Returns the string equivalent of a visibility notify state */
44 static char *VisibilityState(state)
48 case VisibilityUnobscured:
49 return ("VisibilityUnobscured");
51 case VisibilityPartiallyObscured:
52 return ("VisibilityPartiallyObscured");
54 case VisibilityFullyObscured:
55 return ("VisibilityFullyObscured");
62 /* Returns the string equivalent of a timestamp */
63 static char *ServerTime(time)
71 static char buffer[50];
83 sprintf(buffer, "%ld day%s %02ld:%02ld:%02ld.%03ld",
84 day, day == 1 ? "" : "(s)", hr, min, sec, msec);
88 /* Simple structure to ease the interpretation of masks */
89 typedef struct _MaskType {
94 /* Returns the string equivalent of a mask of buttons and/or modifier keys */
95 static char *ButtonAndOrModifierState(state)
98 static char buffer[256];
99 static MaskType masks[] = {
100 {Button1Mask, "Button1Mask"},
101 {Button2Mask, "Button2Mask"},
102 {Button3Mask, "Button3Mask"},
103 {Button4Mask, "Button4Mask"},
104 {Button5Mask, "Button5Mask"},
105 {ShiftMask, "ShiftMask"},
106 {LockMask, "LockMask"},
107 {ControlMask, "ControlMask"},
108 {Mod1Mask, "Mod1Mask"},
109 {Mod2Mask, "Mod2Mask"},
110 {Mod3Mask, "Mod3Mask"},
111 {Mod4Mask, "Mod4Mask"},
112 {Mod5Mask, "Mod5Mask"},
114 int num_masks = sizeof(masks) / sizeof(MaskType);
116 Boolean first = True;
120 for (i = 0; i < num_masks; i++)
121 if (state & masks[i].value)
124 strcpy(buffer, masks[i].string);
126 strcat(buffer, " | ");
127 strcat(buffer, masks[i].string);
132 /* Returns the string equivalent of a mask of configure window values */
133 static char *ConfigureValueMask(valuemask)
134 unsigned int valuemask;
136 static char buffer[256];
137 static MaskType masks[] = {
140 {CWWidth, "CWWidth"},
141 {CWHeight, "CWHeight"},
142 {CWBorderWidth, "CWBorderWidth"},
143 {CWSibling, "CWSibling"},
144 {CWStackMode, "CWStackMode"},
146 int num_masks = sizeof(masks) / sizeof(MaskType);
148 Boolean first = True;
152 for (i = 0; i < num_masks; i++)
153 if (valuemask & masks[i].value)
156 strcpy(buffer, masks[i].string);
158 strcat(buffer, " | ");
159 strcat(buffer, masks[i].string);
165 /* Returns the string equivalent of a motion hint */
166 static char *IsHint(is_hint)
171 return ("NotifyNormal");
174 return ("NotifyHint");
181 /* Returns the string equivalent of an id or the value "None" */
182 static char *MaybeNone(value)
185 static char buffer[16];
190 sprintf(buffer, "0x%x", value);
195 /* Returns the string equivalent of a colormap state */
196 static char *ColormapState(state)
200 case ColormapInstalled:
201 return ("ColormapInstalled");
203 case ColormapUninstalled:
204 return ("ColormapUninstalled");
211 /* Returns the string equivalent of a crossing detail */
212 static char *CrossingDetail(detail)
217 return ("NotifyAncestor");
220 return ("NotifyInferior");
223 return ("NotifyVirtual");
225 case NotifyNonlinear:
226 return ("NotifyNonlinear");
228 case NotifyNonlinearVirtual:
229 return ("NotifyNonlinearVirtual");
236 /* Returns the string equivalent of a focus change detail */
237 static char *FocusChangeDetail(detail)
242 return ("NotifyAncestor");
245 return ("NotifyInferior");
248 return ("NotifyVirtual");
250 case NotifyNonlinear:
251 return ("NotifyNonlinear");
253 case NotifyNonlinearVirtual:
254 return ("NotifyNonlinearVirtual");
257 return ("NotifyPointer");
259 case NotifyPointerRoot:
260 return ("NotifyPointerRoot");
262 case NotifyDetailNone:
263 return ("NotifyDetailNone");
270 /* Returns the string equivalent of a configure detail */
271 static char *ConfigureDetail(detail)
295 /* Returns the string equivalent of a grab mode */
296 static char *GrabMode(mode)
301 return ("NotifyNormal");
304 return ("NotifyGrab");
307 return ("NotifyUngrab");
309 case NotifyWhileGrabbed:
310 return ("NotifyWhileGrabbed");
317 /* Returns the string equivalent of a mapping request */
318 static char *MappingRequest(request)
322 case MappingModifier:
323 return ("MappingModifier");
325 case MappingKeyboard:
326 return ("MappingKeyboard");
329 return ("MappingPointer");
336 /* Returns the string equivalent of a stacking order place */
337 static char *Place(place)
342 return ("PlaceOnTop");
345 return ("PlaceOnBottom");
352 /* Returns the string equivalent of a major code */
353 static char *MajorCode(code)
356 static char buffer[32];
360 return ("X_CopyArea");
363 return ("X_CopyPlane");
366 sprintf(buffer, "0x%x", code);
371 /* Returns the string equivalent the keycode contained in the key event */
372 static char *Keycode(ev)
375 static char buffer[256];
380 XLookupString(ev, string, 64, &keysym_str, NULL);
382 if (keysym_str == NoSymbol)
383 keysym_name = "NoSymbol";
384 else if (!(keysym_name = XKeysymToString(keysym_str)))
385 keysym_name = "(no name)";
386 sprintf(buffer, "%u (keysym 0x%x \"%s\")",
387 ev->keycode, (unsigned)keysym_str, keysym_name);
391 /* Returns the string equivalent of an atom or "None"*/
392 static char *AtomName(Display *dpy, Atom atom)
394 static char buffer[256];
400 atom_name = XGetAtomName(dpy, atom);
401 strncpy(buffer, atom_name, 256);
406 /******************************************************************************/
407 /**** Routines to print out readable values for the field of various events ***/
408 /******************************************************************************/
410 static void VerbMotion(XMotionEvent *ev)
412 printf("window=0x%x%s", (unsigned)ev->window, sep);
413 printf("root=0x%x%s", (unsigned)ev->root, sep);
414 printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
415 printf("time=%s%s", ServerTime(ev->time), sep);
416 printf("x=%d y=%d%s", ev->x, ev->y, sep);
417 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
418 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
419 printf("is_hint=%s%s", IsHint(ev->is_hint), sep);
420 printf("same_screen=%s\n", TorF(ev->same_screen));
423 static void VerbButton(XButtonEvent *ev)
425 printf("window=0x%x%s", (unsigned)ev->window, sep);
426 printf("root=0x%x%s", (unsigned)ev->root, sep);
427 printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
428 printf("time=%s%s", ServerTime(ev->time), sep);
429 printf("x=%d y=%d%s", ev->x, ev->y, sep);
430 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
431 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
432 printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep);
433 printf("same_screen=%s\n", TorF(ev->same_screen));
436 static void VerbColormap(XColormapEvent *ev)
438 printf("window=0x%x%s", (unsigned)ev->window, sep);
439 printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
440 printf("new=%s%s", TorF(ev->new), sep);
441 printf("state=%s\n", ColormapState(ev->state));
444 static void VerbCrossing(XCrossingEvent *ev)
446 printf("window=0x%x%s", (unsigned)ev->window, sep);
447 printf("root=0x%x%s", (unsigned)ev->root, sep);
448 printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
449 printf("time=%s%s", ServerTime(ev->time), sep);
450 printf("x=%d y=%d%s", ev->x, ev->y, sep);
451 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
452 printf("mode=%s%s", GrabMode(ev->mode), sep);
453 printf("detail=%s%s", CrossingDetail(ev->detail), sep);
454 printf("same_screen=%s%s", TorF(ev->same_screen), sep);
455 printf("focus=%s%s", TorF(ev->focus), sep);
456 printf("state=%s\n", ButtonAndOrModifierState(ev->state));
459 static void VerbExpose(XExposeEvent *ev)
461 printf("window=0x%x%s", (unsigned)ev->window, sep);
462 printf("x=%d y=%d%s", ev->x, ev->y, sep);
463 printf("width=%d height=%d%s", ev->width, ev->height, sep);
464 printf("count=%d\n", ev->count);
467 static void VerbGraphicsExpose(XGraphicsExposeEvent *ev)
469 printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
470 printf("x=%d y=%d%s", ev->x, ev->y, sep);
471 printf("width=%d height=%d%s", ev->width, ev->height, sep);
472 printf("major_code=%s%s", MajorCode(ev->major_code), sep);
473 printf("minor_code=%d\n", ev->minor_code);
476 static void VerbNoExpose(XNoExposeEvent *ev)
478 printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
479 printf("major_code=%s%s", MajorCode(ev->major_code), sep);
480 printf("minor_code=%d\n", ev->minor_code);
483 static void VerbFocus(XFocusChangeEvent *ev)
485 printf("window=0x%x%s", (unsigned)ev->window, sep);
486 printf("mode=%s%s", GrabMode(ev->mode), sep);
487 printf("detail=%s\n", FocusChangeDetail(ev->detail));
490 static void VerbKeymap(XKeymapEvent *ev)
494 printf("window=0x%x%s", (unsigned)ev->window, sep);
495 printf("key_vector=");
496 for (i = 0; i < 32; i++)
497 printf("%02x", ev->key_vector[i]);
501 static void VerbKey(XKeyEvent *ev)
503 printf("window=0x%x%s", (unsigned)ev->window, sep);
504 printf("root=0x%x%s", (unsigned)ev->root, sep);
505 printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
506 printf("time=%s%s", ServerTime(ev->time), sep);
507 printf("x=%d y=%d%s", ev->x, ev->y, sep);
508 printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
509 printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
510 printf("keycode=%s%s", Keycode(ev), sep);
511 printf("same_screen=%s\n", TorF(ev->same_screen));
514 static void VerbProperty(XPropertyEvent *ev)
516 printf("window=0x%x%s", (unsigned)ev->window, sep);
517 printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
518 printf("time=%s%s", ServerTime(ev->time), sep);
519 printf("state=%s\n", PropertyState(ev->state));
522 static void VerbResizeRequest(XResizeRequestEvent *ev)
524 printf("window=0x%x%s", (unsigned)ev->window, sep);
525 printf("width=%d height=%d\n", ev->width, ev->height);
528 static void VerbCirculate(XCirculateEvent *ev)
530 printf("event=0x%x%s", (unsigned)ev->event, sep);
531 printf("window=0x%x%s", (unsigned)ev->window, sep);
532 printf("place=%s\n", Place(ev->place));
535 static void VerbConfigure(XConfigureEvent *ev)
537 printf("event=0x%x%s", (unsigned)ev->event, sep);
538 printf("window=0x%x%s", (unsigned)ev->window, sep);
539 printf("x=%d y=%d%s", ev->x, ev->y, sep);
540 printf("width=%d height=%d%s", ev->width, ev->height, sep);
541 printf("border_width=%d%s", ev->border_width, sep);
542 printf("above=%s%s", MaybeNone(ev->above), sep);
543 printf("override_redirect=%s\n", TorF(ev->override_redirect));
546 static void VerbCreateWindow(XCreateWindowEvent *ev)
548 printf("parent=0x%x%s", (unsigned)ev->parent, sep);
549 printf("window=0x%x%s", (unsigned)ev->window, sep);
550 printf("x=%d y=%d%s", ev->x, ev->y, sep);
551 printf("width=%d height=%d%s", ev->width, ev->height, sep);
552 printf("border_width=%d%s", ev->border_width, sep);
553 printf("override_redirect=%s\n", TorF(ev->override_redirect));
556 static void VerbDestroyWindow(XDestroyWindowEvent *ev)
558 printf("event=0x%x%s", (unsigned)ev->event, sep);
559 printf("window=0x%x\n", (unsigned)ev->window);
562 static void VerbGravity(XGravityEvent *ev)
564 printf("event=0x%x%s", (unsigned)ev->event, sep);
565 printf("window=0x%x%s", (unsigned)ev->window, sep);
566 printf("x=%d y=%d\n", ev->x, ev->y);
569 static void VerbMap(XMapEvent *ev)
571 printf("event=0x%x%s", (unsigned)ev->event, sep);
572 printf("window=0x%x%s", (unsigned)ev->window, sep);
573 printf("override_redirect=%s\n", TorF(ev->override_redirect));
576 static void VerbReparent(XReparentEvent *ev)
578 printf("event=0x%x%s", (unsigned)ev->event, sep);
579 printf("window=0x%x%s", (unsigned)ev->window, sep);
580 printf("parent=0x%x%s", (unsigned)ev->parent, sep);
581 printf("x=%d y=%d%s", ev->x, ev->y, sep);
582 printf("override_redirect=%s\n", TorF(ev->override_redirect));
585 static void VerbUnmap(XUnmapEvent *ev)
587 printf("event=0x%x%s", (unsigned)ev->event, sep);
588 printf("window=0x%x%s", (unsigned)ev->window, sep);
589 printf("from_configure=%s\n", TorF(ev->from_configure));
592 static void VerbCirculateRequest(XCirculateRequestEvent *ev)
594 printf("parent=0x%x%s", (unsigned)ev->parent, sep);
595 printf("window=0x%x%s", (unsigned)ev->window, sep);
596 printf("place=%s\n", Place(ev->place));
599 static void VerbConfigureRequest(XConfigureRequestEvent *ev)
601 printf("parent=0x%x%s", (unsigned)ev->parent, sep);
602 printf("window=0x%x%s", (unsigned)ev->window, sep);
603 printf("x=%d y=%d%s", ev->x, ev->y, sep);
604 printf("width=%d height=%d%s", ev->width, ev->height, sep);
605 printf("border_width=%d%s", ev->border_width, sep);
606 printf("above=%s%s", MaybeNone(ev->above), sep);
607 printf("detail=%s%s", ConfigureDetail(ev->detail), sep);
608 printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask));
611 static void VerbMapRequest(XMapRequestEvent *ev)
613 printf("parent=0x%x%s", (unsigned)ev->parent, sep);
614 printf("window=0x%x\n", (unsigned)ev->window);
617 static void VerbClient(XClientMessageEvent *ev)
621 printf("window=0x%x%s", (unsigned)ev->window, sep);
622 printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
623 printf("format=%d\n", ev->format);
624 printf("data (shown as longs)=");
625 for (i = 0; i < 5; i++)
626 printf(" 0x%08lx", ev->data.l[i]);
630 static void VerbMapping(XMappingEvent *ev)
632 printf("window=0x%x%s", (unsigned)ev->window, sep);
633 printf("request=%s%s", MappingRequest(ev->request), sep);
634 printf("first_keycode=0x%x%s", ev->first_keycode, sep);
635 printf("count=0x%x\n", ev->count);
638 static void VerbSelectionClear(XSelectionClearEvent *ev)
640 printf("window=0x%x%s", (unsigned)ev->window, sep);
641 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
642 printf("time=%s\n", ServerTime(ev->time));
645 static void VerbSelection(XSelectionEvent *ev)
647 printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
648 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
649 printf("target=%s%s", AtomName(ev->display, ev->target), sep);
650 printf("property=%s%s", AtomName(ev->display, ev->property), sep);
651 printf("time=%s\n", ServerTime(ev->time));
654 static void VerbSelectionRequest(XSelectionRequestEvent *ev)
656 printf("owner=0x%x%s", (unsigned)ev->owner, sep);
657 printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
658 printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
659 printf("target=%s%s", AtomName(ev->display, ev->target), sep);
660 printf("property=%s%s", AtomName(ev->display, ev->property), sep);
661 printf("time=%s\n", ServerTime(ev->time));
664 static void VerbVisibility(XVisibilityEvent *ev)
666 printf("window=0x%x%s", (unsigned)ev->window, sep);
667 printf("state=%s\n", VisibilityState(ev->state));
670 /******************************************************************************/
671 /************ Return the string representation for type of an event ***********/
672 /******************************************************************************/
681 return ("KeyRelease");
683 return ("ButtonPress");
685 return ("ButtonRelease");
687 return ("MotionNotify");
689 return ("EnterNotify");
691 return ("LeaveNotify");
697 return ("KeymapNotify");
701 return ("GraphicsExpose");
704 case VisibilityNotify:
705 return ("VisibilityNotify");
707 return ("CreateNotify");
709 return ("DestroyNotify");
711 return ("UnmapNotify");
713 return ("MapNotify");
715 return ("MapRequest");
717 return ("ReparentNotify");
718 case ConfigureNotify:
719 return ("ConfigureNotify");
720 case ConfigureRequest:
721 return ("ConfigureRequest");
723 return ("GravityNotify");
725 return ("ResizeRequest");
726 case CirculateNotify:
727 return ("CirculateNotify");
728 case CirculateRequest:
729 return ("CirculateRequest");
731 return ("PropertyNotify");
733 return ("SelectionClear");
734 case SelectionRequest:
735 return ("SelectionRequest");
736 case SelectionNotify:
737 return ("SelectionNotify");
739 return ("ColormapNotify");
741 return ("ClientMessage");
743 return ("MappingNotify");
748 /******************************************************************************/
749 /**************** Print the values of all fields for any event ****************/
750 /******************************************************************************/
752 void ShowEvent(XEvent *eev)
754 XAnyEvent *ev = (XAnyEvent*)eev;
755 /* determine which field separator to use */
756 if (use_separate_lines)
761 printf("type=%s%s", GetType((XEvent*)ev), sep);
762 printf("serial=%ld%s", ev->serial, sep);
763 printf("send_event=%s%s", TorF(ev->send_event), sep);
764 printf("display=0x%p%s", ev->display, sep);
768 VerbMotion((void*)ev);
773 VerbButton((void*)ev);
777 VerbColormap((void*)ev);
782 VerbCrossing((void*)ev);
786 VerbExpose((void*)ev);
790 VerbGraphicsExpose((void*)ev);
794 VerbNoExpose((void*)ev);
799 VerbFocus((void*)ev);
803 VerbKeymap((void*)ev);
812 VerbProperty((void*)ev);
816 VerbResizeRequest((void*)ev);
819 case CirculateNotify:
820 VerbCirculate((void*)ev);
823 case ConfigureNotify:
824 VerbConfigure((void*)ev);
828 VerbCreateWindow((void*)ev);
832 VerbDestroyWindow((void*)ev);
836 VerbGravity((void*)ev);
844 VerbReparent((void*)ev);
848 VerbUnmap((void*)ev);
851 case CirculateRequest:
852 VerbCirculateRequest((void*)ev);
855 case ConfigureRequest:
856 VerbConfigureRequest((void*)ev);
860 VerbMapRequest((void*)ev);
864 VerbClient((void*)ev);
868 VerbMapping((void*)ev);
872 VerbSelectionClear((void*)ev);
875 case SelectionNotify:
876 VerbSelection((void*)ev);
879 case SelectionRequest:
880 VerbSelectionRequest((void*)ev);
883 case VisibilityNotify:
884 VerbVisibility((void*)ev);