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




Aaron Digulla <digulla@wi-pc44.fh-konstanz.de> writes:

> Quoting Owen Taylor (otaylor@redhat.com):
> 
> > > 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
> 
> The problem is not XPending() itself. It's the way gtk works: If you
> do something, it's usually not done instantly (ie. when the function
> returns) but a signal is emitted. Signals are processed in an idle
> proc. Now what happens is this: When all events are processed, there
> are some idle procs but no events pending. So the loop above exits
> and the idle proc is not executed -> the GUI is dead. When you move
> the mouse, an event happens and this can *sometimes* wake the
> idle proc !

GTK's internal idle procedures are accounted for by gtk_events_pending().

If you have your _own_ idle procedures, they are not accounted for,
because the assumption is that if you are using the above loop,
you want to schedule things above.
 
> > > 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.
> 
> You must make sure that all events are processed - In this case, the idle
> proc won't be called (same for timeout functions) because that happens
> only in gtk_main_iteration() which isn't called because no events are
> pending...
> 
> I have the same problem here with my threads. Owen, can you *please* have a
> look at this ASAP. It *really* sux :-)

If somebody can provide an example of the problem I can
reproduce here...

                                        Owen



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