diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 6c1da73a4..59c442ed5 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -697,7 +697,7 @@ void fl_open_display(Display* d) { #if USE_XRANDR void *libxrandr_addr = dlopen("libXrandr.so.2", RTLD_LAZY); - if (!libxrandr_addr) libxrandr_addr = dlopen("libXrandr.so", RTLD_LAZY); + if (!libxrandr_addr) libxrandr_addr = Fl::system_driver()->dlopen("libXrandr.so"); if (libxrandr_addr) { int error_base; typedef Bool (*XRRQueryExtension_type)(Display*, int*, int*); diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx index c2576b268..6cf7bef55 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx @@ -47,14 +47,43 @@ #endif /* !S_ISDIR */ +static void* double_dlopen(const char *filename1) +{ + void *ptr = ::dlopen(filename1, RTLD_LAZY | RTLD_GLOBAL); + if (!ptr) { + char filename2[FL_PATH_MAX]; + sprintf(filename2, "%s.0", filename1); + ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); + } + return ptr; +} void *Fl_Posix_System_Driver::dlopen(const char *filename) { + void *ptr = NULL; #if HAVE_DLSYM - return ::dlopen(filename, RTLD_LAZY); -#endif - return NULL; + ptr = double_dlopen(filename); +# ifdef __APPLE_CC__ // allows testing on Darwin + XQuartz + fink + if (!ptr) { + char *f_dylib = strdup(filename); + strcpy(strrchr(f_dylib, '.'), ".dylib"); + char path[FL_PATH_MAX]; + sprintf(path, "/sw/lib/%s", f_dylib); + ptr = ::dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + if (!ptr) { + sprintf(path, "/opt/sw/lib/%s", f_dylib); + ptr = ::dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + } + if (!ptr) { + sprintf(path, "/opt/X11/lib/%s", f_dylib); + ptr = ::dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + } + free(f_dylib); + } +# endif // __APPLE_CC__ +#endif // HAVE_DLSYM + return ptr; } int Fl_Posix_System_Driver::file_type(const char *filename) diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index d13562ea9..ff095f2c4 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -21,6 +21,7 @@ #include "Fl_X11_Screen_Driver.H" #include "../Xlib/Fl_Font.H" #include "Fl_X11_Window_Driver.H" +#include "../../src/Fl_System_Driver.H" #include "../Xlib/Fl_Xlib_Graphics_Driver.H" #include #include @@ -287,10 +288,7 @@ void Fl_X11_Screen_Driver::init() { static XRRSizes_type XRRSizes_f = NULL; if (!XRRSizes_f) { void *libxrandr_addr = dlopen("libXrandr.so.2", RTLD_LAZY); - if (!libxrandr_addr) libxrandr_addr = dlopen("libXrandr.so", RTLD_LAZY); -# ifdef __APPLE_CC__ // allows testing on Darwin + X11 - if (!libxrandr_addr) libxrandr_addr = dlopen("/opt/X11/lib/libXrandr.dylib", RTLD_LAZY); -# endif + if (!libxrandr_addr) libxrandr_addr = Fl::system_driver()->dlopen("libXrandr.so"); if (libxrandr_addr) XRRSizes_f = (XRRSizes_type)dlsym(libxrandr_addr, "XRRSizes"); } if (XRRSizes_f) { diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index f406dce02..412d64667 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -520,13 +520,6 @@ int Fl_X11_System_Driver::utf8locale() { #if HAVE_DLSYM && HAVE_DLFCN_H #include // 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; @@ -536,18 +529,14 @@ bool Fl_X11_System_Driver::probe_for_GTK(int major, int minor, void **ptr_gtk) { *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"); + *ptr_gtk = Fl::system_driver()->dlopen("libgtk3.0.so"); 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 + *ptr_gtk = Fl::system_driver()->dlopen("libgtk-x11-2.0.so"); } if (*ptr_gtk) { #ifdef DEBUG