diff options
| author | Trent McPheron <twilightinzero@gmail.com> | 2022-04-03 20:04:00 -0400 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-12-16 16:21:23 +0100 |
| commit | 576271fb04e1c2f9ba1f95c0399fef2f73af3b06 (patch) | |
| tree | 3740f4878b837a1254cd3f7becc97321c1d0f31c /src/Fl_Native_File_Chooser_GTK.cxx | |
| parent | 2ddb27f0f293eb0e57e32194e4f48c72614500ab (diff) | |
Add Zenity-based file chooser based on the KDialog one (HugLifeTiZ)
If available, it is used on Linux regardless of the current desktop because
it offers free XDG portal integration, which means it picks the correct file
chooser on all desktops, and allows for meaningful file selection in sandbox
environments like Flatpak.
Diffstat (limited to 'src/Fl_Native_File_Chooser_GTK.cxx')
| -rw-r--r-- | src/Fl_Native_File_Chooser_GTK.cxx | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Fl_Native_File_Chooser_GTK.cxx b/src/Fl_Native_File_Chooser_GTK.cxx index ff5df7293..e41c4230f 100644 --- a/src/Fl_Native_File_Chooser_GTK.cxx +++ b/src/Fl_Native_File_Chooser_GTK.cxx @@ -17,6 +17,9 @@ #include <config.h> #include <FL/Fl_Native_File_Chooser.H> +#if USE_ZENITY +# include "Fl_Native_File_Chooser_Zenity.H" +#endif #if USE_KDIALOG # include "Fl_Native_File_Chooser_Kdialog.H" #endif @@ -923,15 +926,34 @@ void Fl_GTK_Native_File_Chooser_Driver::probe_for_GTK_libs(void) { #endif // HAVE_DLSYM && HAVE_DLFCN_H Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) { - // Use kdialog if available at run-time and if using the KDE desktop, - // else, use GTK dialog if available at run-time + // Use zenity if available at run-time even if using the KDE desktop, + // because its portal integration means the KDE chooser will be used. + // Else use kdialog if available at run-time and if using the KDE + // desktop, else, use GTK dialog if available at run-time // otherwise, use FLTK file chooser. platform_fnfc = NULL; fl_open_display(); if (Fl::option(Fl::OPTION_FNFC_USES_GTK)) { +#if USE_ZENITY + if (val != BROWSE_MULTI_DIRECTORY) { + if (!Fl_Zenity_Native_File_Chooser_Driver::have_looked_for_zenity) { + // First Time here, try to find zenity + FILE *pipe = popen("zenity --version 2> /dev/null", "r"); + if (pipe) { + char *p, line[100] = ""; + p = fgets(line, sizeof(line), pipe); + if (p && strlen(line) > 0) Fl_Zenity_Native_File_Chooser_Driver::did_find_zenity = true; + pclose(pipe); + } + Fl_Zenity_Native_File_Chooser_Driver::have_looked_for_zenity = true; + } + // if we found zenity, we will use the Fl_Zenity_Native_File_Chooser_Driver + if (Fl_Zenity_Native_File_Chooser_Driver::did_find_zenity) platform_fnfc = new Fl_Zenity_Native_File_Chooser_Driver(val); + } +#endif // USE_ZENITY #if USE_KDIALOG const char *desktop = getenv("XDG_CURRENT_DESKTOP"); - if (desktop && strcmp(desktop, "KDE") == 0 && val != BROWSE_MULTI_DIRECTORY) { + if (!platform_fnfc && desktop && strcmp(desktop, "KDE") == 0 && val != BROWSE_MULTI_DIRECTORY) { if (!Fl_Kdialog_Native_File_Chooser_Driver::have_looked_for_kdialog) { // First Time here, try to find kdialog FILE *pipe = popen("kdialog -v 2> /dev/null", "r"); |
