Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!unido!uklirb!incas!sirius!tbecker From: tbecker@sirius.informatik.uni-kl.de (Thomas Becker) Newsgroups: comp.windows.x Subject: Re: Receiving XEvents asynchronously Message-ID: Date: 18 Jan 91 14:42:32 GMT References: <129@crystel.UUCP> Sender: news@incas.informatik.uni-kl.de (News System) Organization: FB Informatik - Uni Kaiserslautern Lines: 45 Nntp-Posting-Host: sirius.informatik.uni-kl.de In comp.windows.x you write: >I am trying to write a program, using Xlib right now, which receives >input from several sockets and displays them on the screen. I have had the same problem some time ago (using Xlib only). In fact X events are nothing else but messages coming in through a socket. By the macro socket = ConnectionNumber(display) you get the socket connection id to the X server, which you can use as any other socket for setting up masks required in select(). However, I had some slight trouble with this: calling select() for the FIRST time, select() told me that an X event is ready to be received, but XNextEvent() couldn't find any. I have solved the problem by looking for the first X event with XPpending() or some other non-blocking function, and then using select() only. So your program should roughly look like that: x_socket = (1 << ConnectionNumber(display)); sockwet_mask |= x_socket; if (XPending(display)) { /* handle event */ } do { i = select(..., &socket_mask, ...); if (socket_mask & x_socket) { XNextEvent(display, &event); /* handle event */ } else { /* ... */ } } Hope that helps. Thomas Becker -- Thomas Becker +---------+ acoustic: Computer Science Department | /"""\ | +49 631 205 3295 University of Kaiserslautern | { O~O } | electronic: P.O.Box 3049 | \ U / | tbecker@informatik.uni-kl.de