#include #include #include #include #include #define W (unsigned) Display *d; static long colour (char r, char g, char b) { long c = 0; char *colour = (char*) &c; colour[0]=b; colour[1]=g; colour[2]=r; return c; } static void test (Window a, Window b) { Window root, child; int rx, ry, x, y; unsigned mask; fprintf(stderr,"a:0x%x b:0x%x\n",(unsigned)a,(unsigned)b); XQueryPointer (d, a, &root, &child, &rx, &ry, &x, &y, &mask); fprintf(stderr,"query - root: (%d, %d) a: (%d %d)\n", rx, ry, x, y); XTranslateCoordinates(d, a, b, x, y, &rx, &ry, &child); fprintf(stderr,"trans - b: (%d, %d) a: (%d %d)\n", rx, ry, x, y); fprintf(stderr,"\n"); } int main (int argc, char **argv) { d = XOpenDisplay(NULL); if(!d) return 1; Window w1 = XCreateSimpleWindow(d, RootWindow(d, 0), 100, 100, 400, 400, 0, 0, colour(255,0,0)); Window w2 = XCreateSimpleWindow(d, w1, 0, 0, 64, 64, 0, 0, colour(99,0,99)); Window w3 = XCreateSimpleWindow(d, w1, 400-64, 400-64, 64, 64, 0, 0, colour(99,0,99)); XSelectInput (d, w1, ButtonPressMask | ButtonReleaseMask); XSelectInput (d, w2, ButtonPressMask | ButtonReleaseMask); XSelectInput (d, w3, ButtonPressMask | ButtonReleaseMask); XMapWindow (d, w2); XMapWindow (d, w3); XMapWindow (d, w1); XFlush (d); while(1) { XEvent ev; XNextEvent(d, &ev); switch (ev.type) { case ButtonPress: { fprintf(stderr,"ButtonPress:\n"); fprintf(stderr," event - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n", ev.xbutton.x_root, ev.xbutton.y_root, ev.xbutton.x, ev.xbutton.y,W ev.xbutton.window,W ev.xbutton.subwindow); Window root, child; int x, y, rx, ry, tx, ty; unsigned int mask; XQueryPointer (d, w1, &root, &child, &rx, &ry, &x, &y, &mask); fprintf(stderr," query - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n", rx, ry, x, y, W w1, W child); XTranslateCoordinates(d, w1, root, x, y, &tx, &ty, &child); XTranslateCoordinates(d, root, w1, rx, ry, &x, &y, &child); fprintf(stderr," trans - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n\n", tx, ty, x, y, W w1, W child); } break; case ButtonRelease: { fprintf(stderr,"ButtonRelease:\n"); fprintf(stderr," event - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n", ev.xbutton.x_root, ev.xbutton.y_root, ev.xbutton.x, ev.xbutton.y,W ev.xbutton.window,W ev.xbutton.subwindow); Window root, child; int x, y, rx, ry, tx, ty; unsigned int mask; XQueryPointer (d, w1, &root, &child, &rx, &ry, &x, &y, &mask); fprintf(stderr," query - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n", rx, ry, x, y, W w1, W child); XTranslateCoordinates(d, w1, root, x, y, &tx, &ty, &child); XTranslateCoordinates(d, root, w1, rx, ry, &x, &y, &child); fprintf(stderr," trans - root: (%d, %d) a: (%d %d) w: 0x%x c: 0x%x\n\n", tx, ty, x, y, W w1, W child); } break; default: break; } } }