Something weird seems to be going on here. I compile gtk-4.16.7 from source, and run the gtk4-demo executable.
When I press on the file dialog button in the “pickers and launchers” section, no file dialog is opened but instead the async callback (file_opened) is executed and the gtk_file_dialog_open_finish() function returns NULL with a g_error set with message “Dismissed by user”. The color selector and font selector dialogs work fine.
The same thing happens when I use gtk_file_dialog from my application using the system installed gtk4 (gtk-4.16.7 ArchLinux).
Would this be that gtk_file_dialog works in Wayland but not in X11? Or what could possibly be missing in the ArchLinux gtk4?
Did you check if the logs display any error messages?
But if I were to guess, the issue is likely that your system can’t find a implementation for the file chooser portal. When calling Gtk.FileDialog, Gtk asks the system for a file chooser instead of using its own when possible.
If you use Gnome and its portal, the issue might be this: Gnome recently removed the file chooser portal from xdg-desktop-portal-gnome, as now Nautilus provides the file chooser. But if your config is still set to use xdg-desktop-portal-gnome for it, it could result in this error?
Check if you have a portals.conf in your configuration folder and see what it tries to call for the file chooser.
Since you are not using a desktop environment, you are effectively working as an integrator yourself, which means you get to install additional dependencies, and make sure they are working in your environment.
In all seriousness, just install xdg-desktop-portal-gtk…
The XDG Desktop Portals are only a new standard on how applications can request resources from the system. Things like the file chooser are no longer part of the application or the library, but of the system.
xdg-desktop-portal-gtk is an basic, desktop independent implementation which provides a file chooser. So, installing it and making it the portal to use will give you the file chooser.
Of course, you can also write your own file chooser. You could even develop your own custom file chooser portal, which is then used by other apps as well.
It’s just a few steps more than necessary to solve this.
Actually there not so many steps involved, since I already have a threaded C++ class template to handle dialogs (non-threaded GtkDialog is no longer an option for me).
Your suggestion about including it into a separate custom file chooser portal is very good. As soon as I complete the xffm+ port to GTK4, I will do so (unless a truckload of work lands on my desk).