[comp.windows.x] updating widget state after a wm move

omtzigt-theo@CS.Yale.EDU (theo omtzigt) (02/05/90)

This must be a very simple question for anyone who has programmed up
any user interface, but I am kind of stuck. This is the problem;
I define a form widget that contains command buttons. The functionality
of the buttons is to pop down a menu through the call back routines.
To be able to pull down the menu at the right place, I am querying 
the x and y position of both the form and the relative position of 
the button. However, the state of the widget that I get back 
through XtGetValues, is the position of the widget at realization, 
which is not necessarily the position where the widget is, because
the user may have moved the widget. I do realize that I have to 
catch a move event from the window manager, but I can`t find the 
event to put in the translation table. So, I have this feeling that
it is not the way to go about this. Does any body know how to solve
this problem, either through a different approach or pointing me
to the right event to put in the translation table? Thanks in advance,

Theo 
omtzigt-theo@cs.yale.edu

marbru@auto-trol.UUCP (Martin Brunecky) (02/06/90)

In article <14274@cs.yale.edu> omtzigt-theo@CS.Yale.EDU (theo omtzigt) writes:
>
>This must be a very simple question for anyone who has programmed up
>any user interface, but I am kind of stuck. This is the problem;
>I define a form widget that contains command buttons. The functionality
>of the buttons is to pop down a menu through the call back routines.
>To be able to pull down the menu at the right place, I am querying 
>the x and y position of both the form and the relative position of 
>the button. However, the state of the widget that I get back 
>through XtGetValues, is the position of the widget at realization, 
>
......

	Depending on the window manager and/or vendorShell, you either
	get the "right" behavior or thr "wrong" behavior. I'v seen
	several window managers that do not bother to send configuration
	events to the window they moved.
	The simplest solution is using XTranslateCoordinates instead
	of XtTranslateCoords. You pay a roundtrip delay... so my code
	uses #ifdef and on machines with guaranteed window manager
	(such as DEC for this case) use faster XtTranslate...

	

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Martin Brunecky                   marbru@auto-trol.COM
(303) 252-2499                    {...}ncar!ico!auto-trol!marbru
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404 

meo@stiatl.UUCP (Miles O'Neal) (02/07/90)

In article <14274@cs.yale.edu> omtzigt-theo@CS.Yale.EDU (theo omtzigt) writes:
|
|To be able to pull down the menu at the right place, I am querying 
|the x and y position of both the form and the relative position of 
|the button. However, the state of the widget that I get back 
|through XtGetValues, is the position of the widget at realization, 
|which is not necessarily the position where the widget is, because
|the user may have moved the widget.

Use XQueryPointer - it returns the cursor position relative to both the
window it's in and the root window.

Example:

/* Code isn't optimal as I ripped out some other stuff we do */

GetXY (w, x, y)

Widget w;            /* widget cursor is currently in */
int *x, *y;          /* locs to hold new (x, y) */
{
   Display *D;       /* display the widget is on */
   Window W,         /* input window */
          rootW,     /* root window returned from XQueryPointer */
          childW;    /* child window returned from XQueryPointer */
   int rx,           /* root-relative x location of pointer */
       ry,           /* root-relative y location of pointer */
       wx,           /* widget-relative x location of pointer */
       wy;           /* widget-relative y location of pointer */
   unsigned int jive;      /* current mouse buttons */

   D = XtDisplay (w);
   W = XtWindow (w);
   XQueryPointer (D, W, &rootW, &childW, &rx, &ry, &wx, &wy, &jive);
   *x = rx;
   *y = ry;
}