[comp.windows.x] Window's absolute position

amy@ntpal.UUCP (Dana Amy) (06/14/90)

   I am a beginning X-programmer, and I need to find the absolute
position of a newly created window.  I have a sneaking suspicion
that there is a simple, straightforward method for this, but I have
been unable to discover it.

   My first thought was to traverse the window's ancestorial tree 
and add up all of the x,y offsets:


Widget       window, toplevel;
Window       win, win_root, win_parent;
Display      *disp;
Status       rc;
int          x, y, win_x, win_y, *win_kids, nkids;
unsigned int win_w, win_h, win_border_w, win_depth;

x = 0;
y = 0;

win = XtWindow(window);
root = RootWindowOfScreen(XtScreen(toplevel));
disp = XtDisplay(toplevel);

/* Loop through all windows until the root window is reached */
while (win != root) {
   /* Add the x,y offset of the current window */
   rc = XGetGeometry(disp, win, &win_root, &win_x, &win_y, &win_w, &win_h,
                     &win_border_w, &win_depth);
   x += win_x + win_border_w;
   y += win_y + win_border_w;

   /* Find the parent of the current window */
   rc = XQueryTree(disp, win, &win_root, &win_parent, &win_kids, &nkids);
   XFree(win_kids);
   win = win_parent;
}
   /* Add the x,y offset of the root window */
   rc = XGetGeometry(disp, win, &win_root, &win_x, &win_y, &win_w, &win_h,
                     &win_border_w, &win_depth);
   x += win_x + win_border_w;
   y += win_y + win_border_w;


but while the other information returned by XGetGeometry looks valid,
the win_x and win_y values are ALWAYS 0.  The window opens up in the
middle of the screen.  What is going on?  Is it possible for the 
display to be offset???

I am using X11R4 on a Sun Sparc.

Please e-mail responses if possible.  I will summarize if enough
interest is shown in this problem.

Thank you in advance!
-- 
Dana Amy                     |  "A rock pile ceases to be a rock pile
amy%ntpal@egsner.cirr.com    |  the moment a single man contemplates it,
ntpal!amy@egsner.cirr.com    |  bearing within him the image of a cathedral."
...!texbell!egsner!ntpal!amy |  - Antoine de Saint-Exupery

klee@wsl.dec.com (Ken Lee) (06/15/90)

|> I need to find the absolute position of a newly created window. 

Start with XGetGeometry to get the coordinates of the window relative
to it's parent (possibly a border window from the window manager).
Then use XTranslateCoordinates to convert these to coordinates relative
to the root or any other window.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (06/15/90)

>> I need to find the absolute position of a newly created window.

> Start with XGetGeometry to get the coordinates of the window relative
> to it[']s parent (possibly a border window from the window manager).
> Then use XTranslateCoordinates to convert these to coordinates
> relative to the root or any other window.

Why bother with the XGetGeometry?  Why not use XTranslateCoordinates
directly to translate (0,0) in the new window into root coordinates?

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu