[comp.windows.x.motif] Getting the position

carl@quad1.quad.com (Carl Priddy) (10/04/90)

Hey out there:
	I have a DrawingArea Widget which is the work area of a main window.
	The main window is a child of an application shell. I need to get
	the top left corner position of the Drawing Area relative to the
	root window, in order to position a popup menu (with XmMenuPosition)
	to a particular location within it. XmMenuPosition (naturally) does
	not accept window-relative positioning, but requires the user to
	compute and set x_root and y_root (yes, this IS another of those 
	"convenience" functions!). The problem I am seeing is that
	XGetGeometry returns 0 for both the x and y positions for ALL of the
	windows between DrawingArea and root. Using XtGetValues is no better.
	Can anyone shed some light on this?
	
Thanks a heap,
carl. 

klee@wsl.dec.com (Ken Lee) (10/04/90)

In article <15307@gouda.quad.com>, carl@quad1.quad.com (Carl Priddy) writes:
|>      I need to get
|> 	the top left corner position of the Drawing Area relative to the
|> 	root window

Try XTranslateCoordinates.

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

db3l@ibm.com (David Bolen) (10/04/90)

In article <15307@gouda.quad.com> carl@quad1.quad.com (Carl Priddy) writes:
> I have a DrawingArea Widget which is the work area of a main window.
> The main window is a child of an application shell. I need to get
> the top left corner position of the Drawing Area relative to the
> root window			[...]
>                            The problem I am seeing is that
> XGetGeometry returns 0 for both the x and y positions for ALL of the
> windows between DrawingArea and root. Using XtGetValues is no better.
> Can anyone shed some light on this?

I just recently ran up against the same problem.  I tried XtGetValues,
XGetGeometry and XGetWindowAttributes for all the windows I knew about,
and always got (0,0) as a position.

It turns out (I believe) that this is because mwm is a "reparenting window
manager," which means that even what you think is your top level window (your
application shell) has actually been forced to have a parent by mwm, which
is the window mwm uses for handling the "decorations."  Thus, even the
position of your application shell is relative to a parent, and is at (0,0).
I don't know how to find out what that parent is, and it doesn't show up
when traversing the window hierarchy, at least with XtParent.  Besides
which, not all window managers will do this, so trying to determine the
"hidden" parent isn't all that smart anyway.

I finally settled for using the XTranslateCoordinates function to translate
the coordinate (0,0) for my main window work area (which like you is a
DrawingArea widget) to coordinates based on the root window.  This seems to
work just fine, and doesn't depend on the parentage of the widget.  You
can use DefaultRootWindow(-display-) as your root window target for the
function if you don't have the root id already.

-- David
--
/-----------------------------------------------------------------------\      
 \                             David Bolen                             /
  |    Laboratory Automation, IBM Thomas J. Watson Research Center    |
 /              P.O. Box 218, Yorktown Heights, NY  10598              \
| - - - - - - - - - - - -  M i t h r a n d i r  - - - - - - - - - - - - |
| Internet : db3l@ibm.com                    | Bitnet : db3l@yktvmv     |
| Usenet   : uunet!bywater!arnor!larios!db3l | Phone  : (914) 945-1940  |
\-----------------------------------------------------------------------/