Xlib: unexpected async reply (sequence 0x7)

Glynn Clements glynn at gclements.plus.com
Wed Nov 14 08:44:10 PST 2007


Matthias Käppler wrote:

> I have the following situation:
> I need to call a Java function via JNI from a C++ program that talks to an X
> server. More precisely, whenever a FocusIn or FocusOut event occurs, I want
> a callback to be invoked on a Java object I supply. However, to process
> events I have to actively wait for any focus events that occur (very
> naughty) so in order to not block the whole system, this must happen in a
> separate thread. I start this thread from within my Java connector. In this
> thread I simply store a reference to that Java object and enter the X11
> event loop. Whenever I receive a focus event, I call back to some method of
> that object.
> 
> This works.... sometimes. Whenever it doesn't work however, X11 outputs the
> message "Xlib: unexpected async reply (sequence 0x7)" and from there on no
> events will be reported anymore whatsoever.
> 
> I have no idea what is going wrong here, being very new to X11 programming.

If you want to call Xlib from multiple threads, you need to call
XInitThreads() before any other Xlib function, and the call needs to
succeed (not all implementations support calling Xlib from multiple
threads).

Also, your event loop simply discards all events except FocusIn. You
should probably be using XCheckTypedWindowEvent() to avoid "stealing"
other events.

More generally, you would be much better off not using a separate
event loop. Why can't you have the main event loop notify your code of
FocusIn events?

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list