Modal Loop in a GTK+ application
-
03-06-2021 - |
Question
I am trying to write a function which will wait till the user clicks somewhere within a GTK+ widget (similar to a drawing area) and return mouse co-ordinates. This function should behave modally in that it waits till input is received. Those familiar with the Windows API may find some similarity to the TrackPopupMenu
function which also waits till a menu item is selected.
What I am trying to do here is similar to running a "secondary message loop" using the Windows API. How is it done in GTK+?
Solution
You can call gtk_main_iteration_do(FALSE);
to "pump" the GTK+ event system, without (the FALSE
) blocking the application.
OTHER TIPS
Being modal is possible for a GtkWindow, using gtk_window_set_modal, not for a GtkWidget. That makes sense, otherwise the user wouldn't know what to interact with if there wasn't a window poping up.