home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!mouse
- From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
- Newsgroups: comp.windows.x
- Subject: Re: Window the pointer is in?
- Message-ID: <1992Nov7.103711.19692@thunder.mcrcim.mcgill.edu>
- Date: 7 Nov 92 10:37:11 GMT
- References: <1d8lhiINN27a@seven-up.East.Sun.COM>
- Distribution: na
- Organization: McGill Research Centre for Intelligent Machines
- Lines: 48
-
- In article <1d8lhiINN27a@seven-up.East.Sun.COM>, marc@betelgeuse.East.Sun.COM (Marc St-Hilaire Canadian Dev. Ctr - Montreal) writes:
-
- > How could I find the window ID of the topmost window that contains
- > the mouse pointer?
-
- "topmost" in what sense?
-
- > If I do an XQueryPointer(dpy, root_window, ...), the returned child
- > window is a window manager window.
-
- This is WM-dependent; it'll be true only for reparenting WMs.
-
- > However the window that I am looking for is a leaf window of the
- > window tree of an X client.
-
- Hm. So "topmost" does not refer to window tree hierarchy. I assume
- what you actually want is the lowest window in the window tree such
- that the pointer cursor's hot-spot is within the viewable portion of
- the window and that the pixel of the window under the hot-spot is not
- obscured by any other window. (This mouthful is the simplest
- descrption I've been able to come up with for what really is a very
- simple concept. If anyone has a simpler, but also precise, way of
- saying the same thing, I'd like to hear it.)
-
- > Can this be done without having to make recursive calls to
- > XQueryTree(), followed by an XGetGeometry() on each child window to
- > figure out in which one the mouse pointer is in?
-
- Just call XQueryPointer repeatedly, starting with the root, recursing
- down the window tree. Note that there are race conditions; the pointer
- must be frozen, and to be fully correct, the server must be grabbed as
- well, though if all the windows in question belong to either the window
- manager or the client doing the searching, omitting the server grab
- would not be unreasonable.
-
- If you don't know which screen the pointer is on (and thus which root
- window to start the querying with), pick any screen, and if you get it
- wrong, the first XQueryPointer will tell you so (and also tell you
- which root window you do need to start with).
-
- Normally, though, you don't need this, because pointer and keyboard
- events carry this information with them. You may be trying to solve
- the wrong problem....
-
- der Mouse
-
- mouse@larry.mcrcim.mcgill.edu
-