Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!agate!ucbvax!hplabs!hpfcdc!hpfclp!diamant From: diamant@hpfclp.SDE.HP.COM (John Diamant) Newsgroups: comp.windows.x Subject: Re: How can I implement a query window at position ? Message-ID: <9740100@hpfclp.SDE.HP.COM> Date: 21 Aug 89 05:56:01 GMT References: <8908121716.AA12203@expo.lcs.mit.edu> Organization: HP SESD, Fort Collins, CO Lines: 40 > I would like to find out what is the window at a certain screen position. > Is there any way to do it without using the hack about warping the mouse > to that position and do a XQueryPointer and then warp back the mouse. > My current hack cannot work when you have EnterNotify and LeaveNotify set. You can use XTranslateCoordinates. For example, here's a piece of code I use to find the smallest window in which the pointer was when the function was called (it expected a call to XQueryPointer to be done prior to the call, but you could pass in the root window and the x y coordinates instead): void find_smallest_window(dpy, parent, child, win_x, win_y) Display *dpy; Window *parent, *child; int win_x, win_y; { Window win; if (!child) child = parent; /* Note: The function XTranslateCoordinates must be used instead of */ /* XQueryPointer to avoid dependence on the pointer remaining */ /* stationary. This eliminates the race condition of the pointer */ /* moving, but not the one of the window hierarchy changing */ while (XTranslateCoordinates(dpy, *parent, *child, win_x, win_y, &win_x, &win_y, &win) && win != NULL) { *parent = *child; *child = win; } } John Diamant Software Engineering Systems Division Hewlett-Packard Co. Internet: diamant@hpfclp.sde.hp.com Fort Collins, CO UUCP: {hplabs,hpfcla}!hpfclp!diamant