[comp.windows.x] Checking for valid Window ID

atmaram@csun11.cs.uh.edu (S. Atmaram) (03/16/90)

My program has the Window ID of a window on a remote display. I
wish to check whether or not the ID is valid (that is, whether the
window still exists), before doing an XSendEvent.

Any pointers as to how I can determine this ?

Thanks.

Atmaram
atmaram@cs.uh.edu

klee@wsl.dec.com (Ken Lee) (03/16/90)

In article <24321@uhnix1.uh.edu>, atmaram@csun11.cs.uh.edu (S. Atmaram) writes:
> My program has the Window ID of a window on a remote display. I
> wish to check whether or not the ID is valid (that is, whether the
> window still exists), before doing an XSendEvent.

You should send the event without checking.  Install an error handler
to catch any BadWindow errors indicating that the window no longer
exists.  Since X is shared and asynchronous, there is no guarantee that
a window that existed when you did your check will still exist when you
send the event.

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

stroyan@hpfcso.HP.COM (Mike Stroyan) (03/17/90)

> > My program has the Window ID of a window on a remote display. I
> > wish to check whether or not the ID is valid (that is, whether the
> > window still exists), before doing an XSendEvent.
> 
> You should send the event without checking.  Install an error handler
> to catch any BadWindow errors indicating that the window no longer
> exists.  Since X is shared and asynchronous, there is no guarantee that
> a window that existed when you did your check will still exist when you
> send the event.
> 
> Ken Lee

Of course, there is also no guarantee that the window id won't be free'd
and reallocated to another client's new window.  Sometimes things like
this make me want to just XGrabServer and never let go.

Mike Stroyan, stroyan@hpfcla.hp.com