From 576271fb04e1c2f9ba1f95c0399fef2f73af3b06 Mon Sep 17 00:00:00 2001 From: Trent McPheron Date: Sun, 3 Apr 2022 20:04:00 -0400 Subject: 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. --- src/Fl_Native_File_Chooser_GTK.cxx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/Fl_Native_File_Chooser_GTK.cxx') 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 #include +#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"); -- cgit v1.2.3