From f07570e92fcea5aed0960d284af19e97e4f5eff3 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 23 Aug 2016 16:57:39 +0000 Subject: Fix compiler warnings and simplify Fl_X11_Screen_Driver::init(). This function sets the screen dimensions and tries to use Xrandr, Xinerama, and basic X11 functions (in this order) to get the screen sizes and resolutions (dpi). This commit simplifies conditional compilation and fixes "unused variable" compiler warnings under certain conditions as mentioned by Greg in fltk.general, thread "Can not change font size in Kubuntu 16.04" on Mon, 15 Aug 2016 00:25:32 -0700. Also merged in small improvements of branch-1.3-porting, basically "the same commit" as svn r11889 in branch-1.3. Todo: dpi resolutions acquired by using Xrandr are not per screen but use dpi value of screen 0 for all screens. Check if this can be improved. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11890 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/X11/Fl_X11_Screen_Driver.cxx | 58 ++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index f8bf520b1..f9bae70f2 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -274,13 +274,14 @@ typedef struct { typedef XRRScreenSize* (*XRRSizes_type)(Display *dpy, int screen, int *nsizes); #endif // USE_XRANDR -void Fl_X11_Screen_Driver::init() -{ +void Fl_X11_Screen_Driver::init() { if (!fl_display) open_display(); - + int dpi_by_randr = 0; float dpih = 0.0f, dpiv = 0.0f; + #if USE_XRANDR + static XRRSizes_type XRRSizes_f = NULL; if (!XRRSizes_f) { void *libxrandr_addr = dlopen("libXrandr.so.2", RTLD_LAZY); @@ -293,17 +294,24 @@ void Fl_X11_Screen_Driver::init() if (XRRSizes_f) { int nscreens; XRRScreenSize *ssize = XRRSizes_f(fl_display, fl_screen, &nscreens); - // for(int i=0;i 0) { // Note: XRRSizes() *may* return nscreens == 0, see docs + int mm = ssize[0].mwidth; + dpih = mm ? ssize[0].width*25.4f/mm : 0.0f; + mm = ssize[0].mheight; + dpiv = mm ? ssize[0].height*25.4f/mm : 0.0f; + dpi_by_randr = 1; + } } + #endif // USE_XRANDR #if HAVE_XINERAMA + if (XineramaIsActive(fl_display)) { XineramaScreenInfo *xsi = XineramaQueryScreens(fl_display, &num_screens); if (num_screens > MAX_SCREENS) num_screens = MAX_SCREENS; @@ -315,8 +323,10 @@ void Fl_X11_Screen_Driver::init() screens[i].width = xsi[i].width; screens[i].height = xsi[i].height; - if (dpi_by_randr) { dpi[i][0] = dpih; dpi[i][1] = dpiv; } - else { + if (dpi_by_randr) { + dpi[i][0] = dpih; + dpi[i][1] = dpiv; + } else { int mm = DisplayWidthMM(fl_display, fl_screen); dpi[i][0] = mm ? screens[i].width*25.4f/mm : 0.0f; mm = DisplayHeightMM(fl_display, fl_screen); @@ -325,23 +335,27 @@ void Fl_X11_Screen_Driver::init() } if (xsi) XFree(xsi); } else -#endif - { // ! XineramaIsActive() + +#endif // HAVE_XINERAMA + + { // ! HAVE_XINERAMA || ! XineramaIsActive() num_screens = ScreenCount(fl_display); if (num_screens > MAX_SCREENS) num_screens = MAX_SCREENS; - + for (int i=0; i