#include #include #include #include #include #include int main(int argc, char **argv) { Display *display; Window root; XEvent event; Window from, to; int x0, y0, x1, y1; if (argc != 1) { char *name; name = strrchr(argv[0], '/'); name = name ? name+1 : argv[0]; fprintf(stderr, "usage: %s\n", name); exit(1); } if ((display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "cannot open display\n"); exit(1); } root = DefaultRootWindow(display); if (XGrabPointer( display, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) { fprintf(stderr, "cannot grab pointer\n"); exit(1); } XNextEvent(display, &event); if (event.type == ButtonPress && event.xbutton.button == 1) { from = event.xbutton.subwindow; x0 = event.xbutton.x_root; y0 = event.xbutton.y_root; if (from == None) from = event.xbutton.window; else from = XmuClientWindow(display, from); if (from != None) { XNextEvent(display, &event); if (event.type == ButtonRelease && event.xbutton.button == 1) { to = event.xbutton.subwindow; x1 = event.xbutton.x_root; y1 = event.xbutton.y_root; if (to == None) to = event.xbutton.window; else to = XmuClientWindow(display, to); if (to != None) { printf("%ld %d %d\n", from, x0, y0); printf("%ld %d %d\n", to, x1, y1); } } } } XCloseDisplay(display); exit(0); }