aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rio
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2008-01-30 10:29:17 -0500
committerRuss Cox <rsc@swtch.com>2008-01-30 10:29:17 -0500
commit0206bd5113e727870d4eb24fbd5f17843745237d (patch)
tree584bad99ee188d7582a5732d7ee106c022c9775f /src/cmd/rio
parent52abe8e13010b21ae13d05f1428caca05aa24bdf (diff)
downloadplan9port-0206bd5113e727870d4eb24fbd5f17843745237d.tar.gz
plan9port-0206bd5113e727870d4eb24fbd5f17843745237d.tar.bz2
plan9port-0206bd5113e727870d4eb24fbd5f17843745237d.zip
rio: make full-screen work properly; add showevent
Diffstat (limited to 'src/cmd/rio')
-rw-r--r--src/cmd/rio/error.c1
-rw-r--r--src/cmd/rio/event.c33
-rw-r--r--src/cmd/rio/fns.h2
-rw-r--r--src/cmd/rio/main.c1
-rw-r--r--src/cmd/rio/mkfile3
-rw-r--r--src/cmd/rio/showevent/Makefile13
-rw-r--r--src/cmd/rio/showevent/README28
-rw-r--r--src/cmd/rio/showevent/ShowEvent.c890
-rw-r--r--src/cmd/rio/showevent/ShowEvent.man20
-rw-r--r--src/cmd/rio/showevent/part011103
-rw-r--r--src/cmd/rio/showevent/patchlevel.h1
-rw-r--r--src/cmd/rio/showevent/sample.c48
12 files changed, 2132 insertions, 11 deletions
diff --git a/src/cmd/rio/error.c b/src/cmd/rio/error.c
index 358a36a5..fa2493f3 100644
--- a/src/cmd/rio/error.c
+++ b/src/cmd/rio/error.c
@@ -87,6 +87,7 @@ dotrace(char *s, Client *c, XEvent *e)
{
if(debug == 0)
return;
+setbuf(stdout, 0);
fprintf(stderr, "rio: %s: c=%p", s, (void*)c);
if(c)
fprintf(stderr, " x %d y %d dx %d dy %d w 0x%x parent 0x%x", c->x, c->y, c->dx, c->dy, (int)c->window, (int)c->parent);
diff --git a/src/cmd/rio/event.c b/src/cmd/rio/event.c
index 1fa00ffc..36c0cdc0 100644
--- a/src/cmd/rio/event.c
+++ b/src/cmd/rio/event.c
@@ -124,7 +124,9 @@ configurereq(XConfigureRequestEvent *e)
e->value_mask &= ~CWSibling;
if(c){
- gravitate(c, 1);
+ c->x -= c->border;
+ c->y -= c->border;
+
if(e->value_mask & CWX)
c->x = e->x;
if(e->value_mask & CWY)
@@ -135,7 +137,20 @@ configurereq(XConfigureRequestEvent *e)
c->dy = e->height;
if(e->value_mask & CWBorderWidth)
c->border = e->border_width;
- gravitate(c, 0);
+
+ if((e->value_mask & (CWX|CWY|CWWidth|CWHeight)) == (CWWidth|CWHeight)
+ && c->dx >= c->screen->width && c->dy >= c->screen->height){
+ c->border = 0;
+ e->value_mask |= CWX|CWY;
+ }else
+ c->border = BORDER;
+
+ c->x += c->border;
+ c->y += c->border;
+
+ e->x = c->x;
+ e->y = c->y;
+
if(e->value_mask & CWStackMode){
if(e->detail == Above)
top(c);
@@ -143,15 +158,14 @@ configurereq(XConfigureRequestEvent *e)
e->value_mask &= ~CWStackMode;
}
if(c->parent != c->screen->root && c->window == e->window){
- wc.x = c->x-BORDER;
- wc.y = c->y-BORDER;
- wc.width = c->dx+2*BORDER;
- wc.height = c->dy+2*BORDER;
+ wc.x = c->x - c->border;
+ wc.y = c->y - c->border;
+ wc.width = c->dx+c->border+c->border;
+ wc.height = c->dy+c->border+c->border;
wc.border_width = 1;
wc.sibling = None;
wc.stack_mode = e->detail;
XConfigureWindow(dpy, c->parent, e->value_mask, &wc);
- sendconfig(c);
if(e->value_mask & CWStackMode){
top(c);
active(c);
@@ -160,8 +174,8 @@ configurereq(XConfigureRequestEvent *e)
}
if(c && c->init){
- wc.x = BORDER;
- wc.y = BORDER;
+ wc.x = c->border;
+ wc.y = c->border;
}
else {
wc.x = e->x;
@@ -174,7 +188,6 @@ configurereq(XConfigureRequestEvent *e)
wc.stack_mode = Above;
e->value_mask &= ~CWStackMode;
e->value_mask |= CWBorderWidth;
-
XConfigureWindow(dpy, e->window, e->value_mask, &wc);
}
diff --git a/src/cmd/rio/fns.h b/src/cmd/rio/fns.h
index cbe7f239..4766f1d8 100644
--- a/src/cmd/rio/fns.h
+++ b/src/cmd/rio/fns.h
@@ -113,3 +113,5 @@ void dotrace();
/* cursor.c */
void initcurs();
+
+void ShowEvent(XEvent*);
diff --git a/src/cmd/rio/main.c b/src/cmd/rio/main.c
index afb2bb8b..2170340c 100644
--- a/src/cmd/rio/main.c
+++ b/src/cmd/rio/main.c
@@ -449,6 +449,7 @@ sendconfig(Client *c)
{
XConfigureEvent ce;
+fprintf(stderr, "send config: %p / %d %d %d %d\n", c);
ce.type = ConfigureNotify;
ce.event = c->window;
ce.window = c->window;
diff --git a/src/cmd/rio/mkfile b/src/cmd/rio/mkfile
index 3f42b2c4..135226d3 100644
--- a/src/cmd/rio/mkfile
+++ b/src/cmd/rio/mkfile
@@ -27,10 +27,11 @@ LDFLAGS=-L$X11/lib$L64/ -lXext -lX11
<|sh mkriorules.sh
-CFLAGS=$CFLAGS -DSHAPE
+CFLAGS=$CFLAGS -DSHAPE -DDEBUG_EV -DDEBUG
$O.xevents: xevents.$O printevent.$O
$LD -o $target $prereq $LDFLAGS
xevents.$O printevent.$O: printevent.h
+error.$O: showevent/ShowEvent.c
diff --git a/src/cmd/rio/showevent/Makefile b/src/cmd/rio/showevent/Makefile
new file mode 100644
index 00000000..9e70f565
--- /dev/null
+++ b/src/cmd/rio/showevent/Makefile
@@ -0,0 +1,13 @@
+CFLAGS = -g
+INCLUDE = -I/global/include
+LFLAGS = -L/global/lib
+OBJS = ShowEvent.o sample.o
+LIBS = -lX11
+
+all: sample
+
+.c.o:
+ $(CC) $(INCLUDE) $(CFLAGS) -c $<
+
+sample: $(OBJS)
+ $(CC) $(LFLAGS) $(OBJS) $(LIBS) -o sample
diff --git a/src/cmd/rio/showevent/README b/src/cmd/rio/showevent/README
new file mode 100644
index 00000000..b6429cb8
--- /dev/null
+++ b/src/cmd/rio/showevent/README
@@ -0,0 +1,28 @@
+I have edited this code to work on modern compilers.
+
+Russ Cox
+
+---
+
+There are times during debugging when it would be real useful to be able to
+print the fields of an event in a human readable form. Too many times I found
+myself scrounging around in section 8 of the Xlib manual looking for the valid
+fields for the events I wanted to see, then adding printf's to display the
+numeric values of the fields, and then scanning through X.h trying to decode
+the cryptic detail and state fields. After playing with xev, I decided to
+write a couple of standard functions that I could keep in a library and call
+on whenever I needed a little debugging verbosity. The first function,
+GetType(), is useful for returning the string representation of the type of
+an event. The second function, ShowEvent(), is used to display all the fields
+of an event in a readable format. The functions are not complicated, in fact,
+they are mind-numbingly boring - but that's just the point nobody wants to
+spend the time writing functions like this, they just want to have them when
+they need them.
+
+A simple, sample program is included which does little else but to demonstrate
+the use of these two functions. These functions have saved me many an hour
+during debugging and I hope you find some benefit to these. If you have any
+comments, suggestions, improvements, or if you find any blithering errors you
+can get it touch with me at the following location:
+
+ ken@richsun.UUCP
diff --git a/src/cmd/rio/showevent/ShowEvent.c b/src/cmd/rio/showevent/ShowEvent.c
new file mode 100644
index 00000000..e73e8ccc
--- /dev/null
+++ b/src/cmd/rio/showevent/ShowEvent.c
@@ -0,0 +1,890 @@
+#include <X11/Intrinsic.h>
+#include <X11/Xproto.h>
+
+Boolean use_separate_lines = True;
+static char *sep;
+
+/******************************************************************************/
+/**** Miscellaneous routines to convert values to their string equivalents ****/
+/******************************************************************************/
+
+/* Returns the string equivalent of a boolean parameter */
+static char *TorF(bool)
+int bool;
+{
+ switch (bool) {
+ case True:
+ return ("True");
+
+ case False:
+ return ("False");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a property notify state */
+static char *PropertyState(state)
+int state;
+{
+ switch (state) {
+ case PropertyNewValue:
+ return ("PropertyNewValue");
+
+ case PropertyDelete:
+ return ("PropertyDelete");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a visibility notify state */
+static char *VisibilityState(state)
+int state;
+{
+ switch (state) {
+ case VisibilityUnobscured:
+ return ("VisibilityUnobscured");
+
+ case VisibilityPartiallyObscured:
+ return ("VisibilityPartiallyObscured");
+
+ case VisibilityFullyObscured:
+ return ("VisibilityFullyObscured");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a timestamp */
+static char *ServerTime(time)
+Time time;
+{
+ unsigned long msec;
+ unsigned long sec;
+ unsigned long min;
+ unsigned long hr;
+ unsigned long day;
+ static char buffer[32];
+
+ msec = time % 1000;
+ time /= 1000;
+ sec = time % 60;
+ time /= 60;
+ min = time % 60;
+ time /= 60;
+ hr = time % 24;
+ time /= 24;
+ day = time;
+
+ sprintf(buffer, "%ld day%s %02ld:%02ld:%02ld.%03ld",
+ day, day == 1 ? "" : "(s)", hr, min, sec, msec);
+ return (buffer);
+}
+
+/* Simple structure to ease the interpretation of masks */
+typedef struct _MaskType {
+ unsigned int value;
+ char *string;
+} MaskType;
+
+/* Returns the string equivalent of a mask of buttons and/or modifier keys */
+static char *ButtonAndOrModifierState(state)
+unsigned int state;
+{
+ static char buffer[256];
+ static MaskType masks[] = {
+ {Button1Mask, "Button1Mask"},
+ {Button2Mask, "Button2Mask"},
+ {Button3Mask, "Button3Mask"},
+ {Button4Mask, "Button4Mask"},
+ {Button5Mask, "Button5Mask"},
+ {ShiftMask, "ShiftMask"},
+ {LockMask, "LockMask"},
+ {ControlMask, "ControlMask"},
+ {Mod1Mask, "Mod1Mask"},
+ {Mod2Mask, "Mod2Mask"},
+ {Mod3Mask, "Mod3Mask"},
+ {Mod4Mask, "Mod4Mask"},
+ {Mod5Mask, "Mod5Mask"},
+ };
+ int num_masks = sizeof(masks) / sizeof(MaskType);
+ int i;
+ Boolean first = True;
+
+ buffer[0] = 0;
+
+ for (i = 0; i < num_masks; i++)
+ if (state & masks[i].value)
+ if (first) {
+ first = False;
+ strcpy(buffer, masks[i].string);
+ } else {
+ strcat(buffer, " | ");
+ strcat(buffer, masks[i].string);
+ }
+ return (buffer);
+}
+
+/* Returns the string equivalent of a mask of configure window values */
+static char *ConfigureValueMask(valuemask)
+unsigned int valuemask;
+{
+ static char buffer[256];
+ static MaskType masks[] = {
+ {CWX, "CWX"},
+ {CWY, "CWY"},
+ {CWWidth, "CWWidth"},
+ {CWHeight, "CWHeight"},
+ {CWBorderWidth, "CWBorderWidth"},
+ {CWSibling, "CWSibling"},
+ {CWStackMode, "CWStackMode"},
+ };
+ int num_masks = sizeof(masks) / sizeof(MaskType);
+ int i;
+ Boolean first = True;
+
+ buffer[0] = 0;
+
+ for (i = 0; i < num_masks; i++)
+ if (valuemask & masks[i].value)
+ if (first) {
+ first = False;
+ strcpy(buffer, masks[i].string);
+ } else {
+ strcat(buffer, " | ");
+ strcat(buffer, masks[i].string);
+ }
+
+ return (buffer);
+}
+
+/* Returns the string equivalent of a motion hint */
+static char *IsHint(is_hint)
+char is_hint;
+{
+ switch (is_hint) {
+ case NotifyNormal:
+ return ("NotifyNormal");
+
+ case NotifyHint:
+ return ("NotifyHint");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of an id or the value "None" */
+static char *MaybeNone(value)
+int value;
+{
+ static char buffer[16];
+
+ if (value == None)
+ return ("None");
+ else {
+ sprintf(buffer, "0x%x", value);
+ return (buffer);
+ }
+}
+
+/* Returns the string equivalent of a colormap state */
+static char *ColormapState(state)
+int state;
+{
+ switch (state) {
+ case ColormapInstalled:
+ return ("ColormapInstalled");
+
+ case ColormapUninstalled:
+ return ("ColormapUninstalled");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a crossing detail */
+static char *CrossingDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case NotifyAncestor:
+ return ("NotifyAncestor");
+
+ case NotifyInferior:
+ return ("NotifyInferior");
+
+ case NotifyVirtual:
+ return ("NotifyVirtual");
+
+ case NotifyNonlinear:
+ return ("NotifyNonlinear");
+
+ case NotifyNonlinearVirtual:
+ return ("NotifyNonlinearVirtual");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a focus change detail */
+static char *FocusChangeDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case NotifyAncestor:
+ return ("NotifyAncestor");
+
+ case NotifyInferior:
+ return ("NotifyInferior");
+
+ case NotifyVirtual:
+ return ("NotifyVirtual");
+
+ case NotifyNonlinear:
+ return ("NotifyNonlinear");
+
+ case NotifyNonlinearVirtual:
+ return ("NotifyNonlinearVirtual");
+
+ case NotifyPointer:
+ return ("NotifyPointer");
+
+ case NotifyPointerRoot:
+ return ("NotifyPointerRoot");
+
+ case NotifyDetailNone:
+ return ("NotifyDetailNone");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a configure detail */
+static char *ConfigureDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case Above:
+ return ("Above");
+
+ case Below:
+ return ("Below");
+
+ case TopIf:
+ return ("TopIf");
+
+ case BottomIf:
+ return ("BottomIf");
+
+ case Opposite:
+ return ("Opposite");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a grab mode */
+static char *GrabMode(mode)
+int mode;
+{
+ switch (mode) {
+ case NotifyNormal:
+ return ("NotifyNormal");
+
+ case NotifyGrab:
+ return ("NotifyGrab");
+
+ case NotifyUngrab:
+ return ("NotifyUngrab");
+
+ case NotifyWhileGrabbed:
+ return ("NotifyWhileGrabbed");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a mapping request */
+static char *MappingRequest(request)
+int request;
+{
+ switch (request) {
+ case MappingModifier:
+ return ("MappingModifier");
+
+ case MappingKeyboard:
+ return ("MappingKeyboard");
+
+ case MappingPointer:
+ return ("MappingPointer");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a stacking order place */
+static char *Place(place)
+int place;
+{
+ switch (place) {
+ case PlaceOnTop:
+ return ("PlaceOnTop");
+
+ case PlaceOnBottom:
+ return ("PlaceOnBottom");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a major code */
+static char *MajorCode(code)
+int code;
+{
+ static char buffer[32];
+
+ switch (code) {
+ case X_CopyArea:
+ return ("X_CopyArea");
+
+ case X_CopyPlane:
+ return ("X_CopyPlane");
+
+ default:
+ sprintf(buffer, "0x%x", code);
+ return (buffer);
+ }
+}
+
+/* Returns the string equivalent the keycode contained in the key event */
+static char *Keycode(ev)
+XKeyEvent *ev;
+{
+ static char buffer[256];
+ KeySym keysym_str;
+ char *keysym_name;
+ char string[256];
+
+ XLookupString(ev, string, 64, &keysym_str, NULL);
+
+ if (keysym_str == NoSymbol)
+ keysym_name = "NoSymbol";
+ else if (!(keysym_name = XKeysymToString(keysym_str)))
+ keysym_name = "(no name)";
+ sprintf(buffer, "%u (keysym 0x%x \"%s\")",
+ ev->keycode, (unsigned)keysym_str, keysym_name);
+ return (buffer);
+}
+
+/* Returns the string equivalent of an atom or "None"*/
+static char *AtomName(dpy, atom)
+Display *dpy;
+Atom atom;
+{
+ static char buffer[256];
+ char *atom_name;
+
+ if (atom == None)
+ return ("None");
+
+ atom_name = XGetAtomName(dpy, atom);
+ strncpy(buffer, atom_name, 256);
+ XFree(atom_name);
+ return (buffer);
+}
+
+/******************************************************************************/
+/**** Routines to print out readable values for the field of various events ***/
+/******************************************************************************/
+
+static void VerbMotion(XMotionEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("root=0x%x%s", (unsigned)ev->root, sep);
+ printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("is_hint=%s%s", IsHint(ev->is_hint), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbButton(XButtonEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("root=0x%x%s", (unsigned)ev->root, sep);
+ printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbColormap(XColormapEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
+ printf("new=%s%s", TorF(ev->new), sep);
+ printf("state=%s\n", ColormapState(ev->state));
+}
+
+static void VerbCrossing(XCrossingEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("root=0x%x%s", (unsigned)ev->root, sep);
+ printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("mode=%s%s", GrabMode(ev->mode), sep);
+ printf("detail=%s%s", CrossingDetail(ev->detail), sep);
+ printf("same_screen=%s%s", TorF(ev->same_screen), sep);
+ printf("focus=%s%s", TorF(ev->focus), sep);
+ printf("state=%s\n", ButtonAndOrModifierState(ev->state));
+}
+
+static void VerbExpose(XExposeEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("count=%d\n", ev->count);
+}
+
+static void VerbGraphicsExpose(XGraphicsExposeEvent *ev)
+{
+ printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("major_code=%s%s", MajorCode(ev->major_code), sep);
+ printf("minor_code=%d\n", ev->minor_code);
+}
+
+static void VerbNoExpose(XNoExposeEvent *ev)
+{
+ printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
+ printf("major_code=%s%s", MajorCode(ev->major_code), sep);
+ printf("minor_code=%d\n", ev->minor_code);
+}
+
+static void VerbFocus(XFocusChangeEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("mode=%s%s", GrabMode(ev->mode), sep);
+ printf("detail=%s\n", FocusChangeDetail(ev->detail));
+}
+
+static void VerbKeymap(XKeymapEvent *ev)
+{
+ int i;
+
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("key_vector=");
+ for (i = 0; i < 32; i++)
+ printf("%02x", ev->key_vector[i]);
+ printf("\n");
+}
+
+static void VerbKey(XKeyEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("root=0x%x%s", (unsigned)ev->root, sep);
+ printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("keycode=%s%s", Keycode(ev), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbProperty(XPropertyEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("state=%s\n", PropertyState(ev->state));
+}
+
+static void VerbResizeRequest(XResizeRequestEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("width=%d height=%d\n", ev->width, ev->height);
+}
+
+static void VerbCirculate(XCirculateEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("place=%s\n", Place(ev->place));
+}
+
+static void VerbConfigure(XConfigureEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("above=%s%s", MaybeNone(ev->above), sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbCreateWindow(XCreateWindowEvent *ev)
+{
+ printf("parent=0x%x%s", (unsigned)ev->parent, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbDestroyWindow(XDestroyWindowEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x\n", (unsigned)ev->window);
+}
+
+static void VerbGravity(XGravityEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("x=%d y=%d\n", ev->x, ev->y);
+}
+
+static void VerbMap(XMapEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbReparent(XReparentEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("parent=0x%x%s", (unsigned)ev->parent, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbUnmap(XUnmapEvent *ev)
+{
+ printf("event=0x%x%s", (unsigned)ev->event, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("from_configure=%s\n", TorF(ev->from_configure));
+}
+
+static void VerbCirculateRequest(XCirculateRequestEvent *ev)
+{
+ printf("parent=0x%x%s", (unsigned)ev->parent, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("place=%s\n", Place(ev->place));
+}
+
+static void VerbConfigureRequest(XConfigureRequestEvent *ev)
+{
+ printf("parent=0x%x%s", (unsigned)ev->parent, sep);
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("above=%s%s", MaybeNone(ev->above), sep);
+ printf("detail=%s%s", ConfigureDetail(ev->detail), sep);
+ printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask));
+}
+
+static void VerbMapRequest(XMapRequestEvent *ev)
+{
+ printf("parent=0x%x%s", (unsigned)ev->parent, sep);
+ printf("window=0x%x\n", (unsigned)ev->window);
+}
+
+static void VerbClient(XClientMessageEvent *ev)
+{
+ int i;
+
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
+ printf("format=%d\n", ev->format);
+ printf("data (shown as longs)=");
+ for (i = 0; i < 5; i++)
+ printf(" 0x%08lx", ev->data.l[i]);
+ printf("\n");
+}
+
+static void VerbMapping(XMappingEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("request=%s%s", MappingRequest(ev->request), sep);
+ printf("first_keycode=0x%x%s", ev->first_keycode, sep);
+ printf("count=0x%x\n", ev->count);
+}
+
+static void VerbSelectionClear(XSelectionClearEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbSelection(XSelectionEvent *ev)
+{
+ printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("target=%s%s", AtomName(ev->display, ev->target), sep);
+ printf("property=%s%s", AtomName(ev->display, ev->property), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbSelectionRequest(XSelectionRequestEvent *ev)
+{
+ printf("owner=0x%x%s", (unsigned)ev->owner, sep);
+ printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("target=%s%s", AtomName(ev->display, ev->target), sep);
+ printf("property=%s%s", AtomName(ev->display, ev->property), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbVisibility(XVisibilityEvent *ev)
+{
+ printf("window=0x%x%s", (unsigned)ev->window, sep);
+ printf("state=%s\n", VisibilityState(ev->state));
+}
+
+/******************************************************************************/
+/************ Return the string representation for type of an event ***********/
+/******************************************************************************/
+
+char *GetType(ev)
+XEvent *ev;
+{
+ switch (ev->type) {
+ case KeyPress:
+ return ("KeyPress");
+ case KeyRelease:
+ return ("KeyRelease");
+ case ButtonPress:
+ return ("ButtonPress");
+ case ButtonRelease:
+ return ("ButtonRelease");
+ case MotionNotify:
+ return ("MotionNotify");
+ case EnterNotify:
+ return ("EnterNotify");
+ case LeaveNotify:
+ return ("LeaveNotify");
+ case FocusIn:
+ return ("FocusIn");
+ case FocusOut:
+ return ("FocusOut");
+ case KeymapNotify:
+ return ("KeymapNotify");
+ case Expose:
+ return ("Expose");
+ case GraphicsExpose:
+ return ("GraphicsExpose");
+ case NoExpose:
+ return ("NoExpose");
+ case VisibilityNotify:
+ return ("VisibilityNotify");
+ case CreateNotify:
+ return ("CreateNotify");
+ case DestroyNotify:
+ return ("DestroyNotify");
+ case UnmapNotify:
+ return ("UnmapNotify");
+ case MapNotify:
+ return ("MapNotify");
+ case MapRequest:
+ return ("MapRequest");
+ case ReparentNotify:
+ return ("ReparentNotify");
+ case ConfigureNotify:
+ return ("ConfigureNotify");
+ case ConfigureRequest:
+ return ("ConfigureRequest");
+ case GravityNotify:
+ return ("GravityNotify");
+ case ResizeRequest:
+ return ("ResizeRequest");
+ case CirculateNotify:
+ return ("CirculateNotify");
+ case CirculateRequest:
+ return ("CirculateRequest");
+ case PropertyNotify:
+ return ("PropertyNotify");
+ case SelectionClear:
+ return ("SelectionClear");
+ case SelectionRequest:
+ return ("SelectionRequest");
+ case SelectionNotify:
+ return ("SelectionNotify");
+ case ColormapNotify:
+ return ("ColormapNotify");
+ case ClientMessage:
+ return ("ClientMessage");
+ case MappingNotify:
+ return ("MappingNotify");
+ }
+ return "???";
+}
+
+/******************************************************************************/
+/**************** Print the values of all fields for any event ****************/
+/******************************************************************************/
+
+void ShowEvent(XEvent *eev)
+{
+ XAnyEvent *ev = (XAnyEvent*)eev;
+ /* determine which field separator to use */
+ if (use_separate_lines)
+ sep = "\n";
+ else
+ sep = " ";
+
+ printf("type=%s%s", GetType(ev), sep);
+ printf("serial=%ld%s", ev->serial, sep);
+ printf("send_event=%s%s", TorF(ev->send_event), sep);
+ printf("display=0x%x%s", (unsigned)ev->display, sep);
+
+ switch (ev->type) {
+ case MotionNotify:
+ VerbMotion((void*)ev);
+ break;
+
+ case ButtonPress:
+ case ButtonRelease:
+ VerbButton((void*)ev);
+ break;
+
+ case ColormapNotify:
+ VerbColormap((void*)ev);
+ break;
+
+ case EnterNotify:
+ case LeaveNotify:
+ VerbCrossing((void*)ev);
+ break;
+
+ case Expose:
+ VerbExpose((void*)ev);
+ break;
+
+ case GraphicsExpose:
+ VerbGraphicsExpose((void*)ev);
+ break;
+
+ case NoExpose:
+ VerbNoExpose((void*)ev);
+ break;
+
+ case FocusIn:
+ case FocusOut:
+ VerbFocus((void*)ev);
+ break;
+
+ case KeymapNotify:
+ VerbKeymap((void*)ev);
+ break;
+
+ case KeyPress:
+ case KeyRelease:
+ VerbKey((void*)ev);
+ break;
+
+ case PropertyNotify:
+ VerbProperty((void*)ev);
+ break;
+
+ case ResizeRequest:
+ VerbResizeRequest((void*)ev);
+ break;
+
+ case CirculateNotify:
+ VerbCirculate((void*)ev);
+ break;
+
+ case ConfigureNotify:
+ VerbConfigure((void*)ev);
+ break;
+
+ case CreateNotify:
+ VerbCreateWindow((void*)ev);
+ break;
+
+ case DestroyNotify:
+ VerbDestroyWindow((void*)ev);
+ break;
+
+ case GravityNotify:
+ VerbGravity((void*)ev);
+ break;
+
+ case MapNotify:
+ VerbMap((void*)ev);
+ break;
+
+ case ReparentNotify:
+ VerbReparent((void*)ev);
+ break;
+
+ case UnmapNotify:
+ VerbUnmap((void*)ev);
+ break;
+
+ case CirculateRequest:
+ VerbCirculateRequest((void*)ev);
+ break;
+
+ case ConfigureRequest:
+ VerbConfigureRequest((void*)ev);
+ break;
+
+ case MapRequest:
+ VerbMapRequest((void*)ev);
+ break;
+
+ case ClientMessage:
+ VerbClient((void*)ev);
+ break;
+
+ case MappingNotify:
+ VerbMapping((void*)ev);
+ break;
+
+ case SelectionClear:
+ VerbSelectionClear((void*)ev);
+ break;
+
+ case SelectionNotify:
+ VerbSelection((void*)ev);
+ break;
+
+ case SelectionRequest:
+ VerbSelectionRequest((void*)ev);
+ break;
+
+ case VisibilityNotify:
+ VerbVisibility((void*)ev);
+ break;
+
+ }
+}
diff --git a/src/cmd/rio/showevent/ShowEvent.man b/src/cmd/rio/showevent/ShowEvent.man
new file mode 100644
index 00000000..cfd188a7
--- /dev/null
+++ b/src/cmd/rio/showevent/ShowEvent.man
@@ -0,0 +1,20 @@
+.TH ShowEvent 3X11 "December 1988"
+.SH NAME
+.B ShowEvent \- display the fields of an event
+.br
+.B GetType - get a string representation of an event type
+
+.SH SYNOPSIS
+.B void ShowEvent(event)
+.br
+.B XEvent *event;
+.PP
+.B char *GetType(event)
+.br
+.B XEvent *event;
+
+.SH DESCRIPTION
+ShowEvent displays the fields of the specified event in a readable form.
+.PP
+GetType returns the string representation of the specified event type.
+
diff --git a/src/cmd/rio/showevent/part01 b/src/cmd/rio/showevent/part01
new file mode 100644
index 00000000..972ddd56
--- /dev/null
+++ b/src/cmd/rio/showevent/part01
@@ -0,0 +1,1103 @@
+Path: uunet!wyse!mikew
+From: mikew@wyse.wyse.com (Mike Wexler)
+Newsgroups: comp.sources.x
+Subject: v02i056: subroutine to print events in human readable form, Part01/01
+Message-ID: <1935@wyse.wyse.com>
+Date: 22 Dec 88 19:28:25 GMT
+Organization: Wyse Technology, San Jose
+Lines: 1093
+Approved: mikew@wyse.com
+
+Submitted-by: richsun!darkstar!ken
+Posting-number: Volume 2, Issue 56
+Archive-name: showevent/part01
+
+
+
+Following is a shar file of a debugging aid along with a sample program to
+show how it is used. The README contains more details.
+
+ Ken
+
+#! /bin/sh
+# This is a shell archive, meaning:
+# 1. Remove everything above the #! /bin/sh line.
+# 2. Save the resulting text in a file.
+# 3. Execute the file with /bin/sh (not csh) to create the files:
+# Makefile
+# README
+# ShowEvent.c
+# ShowEvent.man
+# patchlevel.h
+# sample.c
+# This archive created: Thu Dec 22 12:13:46 1988
+export PATH; PATH=/bin:$PATH
+if test -f 'Makefile'
+then
+ echo shar: will not over-write existing file "'Makefile'"
+else
+cat << \SHAR_EOF > 'Makefile'
+CFLAGS = -g
+INCLUDE = -I/global/include
+LFLAGS = -L/global/lib
+OBJS = ShowEvent.o sample.o
+LIBS = -lX11
+
+all: sample
+
+.c.o:
+ $(CC) $(INCLUDE) $(CFLAGS) -c $<
+
+sample: $(OBJS)
+ $(CC) $(LFLAGS) $(OBJS) $(LIBS) -o sample
+SHAR_EOF
+fi # end of overwriting check
+if test -f 'README'
+then
+ echo shar: will not over-write existing file "'README'"
+else
+cat << \SHAR_EOF > 'README'
+There are times during debugging when it would be real useful to be able to
+print the fields of an event in a human readable form. Too many times I found
+myself scrounging around in section 8 of the Xlib manual looking for the valid
+fields for the events I wanted to see, then adding printf's to display the
+numeric values of the fields, and then scanning through X.h trying to decode
+the cryptic detail and state fields. After playing with xev, I decided to
+write a couple of standard functions that I could keep in a library and call
+on whenever I needed a little debugging verbosity. The first function,
+GetType(), is useful for returning the string representation of the type of
+an event. The second function, ShowEvent(), is used to display all the fields
+of an event in a readable format. The functions are not complicated, in fact,
+they are mind-numbingly boring - but that's just the point nobody wants to
+spend the time writing functions like this, they just want to have them when
+they need them.
+
+A simple, sample program is included which does little else but to demonstrate
+the use of these two functions. These functions have saved me many an hour
+during debugging and I hope you find some benefit to these. If you have any
+comments, suggestions, improvements, or if you find any blithering errors you
+can get it touch with me at the following location:
+
+ ken@richsun.UUCP
+SHAR_EOF
+fi # end of overwriting check
+if test -f 'ShowEvent.c'
+then
+ echo shar: will not over-write existing file "'ShowEvent.c'"
+else
+cat << \SHAR_EOF > 'ShowEvent.c'
+#include <X11/Intrinsic.h>
+#include <X11/Xproto.h>
+
+Boolean use_separate_lines = True;
+static char *sep;
+
+/******************************************************************************/
+/**** Miscellaneous routines to convert values to their string equivalents ****/
+/******************************************************************************/
+
+/* Returns the string equivalent of a boolean parameter */
+static char *TorF(bool)
+int bool;
+{
+ switch (bool) {
+ case True:
+ return ("True");
+
+ case False:
+ return ("False");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a property notify state */
+static char *PropertyState(state)
+int state;
+{
+ switch (state) {
+ case PropertyNewValue:
+ return ("PropertyNewValue");
+
+ case PropertyDelete:
+ return ("PropertyDelete");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a visibility notify state */
+static char *VisibilityState(state)
+int state;
+{
+ switch (state) {
+ case VisibilityUnobscured:
+ return ("VisibilityUnobscured");
+
+ case VisibilityPartiallyObscured:
+ return ("VisibilityPartiallyObscured");
+
+ case VisibilityFullyObscured:
+ return ("VisibilityFullyObscured");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a timestamp */
+static char *ServerTime(time)
+Time time;
+{
+ unsigned long msec;
+ unsigned long sec;
+ unsigned long min;
+ unsigned long hr;
+ unsigned long day;
+ char buffer[32];
+
+ msec = time % 1000;
+ time /= 1000;
+ sec = time % 60;
+ time /= 60;
+ min = time % 60;
+ time /= 60;
+ hr = time % 24;
+ time /= 24;
+ day = time;
+
+ sprintf(buffer, "%d day%s %02d:%02d:%02d.%03d",
+ day, day == 1 ? "" : "(s)", hr, min, sec, msec);
+ return (buffer);
+}
+
+/* Simple structure to ease the interpretation of masks */
+typedef struct _MaskType {
+ unsigned int value;
+ char *string;
+} MaskType;
+
+/* Returns the string equivalent of a mask of buttons and/or modifier keys */
+static char *ButtonAndOrModifierState(state)
+unsigned int state;
+{
+ char buffer[256];
+ static MaskType masks[] = {
+ {Button1Mask, "Button1Mask"},
+ {Button2Mask, "Button2Mask"},
+ {Button3Mask, "Button3Mask"},
+ {Button4Mask, "Button4Mask"},
+ {Button5Mask, "Button5Mask"},
+ {ShiftMask, "ShiftMask"},
+ {LockMask, "LockMask"},
+ {ControlMask, "ControlMask"},
+ {Mod1Mask, "Mod1Mask"},
+ {Mod2Mask, "Mod2Mask"},
+ {Mod3Mask, "Mod3Mask"},
+ {Mod4Mask, "Mod4Mask"},
+ {Mod5Mask, "Mod5Mask"},
+ };
+ int num_masks = sizeof(masks) / sizeof(MaskType);
+ int i;
+ Boolean first = True;
+
+ buffer[0] = NULL;
+
+ for (i = 0; i < num_masks; i++)
+ if (state & masks[i].value)
+ if (first) {
+ first = False;
+ strcpy(buffer, masks[i].string);
+ } else {
+ strcat(buffer, " | ");
+ strcat(buffer, masks[i].string);
+ }
+ return (buffer);
+}
+
+/* Returns the string equivalent of a mask of configure window values */
+static char *ConfigureValueMask(valuemask)
+unsigned int valuemask;
+{
+ char buffer[256];
+ static MaskType masks[] = {
+ {CWX, "CWX"},
+ {CWY, "CWY"},
+ {CWWidth, "CWWidth"},
+ {CWHeight, "CWHeight"},
+ {CWBorderWidth, "CWBorderWidth"},
+ {CWSibling, "CWSibling"},
+ {CWStackMode, "CWStackMode"},
+ };
+ int num_masks = sizeof(masks) / sizeof(MaskType);
+ int i;
+ Boolean first = True;
+
+ buffer[0] = NULL;
+
+ for (i = 0; i < num_masks; i++)
+ if (valuemask & masks[i].value)
+ if (first) {
+ first = False;
+ strcpy(buffer, masks[i].string);
+ } else {
+ strcat(buffer, " | ");
+ strcat(buffer, masks[i].string);
+ }
+
+ return (buffer);
+}
+
+/* Returns the string equivalent of a motion hint */
+static char *IsHint(is_hint)
+char is_hint;
+{
+ switch (is_hint) {
+ case NotifyNormal:
+ return ("NotifyNormal");
+
+ case NotifyHint:
+ return ("NotifyHint");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of an id or the value "None" */
+static char *MaybeNone(value)
+int value;
+{
+ char buffer[16];
+
+ if (value == None)
+ return ("None");
+ else {
+ sprintf(buffer, "0x%x", value);
+ return (buffer);
+ }
+}
+
+/* Returns the string equivalent of a colormap state */
+static char *ColormapState(state)
+int state;
+{
+ switch (state) {
+ case ColormapInstalled:
+ return ("ColormapInstalled");
+
+ case ColormapUninstalled:
+ return ("ColormapUninstalled");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a crossing detail */
+static char *CrossingDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case NotifyAncestor:
+ return ("NotifyAncestor");
+
+ case NotifyInferior:
+ return ("NotifyInferior");
+
+ case NotifyVirtual:
+ return ("NotifyVirtual");
+
+ case NotifyNonlinear:
+ return ("NotifyNonlinear");
+
+ case NotifyNonlinearVirtual:
+ return ("NotifyNonlinearVirtual");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a focus change detail */
+static char *FocusChangeDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case NotifyAncestor:
+ return ("NotifyAncestor");
+
+ case NotifyInferior:
+ return ("NotifyInferior");
+
+ case NotifyVirtual:
+ return ("NotifyVirtual");
+
+ case NotifyNonlinear:
+ return ("NotifyNonlinear");
+
+ case NotifyNonlinearVirtual:
+ return ("NotifyNonlinearVirtual");
+
+ case NotifyPointer:
+ return ("NotifyPointer");
+
+ case NotifyPointerRoot:
+ return ("NotifyPointerRoot");
+
+ case NotifyDetailNone:
+ return ("NotifyDetailNone");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a configure detail */
+static char *ConfigureDetail(detail)
+int detail;
+{
+ switch (detail) {
+ case Above:
+ return ("Above");
+
+ case Below:
+ return ("Below");
+
+ case TopIf:
+ return ("TopIf");
+
+ case BottomIf:
+ return ("BottomIf");
+
+ case Opposite:
+ return ("Opposite");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a grab mode */
+static char *GrabMode(mode)
+int mode;
+{
+ switch (mode) {
+ case NotifyNormal:
+ return ("NotifyNormal");
+
+ case NotifyGrab:
+ return ("NotifyGrab");
+
+ case NotifyUngrab:
+ return ("NotifyUngrab");
+
+ case NotifyWhileGrabbed:
+ return ("NotifyWhileGrabbed");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a mapping request */
+static char *MappingRequest(request)
+int request;
+{
+ switch (request) {
+ case MappingModifier:
+ return ("MappingModifier");
+
+ case MappingKeyboard:
+ return ("MappingKeyboard");
+
+ case MappingPointer:
+ return ("MappingPointer");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a stacking order place */
+static char *Place(place)
+int place;
+{
+ switch (place) {
+ case PlaceOnTop:
+ return ("PlaceOnTop");
+
+ case PlaceOnBottom:
+ return ("PlaceOnBottom");
+
+ default:
+ return ("?");
+ }
+}
+
+/* Returns the string equivalent of a major code */
+static char *MajorCode(code)
+int code;
+{
+ char buffer[32];
+
+ switch (code) {
+ case X_CopyArea:
+ return ("X_CopyArea");
+
+ case X_CopyPlane:
+ return ("X_CopyPlane");
+
+ default:
+ sprintf(buffer, "0x%x", code);
+ return (buffer);
+ }
+}
+
+/* Returns the string equivalent the keycode contained in the key event */
+static char *Keycode(ev)
+XKeyEvent *ev;
+{
+ char buffer[256];
+ KeySym keysym_str;
+ char *keysym_name;
+ char string[256];
+
+ XLookupString(ev, string, 64, &keysym_str, NULL);
+
+ if (keysym_str == NoSymbol)
+ keysym_name = "NoSymbol";
+ else if (!(keysym_name = XKeysymToString(keysym_str)))
+ keysym_name = "(no name)";
+ sprintf(buffer, "%u (keysym 0x%x \"%s\")",
+ ev->keycode, keysym_str, keysym_name);
+ return (buffer);
+}
+
+/* Returns the string equivalent of an atom or "None"*/
+static char *AtomName(dpy, atom)
+Display *dpy;
+Atom atom;
+{
+ char buffer[256];
+ char *atom_name;
+
+ if (atom == None)
+ return ("None");
+
+ atom_name = XGetAtomName(dpy, atom);
+ strncpy(buffer, atom_name, 256);
+ XFree(atom_name);
+ return (buffer);
+}
+
+/******************************************************************************/
+/**** Routines to print out readable values for the field of various events ***/
+/******************************************************************************/
+
+static void VerbMotion(ev)
+XMotionEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("root=0x%x%s", ev->root, sep);
+ printf("subwindow=0x%x%s", ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("is_hint=%s%s", IsHint(ev->is_hint), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbButton(ev)
+XButtonEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("root=0x%x%s", ev->root, sep);
+ printf("subwindow=0x%x%s", ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbColormap(ev)
+XColormapEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
+ printf("new=%s%s", TorF(ev->new), sep);
+ printf("state=%s\n", ColormapState(ev->state));
+}
+
+static void VerbCrossing(ev)
+XCrossingEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("root=0x%x%s", ev->root, sep);
+ printf("subwindow=0x%x%s", ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("mode=%s%s", GrabMode(ev->mode), sep);
+ printf("detail=%s%s", CrossingDetail(ev->detail), sep);
+ printf("same_screen=%s%s", TorF(ev->same_screen), sep);
+ printf("focus=%s%s", TorF(ev->focus), sep);
+ printf("state=%s\n", ButtonAndOrModifierState(ev->state));
+}
+
+static void VerbExpose(ev)
+XExposeEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("count=%d\n", ev->count);
+}
+
+static void VerbGraphicsExpose(ev)
+XGraphicsExposeEvent *ev;
+{
+ printf("drawable=0x%x%s", ev->drawable, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("major_code=%s%s", MajorCode(ev->major_code), sep);
+ printf("minor_code=%d\n", ev->minor_code);
+}
+
+static void VerbNoExpose(ev)
+XNoExposeEvent *ev;
+{
+ printf("drawable=0x%x%s", ev->drawable, sep);
+ printf("major_code=%s%s", MajorCode(ev->major_code), sep);
+ printf("minor_code=%d\n", ev->minor_code);
+}
+
+static void VerbFocus(ev)
+XFocusChangeEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("mode=%s%s", GrabMode(ev->mode), sep);
+ printf("detail=%s\n", FocusChangeDetail(ev->detail));
+}
+
+static void VerbKeymap(ev)
+XKeymapEvent *ev;
+{
+ int i;
+
+ printf("window=0x%x%s", ev->window, sep);
+ printf("key_vector=");
+ for (i = 0; i < 32; i++)
+ printf("%02x", ev->key_vector[i]);
+ printf("\n");
+}
+
+static void VerbKey(ev)
+XKeyEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("root=0x%x%s", ev->root, sep);
+ printf("subwindow=0x%x%s", ev->subwindow, sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep);
+ printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
+ printf("keycode=%s%s", Keycode(ev), sep);
+ printf("same_screen=%s\n", TorF(ev->same_screen));
+}
+
+static void VerbProperty(ev)
+XPropertyEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
+ printf("time=%s%s", ServerTime(ev->time), sep);
+ printf("state=%s\n", PropertyState(ev->state));
+}
+
+static void VerbResizeRequest(ev)
+XResizeRequestEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("width=%d height=%d\n", ev->width, ev->height);
+}
+
+static void VerbCirculate(ev)
+XCirculateEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("place=%s\n", Place(ev->place));
+}
+
+static void VerbConfigure(ev)
+XConfigureEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("above=%s%s", MaybeNone(ev->above), sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbCreateWindow(ev)
+XCreateWindowEvent *ev;
+{
+ printf("parent=0x%x%s", ev->parent, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbDestroyWindow(ev)
+XDestroyWindowEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x\n", ev->window);
+}
+
+static void VerbGravity(ev)
+XGravityEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("x=%d y=%d\n", ev->x, ev->y);
+}
+
+static void VerbMap(ev)
+XMapEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbReparent(ev)
+XReparentEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("parent=0x%x%s", ev->parent, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("override_redirect=%s\n", TorF(ev->override_redirect));
+}
+
+static void VerbUnmap(ev)
+XUnmapEvent *ev;
+{
+ printf("event=0x%x%s", ev->event, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("from_configure=%s\n", TorF(ev->from_configure));
+}
+
+static void VerbCirculateRequest(ev)
+XCirculateRequestEvent *ev;
+{
+ printf("parent=0x%x%s", ev->parent, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("place=%s\n", Place(ev->place));
+}
+
+static void VerbConfigureRequest(ev)
+XConfigureRequestEvent *ev;
+{
+ printf("parent=0x%x%s", ev->parent, sep);
+ printf("window=0x%x%s", ev->window, sep);
+ printf("x=%d y=%d%s", ev->x, ev->y, sep);
+ printf("width=%d height=%d%s", ev->width, ev->height, sep);
+ printf("border_width=%d%s", ev->border_width, sep);
+ printf("above=%s%s", MaybeNone(ev->above), sep);
+ printf("detail=0x%x%s", ConfigureDetail(ev->detail), sep);
+ printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask));
+}
+
+static void VerbMapRequest(ev)
+XMapRequestEvent *ev;
+{
+ printf("parent=0x%x%s", ev->parent, sep);
+ printf("window=0x%x\n", ev->window);
+}
+
+static void VerbClient(ev)
+XClientMessageEvent *ev;
+{
+ int i;
+
+ printf("window=0x%x%s", ev->window, sep);
+ printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
+ printf("format=%d\n", ev->format);
+ printf("data (shown as longs)=");
+ for (i = 0; i < 5; i++)
+ printf(" 0x%08x", ev->data.l[i]);
+ printf("\n");
+}
+
+static void VerbMapping(ev)
+XMappingEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("request=0x%x%s", MappingRequest(ev->request), sep);
+ printf("first_keycode=0x%x%s", ev->first_keycode, sep);
+ printf("count=0x%x\n", ev->count);
+}
+
+static void VerbSelectionClear(ev)
+XSelectionClearEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbSelection(ev)
+XSelectionEvent *ev;
+{
+ printf("requestor=0x%x%s", ev->requestor, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("target=%s%s", AtomName(ev->display, ev->target), sep);
+ printf("property=%s%s", AtomName(ev->display, ev->property), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbSelectionRequest(ev)
+XSelectionRequestEvent *ev;
+{
+ printf("owner=0x%x%s", ev->owner, sep);
+ printf("requestor=0x%x%s", ev->requestor, sep);
+ printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
+ printf("target=%s%s", AtomName(ev->display, ev->target), sep);
+ printf("property=%s%s", AtomName(ev->display, ev->property), sep);
+ printf("time=%s\n", ServerTime(ev->time));
+}
+
+static void VerbVisibility(ev)
+XVisibilityEvent *ev;
+{
+ printf("window=0x%x%s", ev->window, sep);
+ printf("state=%s\n", VisibilityState(ev->state));
+}
+
+/******************************************************************************/
+/************ Return the string representation for type of an event ***********/
+/******************************************************************************/
+
+char *GetType(ev)
+XEvent *ev;
+{
+ switch (ev->type) {
+ case KeyPress:
+ return ("KeyPress");
+ case KeyRelease:
+ return ("KeyRelease");
+ case ButtonPress:
+ return ("ButtonPress");
+ case ButtonRelease:
+ return ("ButtonRelease");
+ case MotionNotify:
+ return ("MotionNotify");
+ case EnterNotify:
+ return ("EnterNotify");
+ case LeaveNotify:
+ return ("LeaveNotify");
+ case FocusIn:
+ return ("FocusIn");
+ case FocusOut:
+ return ("FocusOut");
+ case KeymapNotify:
+ return ("KeymapNotify");
+ case Expose:
+ return ("Expose");
+ case GraphicsExpose:
+ return ("GraphicsExpose");
+ case NoExpose:
+ return ("NoExpose");
+ case VisibilityNotify:
+ return ("VisibilityNotify");
+ case CreateNotify:
+ return ("CreateNotify");
+ case DestroyNotify:
+ return ("DestroyNotify");
+ case UnmapNotify:
+ return ("UnmapNotify");
+ case MapNotify:
+ return ("MapNotify");
+ case MapRequest:
+ return ("MapRequest");
+ case ReparentNotify:
+ return ("ReparentNotify");
+ case ConfigureNotify:
+ return ("ConfigureNotify");
+ case ConfigureRequest:
+ return ("ConfigureRequest");
+ case GravityNotify:
+ return ("GravityNotify");
+ case ResizeRequest:
+ return ("ResizeRequest");
+ case CirculateNotify:
+ return ("CirculateNotify");
+ case CirculateRequest:
+ return ("CirculateRequest");
+ case PropertyNotify:
+ return ("PropertyNotify");
+ case SelectionClear:
+ return ("SelectionClear");
+ case SelectionRequest:
+ return ("SelectionRequest");
+ case SelectionNotify:
+ return ("SelectionNotify");
+ case ColormapNotify:
+ return ("ColormapNotify");
+ case ClientMessage:
+ return ("ClientMessage");
+ case MappingNotify:
+ return ("MappingNotify");
+ }
+}
+
+/******************************************************************************/
+/**************** Print the values of all fields for any event ****************/
+/******************************************************************************/
+
+void ShowEvent(ev)
+XAnyEvent *ev;
+{
+ /* determine which field separator to use */
+ if (use_separate_lines)
+ sep = "\n";
+ else
+ sep = " ";
+
+ printf("type=%s%s", GetType(ev), sep);
+ printf("serial=%d%s", ev->serial, sep);
+ printf("send_event=%s%s", TorF(ev->send_event), sep);
+ printf("display=0x%x%s", ev->display, sep);
+
+ switch (ev->type) {
+ case MotionNotify:
+ VerbMotion(ev);
+ break;
+
+ case ButtonPress:
+ case ButtonRelease:
+ VerbButton(ev);
+ break;
+
+ case ColormapNotify:
+ VerbColormap(ev);
+ break;
+
+ case EnterNotify:
+ case LeaveNotify:
+ VerbCrossing(ev);
+ break;
+
+ case Expose:
+ VerbExpose(ev);
+ break;
+
+ case GraphicsExpose:
+ VerbGraphicsExpose(ev);
+ break;
+
+ case NoExpose:
+ VerbNoExpose(ev);
+ break;
+
+ case FocusIn:
+ case FocusOut:
+ VerbFocus(ev);
+ break;
+
+ case KeymapNotify:
+ VerbKeymap(ev);
+ break;
+
+ case KeyPress:
+ case KeyRelease:
+ VerbKey(ev);
+ break;
+
+ case PropertyNotify:
+ VerbProperty(ev);
+ break;
+
+ case ResizeRequest:
+ VerbResizeRequest(ev);
+ break;
+
+ case CirculateNotify:
+ VerbCirculate(ev);
+ break;
+
+ case ConfigureNotify:
+ VerbConfigure(ev);
+ break;
+
+ case CreateNotify:
+ VerbCreateWindow(ev);
+ break;
+
+ case DestroyNotify:
+ VerbDestroyWindow(ev);
+ break;
+
+ case GravityNotify:
+ VerbGravity(ev);
+ break;
+
+ case MapNotify:
+ VerbMap(ev);
+ break;
+
+ case ReparentNotify:
+ VerbReparent(ev);
+ break;
+
+ case UnmapNotify:
+ VerbUnmap(ev);
+ break;
+
+ case CirculateRequest:
+ VerbCirculateRequest(ev);
+ break;
+
+ case ConfigureRequest:
+ VerbConfigureRequest(ev);
+ break;
+
+ case MapRequest:
+ VerbMapRequest(ev);
+ break;
+
+ case ClientMessage:
+ VerbClient(ev);
+ break;
+
+ case MappingNotify:
+ VerbMapping(ev);
+ break;
+
+ case SelectionClear:
+ VerbSelectionClear(ev);
+ break;
+
+ case SelectionNotify:
+ VerbSelection(ev);
+ break;
+
+ case SelectionRequest:
+ VerbSelectionRequest(ev);
+ break;
+
+ case VisibilityNotify:
+ VerbVisibility(ev);
+ break;
+
+ }
+}
+SHAR_EOF
+fi # end of overwriting check
+if test -f 'ShowEvent.man'
+then
+ echo shar: will not over-write existing file "'ShowEvent.man'"
+else
+cat << \SHAR_EOF > 'ShowEvent.man'
+.TH ShowEvent 3X11 "December 1988"
+.SH NAME
+.B ShowEvent \- display the fields of an event
+.br
+.B GetType - get a string representation of an event type
+
+.SH SYNOPSIS
+.B void ShowEvent(event)
+.br
+.B XEvent *event;
+.PP
+.B char *GetType(event)
+.br
+.B XEvent *event;
+
+.SH DESCRIPTION
+ShowEvent displays the fields of the specified event in a readable form.
+.PP
+GetType returns the string representation of the specified event type.
+
+SHAR_EOF
+fi # end of overwriting check
+if test -f 'patchlevel.h'
+then
+ echo shar: will not over-write existing file "'patchlevel.h'"
+else
+cat << \SHAR_EOF > 'patchlevel.h'
+#define PATCHLEVEL 0
+SHAR_EOF
+fi # end of overwriting check
+if test -f 'sample.c'
+then
+ echo shar: will not over-write existing file "'sample.c'"
+else
+cat << \SHAR_EOF > 'sample.c'
+#include <X11/Intrinsic.h>
+
+/*
+ * Disclaimer: No I don't actually code like this but this is a simple,
+ * "Quick-n-Dirty", plain, vanilla, "No ups, No extras" piece of code.
+ */
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+ Display *dpy;
+ int screen;
+ Window window;
+ XEvent event;
+ extern Boolean use_separate_lines;
+
+ if (!(dpy = XOpenDisplay(""))) {
+ printf("Failed to open display...\n");
+ exit(1);
+ }
+ screen = DefaultScreen(dpy);
+
+ window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100,
+ 300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
+
+ XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask |
+ ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
+ PointerMotionMask | PointerMotionHintMask | Button1MotionMask |
+ Button2MotionMask | Button3MotionMask | Button4MotionMask |
+ Button5MotionMask | ButtonMotionMask | KeymapStateMask |
+ ExposureMask | VisibilityChangeMask | StructureNotifyMask |
+ SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask |
+ PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask);
+
+ XMapWindow(dpy, window);
+
+ /* set this to false to make ShowEvent take up less vertival space */
+ use_separate_lines = True;
+
+ while (1) {
+ XNextEvent(dpy, &event);
+ printf("Detail of %s event:\n", GetType(&event));
+ ShowEvent(&event);
+ printf("\n\n");
+ }
+}
+
+SHAR_EOF
+fi # end of overwriting check
+# End of shell archive
+exit 0
+--
+Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330
+Moderator of comp.sources.x
diff --git a/src/cmd/rio/showevent/patchlevel.h b/src/cmd/rio/showevent/patchlevel.h
new file mode 100644
index 00000000..935ec354
--- /dev/null
+++ b/src/cmd/rio/showevent/patchlevel.h
@@ -0,0 +1 @@
+#define PATCHLEVEL 0
diff --git a/src/cmd/rio/showevent/sample.c b/src/cmd/rio/showevent/sample.c
new file mode 100644
index 00000000..7b22e970
--- /dev/null
+++ b/src/cmd/rio/showevent/sample.c
@@ -0,0 +1,48 @@
+#include <X11/Intrinsic.h>
+
+/*
+ * Disclaimer: No I don't actually code like this but this is a simple,
+ * "Quick-n-Dirty", plain, vanilla, "No ups, No extras" piece of code.
+ */
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+ Display *dpy;
+ int screen;
+ Window window;
+ XEvent event;
+ extern Boolean use_separate_lines;
+
+ if (!(dpy = XOpenDisplay(""))) {
+ printf("Failed to open display...\n");
+ exit(1);
+ }
+ screen = DefaultScreen(dpy);
+
+ window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100,
+ 300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
+
+ XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask |
+ ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
+ PointerMotionMask | PointerMotionHintMask | Button1MotionMask |
+ Button2MotionMask | Button3MotionMask | Button4MotionMask |
+ Button5MotionMask | ButtonMotionMask | KeymapStateMask |
+ ExposureMask | VisibilityChangeMask | StructureNotifyMask |
+ SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask |
+ PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask);
+
+ XMapWindow(dpy, window);
+
+ /* set this to false to make ShowEvent take up less vertival space */
+ use_separate_lines = True;
+
+ while (1) {
+ XNextEvent(dpy, &event);
+ printf("Detail of %s event:\n", GetType(&event));
+ ShowEvent(&event);
+ printf("\n\n");
+ }
+}
+