Check validity of window id

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

2 posts / 0 new
Last post
Check validity of window id

Submitted by Anonymous on Wed, 01/10/2001 - 19:53. Developers
This is probably a more of a general X question how can I check a window id before using it, to make sure the window exists, and hopefully not get a `bad window id` or `bad drawable` error.

ICS_support

It is a general X question, and the answer is in the comp.windows.x FAQ

Subject 184) How do I check whether a window ID is valid?
My program has the ID of a window on a remote display. I want to check whether
the window exists before doing anything with it.

Because X is asynchronous, there isn`t a guarantee that the window
would still exist between the time that you got the ID and the time you sent an
event to the window or otherwise manipulated it. What you should do is send the
event without checking, but install an error handler to catch any BadWindow
errors, which would indicate that the window no longer exists. This scheme
will work except on the [rare] occasion that the original window has been
destroyed and its ID reallocated to another window.
You can use this scheme to make a function which checks the validity
of a window; you can make this operation almost synchronous by calling
XSync() after the request, although there is still no guarantee that the
window will exist after the result (unless the sterver is grabbed). On the
whole, catching the error rather than pre-checking is preferable.