[Xcb] questions about proper event loop and timers

Ian Osgood iano at quirkster.com
Sat Aug 12 09:56:19 PDT 2006


Jim,

I don't think XCBWaitForEvent is deprecated (although XCBWaitEvent  
is; just for consistent naming).  XCBWaitForEvent is just fine for  
standard event-driven X programs.

XCB is much more thread-friendly than Xlib. One way to do timed  
events is to put that processing in a thread. You should look at xcb- 
demo/hypnomoire.c for an example of how to do this.

Another possibility is to use select() upon XCBGetFileDescriptor(),  
where the timeout parameter provides the interval. If select()  
returns zero, then you perform your periodic actions, otherwise you  
do your XCBPollForEvent() loop.  This is trickier to get right, but  
you stay single-threaded.

I'm not familiar with the Linux timer API, myself.

Ian

On Aug 12, 2006, at 9:28 AM, Vincent Torri wrote:

>
> Hey,
>
> Don't use XCBWaitForEvent. It's deprecated, iirc. Use  
> XCBPollForEvent, which is, btw, non-blocking.
>
> look at the tutorial (in xcb/doc/tutorial) or in xcb-demo to see  
> example of event loops.
>
> (something like:
>
> while (1) {
>   e = XCBPollForEvent(c, NULL);
>   if (e) {
>     ***
>     ***
>   }
> }
>
> )
>
> otherwise, i've not advice to give you about your timer stuff.
>
> regards
>
> Vincent
>
> On Sat, 12 Aug 2006, Jim Crafton wrote:
>
>> Hi,
>> I'm new to xcb usage and running into a bit of problem.
>>
>> I'm trying to figure out the best way to put together an event loop
>> that uses both timers and x events in a single thread.
>>
>> If I was just catching/dispatching x events I'd do something like
>>
>> XCBGenericEvent* xcbEvent = XCBWaitForEvent( connection );
>> while ( NULL != xcbEvent ) {
>>   //process the event..
>>   xcbEvent = XCBWaitForEvent( connection );
>> }
>>
>> This works fine, no busy waiting, no CPU spiking
>>
>>
>> However if I want to add support for timers, i.e. registering some
>> callback function that gets invoked every x milliseconds, then I'm a
>> bit stuck.
>>
>> As I understand it, on linux, timers are handled with timer_create 
>> () and
>> timer_settime(). If I use these API's then how do I set up the XCB
>> event loop such that I don't have to poll all the time? Won't
>> XCBWaitForEvent() block, and then the callback for the timer not get
>> triggered (because the thread is blocked in the XCBWaitForEvent()
>> code)?
>>
>> Is there a standard way to handle timers with XCB? Alternately, would
>> anyone consider adding some extra functions that allow for add timer
>> support into the XCB API's?
>>
>>
>> Thanks
>>
>> Jim Crafton
>> _______________________________________________
>> Xcb mailing list
>> Xcb at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/xcb
>>
>> -- 
>> Ce message a été vérifié par MailScanner
>> pour des virus ou des polluriels et rien de
>> suspect n'a été trouvé.
>> Message délivré par le serveur de messagerie de l'Université d'Evry.
>>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb



More information about the Xcb mailing list