diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-09-15 15:57:29 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-09-15 15:57:29 +0200 |
| commit | c549b7acbd65674019b731c6648a9e8eb22f70dd (patch) | |
| tree | 7e6b8745573d2b8c1f9a61a7393b1e7c2b0d8f69 /src/drivers/X11 | |
| parent | 000807cc1d1a1c2f00274763f3e8e24145f1af00 (diff) | |
X11 platform: use Gnome printer dialog when the GTK library is available at run-time
The code to determine whether the GTK library is available is now in Fl_X11_System_Driver::probe_for_GTK()
called both by Fl_Printer::begin_job() and Fl_Native_File_Chooser.
New Fl::option OPTION_PRINTER_USES_GTK allows to deactivate use of
the Gnome print dialog.
Minor change in Fl_Native_File_Chooser: GTK version 3 is searched before version 2,
whereas the search order was the opposite before.
Diffstat (limited to 'src/drivers/X11')
| -rw-r--r-- | src/drivers/X11/Fl_X11_System_Driver.H | 4 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_System_Driver.cxx | 57 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/drivers/X11/Fl_X11_System_Driver.H b/src/drivers/X11/Fl_X11_System_Driver.H index b7d6e9ff7..138959d75 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.H +++ b/src/drivers/X11/Fl_X11_System_Driver.H @@ -20,6 +20,7 @@ #ifndef FL_X11_SYSTEM_DRIVER_H #define FL_X11_SYSTEM_DRIVER_H +#include "../../config_lib.h" #include "../Posix/Fl_Posix_System_Driver.H" class Fl_X11_System_Driver : public Fl_Posix_System_Driver { @@ -63,6 +64,9 @@ public: virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0); virtual void remove_fd(int, int when); virtual void remove_fd(int); +#if HAVE_DLSYM && HAVE_DLFCN_H + static bool probe_for_GTK(int major, int minor, void **ptr_gtk); +#endif }; #endif /* FL_X11_SYSTEM_DRIVER_H */ diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 42d403299..f406dce02 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -517,6 +517,63 @@ int Fl_X11_System_Driver::utf8locale() { return ret; } +#if HAVE_DLSYM && HAVE_DLFCN_H +#include <dlfcn.h> // for dlopen et al + +static void* fl_dlopen(const char *filename1, const char *filename2) +{ + void *ptr = dlopen(filename1, RTLD_LAZY | RTLD_GLOBAL); + if (!ptr) ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); + return ptr; +} + +bool Fl_X11_System_Driver::probe_for_GTK(int major, int minor, void **ptr_gtk) { + typedef void (*init_t)(int*, void*); + *ptr_gtk = NULL; + // was GTK previously loaded? + init_t init_f = (init_t)dlsym(RTLD_DEFAULT, "gtk_init_check"); + if (init_f) { // yes it was. + *ptr_gtk = RTLD_DEFAULT; // Caution: NULL under linux, not-NULL under Darwin + } else { + // Try first with GTK3 + *ptr_gtk = fl_dlopen("libgtk-3.so", "libgtk-3.so.0"); + if (*ptr_gtk) { +#ifdef DEBUG + puts("selected GTK-3\n"); +#endif + } else { + // Try then with GTK2 +# ifdef __APPLE_CC__ // allows testing on Darwin + X11 + *ptr_gtk = ::dlopen("/sw/lib/libgtk-x11-2.0.dylib", RTLD_LAZY | RTLD_GLOBAL); +#else + *ptr_gtk = fl_dlopen("libgtk-x11-2.0.so", "libgtk-x11-2.0.so.0"); +#endif + } + if (*ptr_gtk) { +#ifdef DEBUG + puts("selected GTK-2\n"); +#endif + } else { +#ifdef DEBUG + puts("Failure to load libgtk"); +#endif + return false; + } + init_f = (init_t)dlsym(*ptr_gtk, "gtk_init_check"); + if (!init_f) return false; + } + int ac = 0; + init_f(&ac, NULL); + // now check if running version is high enough + if (dlsym(*ptr_gtk, "gtk_get_major_version") == NULL) { // YES indicates V 3 + typedef const char* (*check_t)(int, int, int); + check_t check_f = (check_t)dlsym(*ptr_gtk, "gtk_check_version"); + if (!check_f || check_f(major, minor, 0) ) return false; + } + return true; +} +#endif // HAVE_DLSYM && HAVE_DLFCN_H + #if !defined(FL_DOXYGEN) const char *Fl_X11_System_Driver::shortcut_add_key_name(unsigned key, char *p, char *buf, const char **eom) |
