From c79ec99d0571bc44989153fdfbf4ffa720972e70 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 23 Aug 2016 16:38:10 +0000 Subject: [PATCH] Fix compiler warnings and simplify X11 screen_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 back small improvements of branch-1.3-porting. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11889 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/screen_xywh.cxx | 64 +++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/src/screen_xywh.cxx b/src/screen_xywh.cxx index 6306ee185..a63012c44 100644 --- a/src/screen_xywh.cxx +++ b/src/screen_xywh.cxx @@ -3,7 +3,7 @@ // // Screen/monitor bounding box API for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2010 by Bill Spitzak and others. +// Copyright 1998-2016 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -142,7 +142,7 @@ static void screen_init() { num_screens = count; } -#else +#else // X11 #if HAVE_XINERAMA # include @@ -168,9 +168,12 @@ typedef XRRScreenSize* (*XRRSizes_type)(Display *dpy, int screen, int *nsizes); static void screen_init() { if (!fl_display) fl_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); @@ -183,17 +186,24 @@ static void screen_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; @@ -204,8 +214,11 @@ static void screen_init() { screens[i].y_org = xsi[i].y_org; 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); @@ -213,27 +226,34 @@ static void screen_init() { } } if (xsi) XFree(xsi); - } else -#endif - { // ! XineramaIsActive() + } else + +#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