get windowposition using drawable and display

Carsten Haitzler (The Rasterman) raster at
Sun Aug 6 16:19:26 PDT 2006

On Sun, 06 Aug 2006 18:02:26 +0200 dragoran <dragoran at> babbled:

> Hello
> Is it possible to query the position of a window when only the display 
> and drawable are known?
> (this should be done inside a glxSwapbuffers wrapper)
> this:
> Window win;
> unsigned int x, y, width, height, border, depth;
> XGetGeometry(dpy, drawable, &win, &x, &y, &width, &height, &border, &depth);
> printf("%dx%d (%d, %d)\n", width, height, x, y);
> prints 0 and 0 for x,y on one sys and segfaults on a other sys...
> can the parent window of a drawable be queried somehow?

1.  segv probbly due to dpy being wrong - not likely an xlib bug
2. you want to do a ROUND TRIP TO X every time to flip a frame? are you MAD?
don't do this - DONT. just DON'T. if you need to know x,y of your window, keep
it up to date via configurenotify events - pay special attetion to the send
event flag as when your window is managed by a window manager it will send you
synthetic configurenotifies whenever your window moves.
3. getting geometry will get the window x,y relative to its PARENT. the PARENT
window once managed by a reparenting window manager (pretty much 99.9% of wm's
are reparenting), will be put into another sub window - the window
"frame" (where it draws the titlebar, resize handles etc.). this frame belongs
to the wm and then this frame may be a child of root - or something else. the
wm may put in any number of windows in between your window and root - so to
accurately query this without any problems you need to do a recursive query to
find each successive parent of your window until you finally find root and query
the geometry at each step of each parent too and adjust your relative geometry.
this would mean a sequence of (N+1)*2 round-trips to x (where N is how many
intermediate parents between your window and root). not to mention
that to avid races where your window tree may be changing under you -
you need to grab the server then ungrab as well between these
queries. this is entirely BAD - in fact probably worse than the round
trips as it now impacts every x client and everything will be
stuttery and jerky as all x clients are locked out during a server
grab - they can't draw, update, respond to events etc. round-trips are SLOW...

so summary: use events - keep an updated x,y co-ord pair and use those when you
need it. don't do query calls to x if you can avoid it.

------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    raster at
Tokyo, Japan (東京 日本)

More information about the xorg mailing list