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
This commit is contained in:
parent
616bcb6357
commit
f07570e92f
@ -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<nscreens; i++)
|
||||
// printf("width=%d height=%d mwidth=%d mheight=%d\n",ssize[i].width,ssize[i].height,ssize[i].mwidth,ssize[i].mheight);
|
||||
// printf("width=%d height=%d mwidth=%d mheight=%d\n",
|
||||
// ssize[i].width,ssize[i].height,ssize[i].mwidth,ssize[i].mheight);
|
||||
|
||||
if (nscreens > 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,8 +335,10 @@ 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;
|
||||
|
||||
@ -336,9 +348,11 @@ void Fl_X11_Screen_Driver::init()
|
||||
screens[i].width = DisplayWidth(fl_display, i);
|
||||
screens[i].height = DisplayHeight(fl_display, i);
|
||||
|
||||
if (dpi_by_randr) { dpi[i][0] = dpih; dpi[i][1] = dpiv; }
|
||||
else {
|
||||
int mm = DisplayWidthMM(fl_display, fl_screen);
|
||||
if (dpi_by_randr) {
|
||||
dpi[i][0] = dpih;
|
||||
dpi[i][1] = dpiv;
|
||||
} else {
|
||||
int mm = DisplayWidthMM(fl_display, i);
|
||||
dpi[i][0] = mm ? screens[i].width*25.4f/mm : 0.0f;
|
||||
mm = DisplayHeightMM(fl_display, fl_screen);
|
||||
dpi[i][1] = mm ? screens[i].height*25.4f/mm : 0.0f;
|
||||
|
Loading…
Reference in New Issue
Block a user