Re: avoiding gtk_main() ?

Hi Peter,

this mailing list is intended for development of GNOME itself and its
apps - you probably should join a Gtk mailing list for questions like
this.  See `' where there is also a great tutorial on getting
started with Gtk which explains how the event loop works using `gtk_main'.

On Tue, 18 Jan 2000, Peter Falk wrote:

> I got a huge problem. I am building a graphicengine for a friend.
> The shared libary i am building includes following functions.
> "StartGraphicEngine" ... inits window,canvas,... and calls gtk_main()
> The functions are working but my problem is that when i call gtk_main() my
> program stops and only waits for signals. This is what i want to avoid. I

When you call gtk_main, it starts event loop processing so that gtk can
respond to X events.  Until you do this, your windows seem "dead".  The
main loop runs until something inside does gtk_main_quit, so when you call
StartGraphicEngine, you are asking for no more processing to be done after
that point in your program UNTIL gtk's main loop finishes.

I suggest reading and trying out the tutorial, then redesigning your
library to init the window and put the canvas in it as a separate call
from the main loop call (e.g. InitGraphicEngine and RunGraphicEngine).

> imagine the libary this way that when he calls "StartGraphicEngine()"
> then the window apears. Then he can call "puttext(..)", "putimage(..)", ..
> until he calls "StopGraphicEngine()" 

Quitting the main loop has to be done from *inside* the main loop.
Normally, you might connect a handler for the close button on the window
to run gtk_main_quit.  This will be run inside the main loop because this
is where gtk's signals are generated.

> I tried to call "gtk_main()" in a p_thread but this makes the program
> unstable and i am not able to quit my program.

Using threads with Gtk is not the solution for this - mixing threads and
event loops is tricky stuff.

Duncan Pierce <>

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