Re: Question: non-blocking check for pending events...




Matt Grossman <mattg@oz.net> writes:

> Is it possible to do something like what I gather this is supposed to
> do?  That is, make a _non-blocking_ check to see if there are any
> events that need to be processed.  If there are no events to be
> processed return 0 immediately, and if there are call
> gtk_main_iteration to process them.
> 
> while(gtk_events_pending())
> 	gtk_main_iteration();
> 
> This will wait in XPending (called by gdk_events_pending(), called by
> gtk_events_pending) if there are no incoming events.  So if the user
> gets bored and starts waggling the mouse at the program, it will work,
> but otherwise it just sits there.

XPending does not block ... I'm confused
 
> Multithreading is obviously one answer, and I guess rewriting the
> program to use timeouts or idle functions is another.  I've tried
> various permutations of gtk_main_iteration do(FALSE), but that just
> doesn't seem to ever do anything, although it doesn't block.
> XEventsQueued(...) either blocks or never returns positive, even when
> there should be events in the queue.

the 'block' parameter to gtk_main_iteration_do () doesn't work as
advertised, but gtk_events_pending() does...

You could also write the program to fork() off a separate
process to do the find, communicate back via a pipe, and
use gdk_input_add().
 
> I've seen the above code fragment in the FAQ and other postings, and I
> guess I just didn't understand exactly what it did.  So I am looking
> to see if there is a way to do what I thought it did. *:-} (dazed
> smiley struck by rock)
> 
> If you want to see an example of this, download gtkfind from
> http://www.oz.net/~mattg/download.html, and look in gtkfind.c, line
> 197.  Just start up a find in a large directory and don't touch the
> mouse.  This is with Gtk+ 1.0.6 (and all other versions).

Works fine for me (1.1.3, but that part hasn't changed IIRC)... I'm
still confused.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]