[comp.windows.x] how do you get correct window position?

davy@itstd.sri.COM (06/14/90)

Given the following code fragment:

	Widget w, toplevel;

	toplevel = ...

	w = XtCreatePopupShell(name, wmShellWidgetClass, toplevel,
		args, nargs);

	/* create widgets inside the shell widget */

How do I get the *correct* (x,y) position of the window belonging to
the shell widget so I can create another one in exactly the same
place?  Currently, I am doing:

	WindowAttributes win_attributes;

	XGetWindowAttributes(display, XtWindow(w), &win_attributes);

	XTranslateCoordinates(display, XtWindow(w), root_window,
		win_attributes.x, win_attributes.y, &savex, &savey, &junk);

and then using savex and savey.  However, when I recreate the shell
widget in the next invocation of the program, using savex and savey in
the geometry argument, the window is a couple of pixels down and to
the right.  So every time I save the position and recreate, the window
moves a little bit.  Not good.

As near as I can figure, since twm is putting a border on the window
of the shell widget, I need to be taking that into account.  But I've
been running through the manuals for an hour and a half and can't find
any routine which will tell me how big the border twm is sticking on
there is!

Can anyone suggest how to do this?  (Note: I'm not particularly attached
to using XGetWindowAttributes, so if there's a better function, please
let me know.)

Thanks,
Dave Curry
davy@itstd.sri.com

asente@wrl.dec.com (Paul Asente) (06/14/90)

In article <9006131913.AA02147@intrepid.itstd.sri.com> davy@itstd.sri.COM writes:
>How do I get the *correct* (x,y) position of the window belonging to
>the shell widget so I can create another one in exactly the same
>place?

If you have an ICCCM-compliant window manager (as I belive the R4 twm is)
XtTranslateCoords should do the trick for you.

	-paul asente
	    asente@decwrl.dec.com	...!decwrl!asente

toml@ninja.Solbourne.COM (Tom LaStrange) (06/14/90)

>>How do I get the *correct* (x,y) position of the window belonging to
>>the shell widget so I can create another one in exactly the same
>>place?
>
> If you have an ICCCM-compliant window manager (as I belive the R4 twm is)
> XtTranslateCoords should do the trick for you.

Yes but if he wants the new window to be positioned at the same
location as the already reparented one, doesn't he really need the
coordinates of the window manager's outside frame window?  As far as I
know, there is no way for an application to find the window manager's
outside frame window.  You can't simply find the ancestor that's on top
of the root, what if the window manager has placed its frame on a
"pseudo" root that's a child of the real root window.  I personally
would like to see a WM_ROOT property placed on client windows that
would contain the window ID of the "root" window for the client.  The
client would then be able to find the window manager's outside frame
window and it would also allow window managers to do interesting things
with "pseudo" root windows.

--
Tom LaStrange

Solbourne Computer Inc.    ARPA: toml@Solbourne.COM
1900 Pike Rd.              UUCP: ...!{boulder,sun}!stan!toml
Longmont, CO  80501

msm@src.dec.com (Mark S. Manasse) (06/14/90)

Unfortunately, you can't do this, at least not with a fully
ICCCM-compliant window manager.  The ICCCM, as adopted, insists
that the placement of a window is specified by a relative positioning
for a corner or edge of the window, including decoration.  There's no
way to specify the absolute position of any pixel of your window.

However, you can compute the difference between where you asked to
pop up initially, and where you showed up.  Since the decoration
geometry for a window will *typically* be unchanged the next time
the same window shows up, you might try adjusting your request
by that difference.  Hania Gajewska and I used that technique to
allow us to move windows back to where they came from in our rooms
manager.  There's no guarantee that it will work, but there's some
hope.

You could, instead, try to figure out which ancestor window is the
frame provided by the window manager, discover its geometry, and then
try to bias by that amount.  I suspect that you would discover that
many ICCCM window managers will still disagree by a few pixels (say,
by a border width or so for that frame window) on exactly where to
place your window.

Mark