diff --git a/src/screen_xywh.cxx b/src/screen_xywh.cxx index 270b6fce7..95c340683 100644 --- a/src/screen_xywh.cxx +++ b/src/screen_xywh.cxx @@ -156,9 +156,43 @@ typedef struct { static FLScreenInfo screens[MAX_SCREENS]; static float dpi[MAX_SCREENS][2]; +#define USE_XRANDR (HAVE_DLSYM && HAVE_DLFCN_H) // means attempt to dynamically load libXrandr.so +#if USE_XRANDR +#include +typedef struct { + int width, height; + int mwidth, mheight; +} XRRScreenSize; +typedef XRRScreenSize* (*XRRSizes_type)(Display *dpy, int screen, int *nsizes); +#endif // USE_XRANDR + static void screen_init() { if (!fl_display) fl_open_display(); - // FIXME: Rewrite using RandR instead + int dpi_by_randr = 0; + float dpih, dpiv; +#if USE_XRANDR + 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) XRRSizes_f = (XRRSizes_type)dlsym(libxrandr_addr, "XRRSizes"); + } + if (XRRSizes_f) { + int nscreens; + XRRScreenSize *ssize = XRRSizes_f(fl_display, fl_screen, &nscreens); +// for(int i=0;i