diff options
-rw-r--r-- | xev.c | 321 | ||||
-rw-r--r-- | xev.man | 24 |
2 files changed, 213 insertions, 132 deletions
@@ -28,7 +28,7 @@ other dealings in this Software without prior written authorization from the X Consortium. */ -/* $XFree86: xc/programs/xev/xev.c,v 1.7 2002/12/24 17:43:00 tsi Exp $ */ +/* $XFree86: xc/programs/xev/xev.c,v 1.13 2003/10/24 20:38:17 tsi Exp $ */ /* * Author: Jim Fulton, MIT X Consortium @@ -68,10 +68,10 @@ const char *ProgramName; Display *dpy; int screen; -void -prologue (eventp, event_name) - XEvent *eventp; - char *event_name; +XIC xic = NULL; + +static void +prologue (XEvent *eventp, char *event_name) { XAnyEvent *e = (XAnyEvent *) eventp; @@ -79,43 +79,98 @@ prologue (eventp, event_name) event_name, e->serial, e->send_event ? Yes : No, e->window); } +static void +dump (char *str, int len) +{ + printf("("); + len--; + while (len-- > 0) + printf("%02x ", *str++); + printf("%02x)", *str++); +} -void -do_KeyPress (eventp) - XEvent *eventp; +static void +do_KeyPress (XEvent *eventp) { XKeyEvent *e = (XKeyEvent *) eventp; KeySym ks; + KeyCode kc = 0; + Bool kc_set = False; char *ksname; - int nbytes; + int nbytes, nmbbytes = 0; char str[256+1]; + static char *buf = NULL; + static int bsize = 8; + Status status; + + if (buf == NULL) + buf = malloc (bsize); nbytes = XLookupString (e, str, 256, &ks, NULL); + + /* not supposed to call XmbLookupString on a key release event */ + if (e->type == KeyPress && xic) { + do { + nmbbytes = XmbLookupString (xic, e, buf, bsize - 1, &ks, &status); + buf[nmbbytes] = '\0'; + + if (status == XBufferOverflow) { + bsize = nmbbytes + 1; + buf = realloc (buf, bsize); + } + } while (status == XBufferOverflow); + } + if (ks == NoSymbol) ksname = "NoSymbol"; - else if (!(ksname = XKeysymToString (ks))) - ksname = "(no name)"; + else { + if (!(ksname = XKeysymToString (ks))) + ksname = "(no name)"; + kc = XKeysymToKeycode(dpy, ks); + kc_set = True; + } + printf (" root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),\n", e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root); printf (" state 0x%x, keycode %u (keysym 0x%lx, %s), same_screen %s,\n", e->state, e->keycode, (unsigned long) ks, ksname, e->same_screen ? Yes : No); + if (kc_set && e->keycode != kc) + printf (" XKeysymToKeycode returns keycode: %u\n",kc); if (nbytes < 0) nbytes = 0; if (nbytes > 256) nbytes = 256; str[nbytes] = '\0'; - printf (" XLookupString gives %d bytes: \"%s\"\n", nbytes, str); + printf (" XLookupString gives %d bytes: ", nbytes); + if (nbytes > 0) { + dump (str, nbytes); + printf (" \"%s\"\n", str); + } else { + printf ("\n"); + } + + /* not supposed to call XmbLookupString on a key release event */ + if (e->type == KeyPress && xic) { + printf (" XmbLookupString gives %d bytes: ", nmbbytes); + if (nmbbytes > 0) { + dump (buf, nmbbytes); + printf (" \"%s\"\n", buf); + } else { + printf ("\n"); + } + + printf (" XFilterEvent returns: %s\n", + XFilterEvent (eventp, e->window) ? "True" : "False"); + } } -void -do_KeyRelease (eventp) - XEvent *eventp; +static void +do_KeyRelease (XEvent *eventp) { do_KeyPress (eventp); /* since it has the same info */ } -void -do_ButtonPress (eventp) - XEvent *eventp; +static void +do_ButtonPress (XEvent *eventp) { XButtonEvent *e = (XButtonEvent *) eventp; @@ -125,16 +180,14 @@ do_ButtonPress (eventp) e->state, e->button, e->same_screen ? Yes : No); } -void -do_ButtonRelease (eventp) - XEvent *eventp; +static void +do_ButtonRelease (XEvent *eventp) { do_ButtonPress (eventp); /* since it has the same info */ } -void -do_MotionNotify (eventp) - XEvent *eventp; +static void +do_MotionNotify (XEvent *eventp) { XMotionEvent *e = (XMotionEvent *) eventp; @@ -144,9 +197,8 @@ do_MotionNotify (eventp) e->state, e->is_hint, e->same_screen ? Yes : No); } -void -do_EnterNotify (eventp) - XEvent *eventp; +static void +do_EnterNotify (XEvent *eventp) { XCrossingEvent *e = (XCrossingEvent *) eventp; char *mode, *detail; @@ -179,16 +231,14 @@ do_EnterNotify (eventp) printf (" focus %s, state %u\n", e->focus ? Yes : No, e->state); } -void -do_LeaveNotify (eventp) - XEvent *eventp; +static void +do_LeaveNotify (XEvent *eventp) { do_EnterNotify (eventp); /* since it has same information */ } -void -do_FocusIn (eventp) - XEvent *eventp; +static void +do_FocusIn (XEvent *eventp) { XFocusChangeEvent *e = (XFocusChangeEvent *) eventp; char *mode, *detail; @@ -217,16 +267,14 @@ do_FocusIn (eventp) printf (" mode %s, detail %s\n", mode, detail); } -void -do_FocusOut (eventp) - XEvent *eventp; +static void +do_FocusOut (XEvent *eventp) { do_FocusIn (eventp); /* since it has same information */ } -void -do_KeymapNotify (eventp) - XEvent *eventp; +static void +do_KeymapNotify (XEvent *eventp) { XKeymapEvent *e = (XKeymapEvent *) eventp; int i; @@ -239,9 +287,8 @@ do_KeymapNotify (eventp) printf ("\n"); } -void -do_Expose (eventp) - XEvent *eventp; +static void +do_Expose (XEvent *eventp) { XExposeEvent *e = (XExposeEvent *) eventp; @@ -249,9 +296,8 @@ do_Expose (eventp) e->x, e->y, e->width, e->height, e->count); } -void -do_GraphicsExpose (eventp) - XEvent *eventp; +static void +do_GraphicsExpose (XEvent *eventp) { XGraphicsExposeEvent *e = (XGraphicsExposeEvent *) eventp; char *m; @@ -268,9 +314,8 @@ do_GraphicsExpose (eventp) printf (" major %s, minor %d\n", m, e->minor_code); } -void -do_NoExpose (eventp) - XEvent *eventp; +static void +do_NoExpose (XEvent *eventp) { XNoExposeEvent *e = (XNoExposeEvent *) eventp; char *m; @@ -286,9 +331,8 @@ do_NoExpose (eventp) return; } -void -do_VisibilityNotify (eventp) - XEvent *eventp; +static void +do_VisibilityNotify (XEvent *eventp) { XVisibilityEvent *e = (XVisibilityEvent *) eventp; char *v; @@ -304,9 +348,8 @@ do_VisibilityNotify (eventp) printf (" state %s\n", v); } -void -do_CreateNotify (eventp) - XEvent *eventp; +static void +do_CreateNotify (XEvent *eventp) { XCreateWindowEvent *e = (XCreateWindowEvent *) eventp; @@ -316,18 +359,16 @@ do_CreateNotify (eventp) e->border_width, e->override_redirect ? Yes : No); } -void -do_DestroyNotify (eventp) - XEvent *eventp; +static void +do_DestroyNotify (XEvent *eventp) { XDestroyWindowEvent *e = (XDestroyWindowEvent *) eventp; printf (" event 0x%lx, window 0x%lx\n", e->event, e->window); } -void -do_UnmapNotify (eventp) - XEvent *eventp; +static void +do_UnmapNotify (XEvent *eventp) { XUnmapEvent *e = (XUnmapEvent *) eventp; @@ -335,9 +376,8 @@ do_UnmapNotify (eventp) e->event, e->window, e->from_configure ? Yes : No); } -void -do_MapNotify (eventp) - XEvent *eventp; +static void +do_MapNotify (XEvent *eventp) { XMapEvent *e = (XMapEvent *) eventp; @@ -345,18 +385,16 @@ do_MapNotify (eventp) e->event, e->window, e->override_redirect ? Yes : No); } -void -do_MapRequest (eventp) - XEvent *eventp; +static void +do_MapRequest (XEvent *eventp) { XMapRequestEvent *e = (XMapRequestEvent *) eventp; printf (" parent 0x%lx, window 0x%lx\n", e->parent, e->window); } -void -do_ReparentNotify (eventp) - XEvent *eventp; +static void +do_ReparentNotify (XEvent *eventp) { XReparentEvent *e = (XReparentEvent *) eventp; @@ -366,9 +404,8 @@ do_ReparentNotify (eventp) e->override_redirect ? Yes : No); } -void -do_ConfigureNotify (eventp) - XEvent *eventp; +static void +do_ConfigureNotify (XEvent *eventp) { XConfigureEvent *e = (XConfigureEvent *) eventp; @@ -378,9 +415,8 @@ do_ConfigureNotify (eventp) e->border_width, e->above, e->override_redirect ? Yes : No); } -void -do_ConfigureRequest (eventp) - XEvent *eventp; +static void +do_ConfigureRequest (XEvent *eventp) { XConfigureRequestEvent *e = (XConfigureRequestEvent *) eventp; char *detail; @@ -401,9 +437,8 @@ do_ConfigureRequest (eventp) e->border_width, e->above, detail, e->value_mask); } -void -do_GravityNotify (eventp) - XEvent *eventp; +static void +do_GravityNotify (XEvent *eventp) { XGravityEvent *e = (XGravityEvent *) eventp; @@ -411,18 +446,16 @@ do_GravityNotify (eventp) e->event, e->window, e->x, e->y); } -void -do_ResizeRequest (eventp) - XEvent *eventp; +static void +do_ResizeRequest (XEvent *eventp) { XResizeRequestEvent *e = (XResizeRequestEvent *) eventp; printf (" width %d, height %d\n", e->width, e->height); } -void -do_CirculateNotify (eventp) - XEvent *eventp; +static void +do_CirculateNotify (XEvent *eventp) { XCirculateEvent *e = (XCirculateEvent *) eventp; char *p; @@ -438,9 +471,8 @@ do_CirculateNotify (eventp) e->event, e->window, p); } -void -do_CirculateRequest (eventp) - XEvent *eventp; +static void +do_CirculateRequest (XEvent *eventp) { XCirculateRequestEvent *e = (XCirculateRequestEvent *) eventp; char *p; @@ -456,9 +488,8 @@ do_CirculateRequest (eventp) e->parent, e->window, p); } -void -do_PropertyNotify (eventp) - XEvent *eventp; +static void +do_PropertyNotify (XEvent *eventp) { XPropertyEvent *e = (XPropertyEvent *) eventp; char *aname = XGetAtomName (dpy, e->atom); @@ -477,9 +508,8 @@ do_PropertyNotify (eventp) if (aname) XFree (aname); } -void -do_SelectionClear (eventp) - XEvent *eventp; +static void +do_SelectionClear (XEvent *eventp) { XSelectionClearEvent *e = (XSelectionClearEvent *) eventp; char *sname = XGetAtomName (dpy, e->selection); @@ -490,9 +520,8 @@ do_SelectionClear (eventp) if (sname) XFree (sname); } -void -do_SelectionRequest (eventp) - XEvent *eventp; +static void +do_SelectionRequest (XEvent *eventp) { XSelectionRequestEvent *e = (XSelectionRequestEvent *) eventp; char *sname = XGetAtomName (dpy, e->selection); @@ -510,9 +539,8 @@ do_SelectionRequest (eventp) if (pname) XFree (pname); } -void -do_SelectionNotify (eventp) - XEvent *eventp; +static void +do_SelectionNotify (XEvent *eventp) { XSelectionEvent *e = (XSelectionEvent *) eventp; char *sname = XGetAtomName (dpy, e->selection); @@ -530,9 +558,8 @@ do_SelectionNotify (eventp) if (pname) XFree (pname); } -void -do_ColormapNotify (eventp) - XEvent *eventp; +static void +do_ColormapNotify (XEvent *eventp) { XColormapEvent *e = (XColormapEvent *) eventp; char *s; @@ -548,9 +575,8 @@ do_ColormapNotify (eventp) e->colormap, e->new ? Yes : No, s); } -void -do_ClientMessage (eventp) - XEvent *eventp; +static void +do_ClientMessage (XEvent *eventp) { XClientMessageEvent *e = (XClientMessageEvent *) eventp; char *mname = XGetAtomName (dpy, e->message_type); @@ -561,9 +587,8 @@ do_ClientMessage (eventp) if (mname) XFree (mname); } -void -do_MappingNotify (eventp) - XEvent *eventp; +static void +do_MappingNotify (XEvent *eventp) { XMappingEvent *e = (XMappingEvent *) eventp; char *r; @@ -583,12 +608,10 @@ do_MappingNotify (eventp) -void -set_sizehints (hintp, min_width, min_height, - defwidth, defheight, defx, defy, geom) - XSizeHints *hintp; - int min_width, min_height, defwidth, defheight, defx, defy; - char *geom; +static void +set_sizehints (XSizeHints *hintp, int min_width, int min_height, + int defwidth, int defheight, int defx, int defy, + char *geom) { int geom_result; @@ -640,10 +663,10 @@ set_sizehints (hintp, min_width, min_height, #if defined(__GNUC__) && \ ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7))) -void usage () __attribute__((__noreturn__)); +static void usage (void) __attribute__((__noreturn__)); #endif -void -usage () +static void +usage (void) { static const char *msg[] = { " -display displayname X server to contact", @@ -667,8 +690,8 @@ NULL}; exit (1); } -static int parse_backing_store (s) - char *s; +static int +parse_backing_store (char *s) { int len = strlen (s); char *cp; @@ -686,9 +709,7 @@ static int parse_backing_store (s) } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *displayname = NULL; char *geom = NULL; @@ -703,6 +724,11 @@ main (argc, argv) char *name = "Event Tester"; Bool reverse = False; unsigned long back, fore; + XIM xim; + XIMStyles *xim_styles; + XIMStyle xim_style = 0; + char *modifiers; + char *imvalret; ProgramName = argv[0]; @@ -743,7 +769,7 @@ main (argc, argv) if (++i >= argc) usage (); sscanf(argv[i], "0x%lx", &w); if (!w) - sscanf(argv[i], "%ld", &w); + sscanf(argv[i], "%lu", &w); if (!w) usage (); continue; @@ -772,6 +798,41 @@ main (argc, argv) exit (1); } + /* we're testing the default input method */ + modifiers = XSetLocaleModifiers ("@im=none"); + if (modifiers == NULL) { + fprintf (stderr, "%s: XSetLocaleModifiers failed\n", ProgramName); + } + + xim = XOpenIM (dpy, NULL, NULL, NULL); + if (xim == NULL) { + fprintf (stderr, "%s: XOpenIM failed\n", ProgramName); + } + + if (xim) { + imvalret = XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL); + if (imvalret != NULL || xim_styles == NULL) { + fprintf (stderr, "%s: input method doesn't support any styles\n", ProgramName); + } + + if (xim_styles) { + xim_style = 0; + for (i = 0; i < xim_styles->count_styles; i++) { + if (xim_styles->supported_styles[i] == + (XIMPreeditNothing | XIMStatusNothing)) { + xim_style = xim_styles->supported_styles[i]; + break; + } + } + + if (xim_style == 0) { + fprintf (stderr, "%s: input method doesn't support the style we support\n", + ProgramName); + } + XFree (xim_styles); + } + } + screen = DefaultScreen (dpy); /* select for all events */ @@ -830,6 +891,18 @@ main (argc, argv) printf ("Outer window is 0x%lx, inner window is 0x%lx\n", w, subw); } + if (xim && xim_style) { + xic = XCreateIC (xim, + XNInputStyle, xim_style, + XNClientWindow, w, + XNFocusWindow, w, + NULL); + + if (xic == NULL) { + fprintf (stderr, "XCreateIC failed\n"); + } + } + for (done = 0; !done; ) { XEvent event; @@ -975,5 +1048,5 @@ main (argc, argv) } XCloseDisplay (dpy); - exit (0); + return 0; } @@ -1,6 +1,6 @@ .\" $XConsortium: xev.man,v 1.10 94/04/17 20:45:20 gildea Exp $ .\" -.\" $XFree86: xc/programs/xev/xev.man,v 1.3 2001/01/27 18:21:11 dawes Exp $ +.\" $XFree86: xc/programs/xev/xev.man,v 1.4 2003/05/24 15:49:02 herrb Exp $ .\" .TH XEV 1 __xorgversion__ .SH NAME @@ -13,31 +13,39 @@ xev - print contents of X events .SH DESCRIPTION .PP \fIXev\fP creates a window and then asks the X server to send it -\fIevents\fP whenever anything happens to the window (such as being moved, -resized, typed in, clicked in, etc.). You can also attach it to an -existing window. It is useful for seeing what causes -events to occur and to display the information that they contain. +\fIevents\fP whenever anything happens to the window (such as it being +moved, resized, typed in, clicked in, etc.). You can also attach it to an +existing window. It is useful for seeing what causes events to occur and to +display the information that they contain; it is essentially a debugging and +development tool, and should not be needed in normal usage. .SH OPTIONS .TP 8 .B \-display \fIdisplay\fP This option specifies the X server to contact. .TP 8 .B \-geometry \fIgeom\fP -This option specifies the size and/or location of the window. +This option specifies the size and/or location of the window, if a window is +to be created. .TP 8 .B \-bw \fIpixels\fP This option specifies the border width for the window. .TP 8 .B \-bs \fI{NotUseful,WhenMapped,Always}\fP This option specifies what kind of backing store to give the window. -The default is NotUseful. +The default is NotUseful. Backing store refers to the the pixels saved +off-screen when the X server maintains the contents of a window; NotUseful +means that the xev process will redraw its contents itself, as necessary. .TP 8 .B \-id \fIwindowid\fP This option specifies that the window with the given id should be monitored, instead of creating a new window. .TP 8 .B \-s -This option specifies that save-unders should be enabled on the window. +This option specifies that save-unders should be enabled on the window. Save +unders are similar to backing store, but they refer rather to the saving of +pixels off-screen when the current window obscures other windows. Save +unders are only advisory, and are normally set for popup dialogs and other +transient windows. .TP 8 .B \-name \fIstring\fP This option specifies the name to assign to the created window. |