x11: Don't use GetXftDPI() when XRandR can tell us the DPI per-output.

Fixes #5764.
This commit is contained in:
Ryan C. Gordon 2022-06-06 14:38:26 -04:00
parent 61115aebd3
commit ec0204d243
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 24 additions and 33 deletions

View File

@ -148,30 +148,6 @@ X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
return SDL_PIXELFORMAT_UNKNOWN;
}
static int
GetXftDPI(Display* dpy)
{
char* xdefault_resource;
int xft_dpi, err;
xdefault_resource = X11_XGetDefault(dpy, "Xft", "dpi");
if(!xdefault_resource) {
return 0;
}
/*
* It's possible for SDL_atoi to call SDL_strtol, if it fails due to a
* overflow or an underflow, it will return LONG_MAX or LONG_MIN and set
* errno to ERANGE. So we need to check for this so we dont get crazy dpi
* values
*/
xft_dpi = SDL_atoi(xdefault_resource);
err = errno;
return err == ERANGE ? 0 : xft_dpi;
}
#if SDL_VIDEO_DRIVER_X11_XRANDR
static SDL_bool
CheckXRandR(Display * display, int *major, int *minor)
@ -333,7 +309,6 @@ X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput outputid, XRRScre
Uint32 pixelformat;
XPixmapFormatValues *pixmapformats;
int scanline_pad;
int xft_dpi = 0;
int i, n;
if (get_visualinfo(dpy, screen, &vinfo) < 0) {
@ -405,14 +380,6 @@ X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput outputid, XRRScre
displaydata->hdpi = display_mm_width ? (((float) mode.w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float) mode.h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float) display_mm_width) / 25.4f,((float) display_mm_height) / 25.4f);
/* if xft dpi is available we will use this over xrandr (!!! FIXME: ...yeah?) */
xft_dpi = GetXftDPI(dpy);
if (xft_dpi > 0) {
displaydata->hdpi = (float) xft_dpi;
displaydata->vdpi = (float) xft_dpi;
}
displaydata->scanline_pad = scanline_pad;
displaydata->x = display_x;
displaydata->y = display_y;
@ -565,6 +532,30 @@ X11_InitModes_XRandR(_THIS)
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
static int
GetXftDPI(Display* dpy)
{
char* xdefault_resource;
int xft_dpi, err;
xdefault_resource = X11_XGetDefault(dpy, "Xft", "dpi");
if(!xdefault_resource) {
return 0;
}
/*
* It's possible for SDL_atoi to call SDL_strtol, if it fails due to a
* overflow or an underflow, it will return LONG_MAX or LONG_MIN and set
* errno to ERANGE. So we need to check for this so we dont get crazy dpi
* values
*/
xft_dpi = SDL_atoi(xdefault_resource);
err = errno;
return err == ERANGE ? 0 : xft_dpi;
}
/* This is used if there's no better functionality--like XRandR--to use.
It won't attempt to supply different display modes at all, but it can
enumerate the current displays and their current sizes. */