From 943d1cf9870a08cbe65ad9235b1ca4347ec9c7dc Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 22 Jun 2016 07:04:00 +0000 Subject: Use Xrandr to get the true DPI of the display under the X11 platform. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11790 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/X11/Fl_X11_Screen_Driver.cxx | 58 +++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index be26205e7..34a932764 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -264,11 +264,45 @@ int Fl_X11_Screen_Driver::h() { return fl_workarea_xywh[3]; } +#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 void Fl_X11_Screen_Driver::init() { if (!fl_display) 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