Hello, my dear GTK fellows! :)
Now I am engaged in AI championship and want to display current situation on battlefield using Cairo on GTK window. My application have to use provided framework which works in its own main loop. So, I can not call gtk_main in main thread. So, I am launching GTK main runloop in separate thread:
Code:
...
g_thread_init(NULL);
g_thread_create(gui_main_loop, data, FALSE, NULL);
...
...
gpointer gui_main_loop(gpointer data)
{
...
gdk_threads_init();
gdk_threads_enter();
...
// Here I make my cute UI
...
gtk_main();
gdk_threads_leave();
...
}
...
I attached handler of "draw" event to my drawing area:
Code:
...
gboolean rendering(GtkWidget *widget, cairo_t *c, gpointer data)
{
// Here I render my UI using cairo.
// Just noticed I do not return anything from here.
}
...
// I call this function before gtk_main
g_signal_connect(G_OBJECT(drawing_area), "draw", G_CALLBACK(rendering), data);
...
So, my GTK window lives in another thread and redrawn each time I resize window. But I need to update it several times a second to monitor the current situation on battlefield. So, on every iteration several time a second I call invalidate function from my main thread:
Code:
...
gdk_window_invalidate_rect(gtk_widget_get_window(drawing_area), NULL, true);
...
But in several seconds the UI freezes. It reacts on window resizes but ignores gdk_window_invalidate_rect calls. What am I doing wrong?
Sincerely,
Kyrylo V. Polezhaiev.