Newsgroups: comp.windows.x
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!ispd-newsserver!ism.isc.com!ico!auto-trol!marbru
From: marbru@auto-trol.com (Martin Brunecky)
Subject: Re: How do I get ID of the window that contains the pointer ?
Message-ID: <1991Apr16.155227.4095@auto-trol.com>
Reply-To: marbru@auto-trol.UUCP (Martin Brunecky)
Organization: Auto-trol Technology, Denver
References: <671411930.29062@mindcraft.com>
Distribution: usa
Date: Tue, 16 Apr 1991 15:52:27 GMT

In article <671411930.29062@mindcraft.com> subodh@mindcraft.com (Subodh Nijsure) writes:
>
>	How do I get ID of the window that holds the pointer ? 
>
      This is a fragment od the code used to send an event to a window
      containing a pointer. You may find a better solution, of course ...
      The target window may be owned by any application, whowever, this
      code only looks for windows interested in a particular event ..

    ......
    /* Find the pointer, if not on our screen, don't send anything */
    if (XQueryPointer( dpy, root, &root, &child, &rx, &ry, &wx, &wy, &mods ) )
    {
        XButtonEvent    bev;
        Window          wins[MAX_WINDOW_STACK];
        int             x[MAX_WINDOW_STACK];
        int             y[MAX_WINDOW_STACK];
        unsigned int    mask =  ButtonPressMask; 
        register int    iw = 0;
        int             ic = 0;         /* index of constraint window */

        /* save root window on our window stack */
        wins[iw] = root;  x[iw] = rx;  y[iw++] = ry;

        /* find the topmost window containing the pointer */
        while ( child != None )
        {
           win = child;
           if ( win == XtWindow(w) ) ic = iw; /* check for constraining win */
           XTranslateCoordinates ( dpy, root, win, rx, ry, &wx, &wy, &child );
           wins[iw] = win;  x[iw] = wx;  y[iw++] = wy;
           if (iw > MAX_WINDOW_STACK) return (FALSE);
        }
        wins[iw] = None;    /* make sure last "next' window is null */

        /* find the window which wants our event, give up on don't propagate */
        for ( --iw; iw >= 0; --iw)
        {
           XWindowAttributes attr;
           if ( XGetWindowAttributes ( dpy, wins[iw], &attr ))
           {
                if (attr.all_event_masks & mask       ) break;
                if (attr.map_state != IsViewable      ) continue;
                if (attr.do_not_propagate_mask & mask ) return(FALSE);
           }
        }

        .....

-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                           {...}sunpeaks!auto-trol!marbru
(303) 252-2499                        (sometimes also:  marbru@auto-trol.COM )
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404 
