Add X11 implementation of SDL_GetDisplayDPI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index 8250a01..d4e3d90 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -533,6 +533,18 @@ X11_InitModes(_THIS)
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
+ // We use the displaydata screen index here so that this works
+ // for both the Xinerama case, where we get the overall DPI,
+ // and the regular X11 screen info case.
+ displaydata->hdpi = (float)DisplayWidth(data->display, displaydata->screen) * 25.4f /
+ DisplayWidthMM(data->display, displaydata->screen);
+ displaydata->vdpi = (float)DisplayHeight(data->display, displaydata->screen) * 25.4f /
+ DisplayHeightMM(data->display, displaydata->screen);
+ displaydata->ddpi = SDL_ComputeDiagonalDPI(DisplayWidth(data->display, displaydata->screen),
+ DisplayHeight(data->display, displaydata->screen),
+ (float)DisplayWidthMM(data->display, displaydata->screen) / 25.4f,
+ (float)DisplayHeightMM(data->display, displaydata->screen) / 25.4f);
+
displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
pixmapFormats = X11_XListPixmapFormats(data->display, &n);
if (pixmapFormats) {
@@ -923,6 +935,24 @@ X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
return 0;
}
+int
+X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi)
+{
+ SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
+
+ if (ddpi) {
+ *ddpi = data->ddpi;
+ }
+ if (hdpi) {
+ *hdpi = data->hdpi;
+ }
+ if (vdpi) {
+ *vpid = data->vdpi;
+ }
+
+ return data->ddpi != 0.0f ? 0 : -1;
+}
+
#endif /* SDL_VIDEO_DRIVER_X11 */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/x11/SDL_x11modes.h b/src/video/x11/SDL_x11modes.h
index f707f69..769da5a 100644
--- a/src/video/x11/SDL_x11modes.h
+++ b/src/video/x11/SDL_x11modes.h
@@ -31,6 +31,9 @@ typedef struct
int scanline_pad;
int x;
int y;
+ float ddpi;
+ float hdpi;
+ float vdpi;
int use_xinerama;
int use_xrandr;
@@ -74,6 +77,7 @@ extern int X11_GetVisualInfoFromVisual(Display * display, Visual * visual,
extern Uint32 X11_GetPixelFormatFromVisualInfo(Display * display,
XVisualInfo * vinfo);
extern int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect);
+extern int X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi);
#endif /* _SDL_x11modes_h */
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 69f7e2d..bc0eabd 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -216,6 +216,7 @@ X11_CreateDevice(int devindex)
device->VideoQuit = X11_VideoQuit;
device->GetDisplayModes = X11_GetDisplayModes;
device->GetDisplayBounds = X11_GetDisplayBounds;
+ device->GetDisplayDPI = X11_GetDisplayDPI;
device->SetDisplayMode = X11_SetDisplayMode;
device->SuspendScreenSaver = X11_SuspendScreenSaver;
device->PumpEvents = X11_PumpEvents;