Re: Clarification about gtk_main() and running simultaneous non-gtk functions

Michal Porzuczek wrote:
Correct me if I'm wrong but the gtk_main() acts like an infinite while
loop that waits for callbacks to the widgets that have been created
before gtk_main() was called.

gtk_main will run a GMainLoop:

The main loop will process "event sources" (IO events and timeout events).

X server events get interpreted by GDK and sent to the appropriate GTK+
objects for processing as "GSignals" (such as "button-press-event");
sometimes other signals are emitted as a result (such as "clicked"
on a button which recieved a "button-press-event" followed by a

Note that signals are emitted synchronously and are not deffered to the
main loop.

My question is, except for the g_timer function which seems to just be
for measuring proccesses inside actual callbacks, is it possible to
have timers running simultaneously with gtk_main() without calling a
separate program? That is, would it be possible to create a seperate
while(1) that say checks for the value of some variable while
gtk_main() is already running?

    You probably want to register a timeout GSource into your mainloop
using g_timeout_add (), so that gtk_main () (i.e. the GMainLoop)
will wakeup at the requested time and call your callback.

If you run a "while (1)" in your process; then you are hijacking
the main loop and your interface wont respond (not to mention that
all your event sources, such as IO watches and timeouts wont
be run either).

If you must see "while (1)" in your code; you'll have to do it in
another process or another thread.


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