Dear GTK developers,
I am one of the gtk-fortran developer (https://github.com/vmagnin/gtk-fortran/wiki), which is a GTK / Fortran binding. We are now porting gtk-fortran to GTK 4. More than 50% of the examples are now running with GTK 3.98.4 on Fedora 32. But we may need some help to port some of the remaining ones.
But in GTK 4, gtk_dialog_run() was removed. In GTK 4, what is the recommended way to run a GtkDialog and get its response ? Should I write a callback function for the “response” event ?
because in my library the dialog window is managed by a function hl_gtk_message_dialog_show() which must show the dialog window then return its response. Therefore I need that blocking behavior.
There is of course a call g_main_loop_quit(dialog_gmainloop) in the callback function.
Blocking functions contradict the nature of event driven programming that has been the model of GTK since its inception; the introduction of gtk_dialog_run() was, in retrospect, a mistake in and of itself, as it used a model more in line with terminal user interfaces/console scripting than GUIs. The main reason for blocking is to prevent interacting with the rest of the application while the dialog is in effect; that is perfectly achievable with modality—that’s what modality is for, after all. If you’re blocking in the middle of a synchronous signal emission, you should strongly reconsider the approach you are using, and avoid the message dialog altogether.
You are, of course, free to create a nested main loop in your own library/code, but you also must be aware of the potential issues that nested loops bring—especially when paired with threaded code that neither you or the toolkit have no control over.
Thank you @ebassi for your clear answer.
I will think about it. In our high level library, our goal was to allow the user to open easily a dialog box and obtain a response by typing just one line of code, without having to care about writing callback functions… I have not yet figured out how I could do without adding a nested loop.