Add X11 implementation of SDL_GetDisplayDPI.
authorAlfred Reynolds <alfred@valvesoftware.com>
Wed, 29 Jul 2015 17:19:02 -0700
changeset 98144df28b087060
parent 9813 0652406e46c6
child 9815 1db11af8159e
Add X11 implementation of SDL_GetDisplayDPI.
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11modes.h
src/video/x11/SDL_x11video.c
     1.1 --- a/src/video/x11/SDL_x11modes.c	Wed Jul 29 17:18:56 2015 -0700
     1.2 +++ b/src/video/x11/SDL_x11modes.c	Wed Jul 29 17:19:02 2015 -0700
     1.3 @@ -533,6 +533,18 @@
     1.4          displaydata->visual = vinfo.visual;
     1.5          displaydata->depth = vinfo.depth;
     1.6  
     1.7 +        // We use the displaydata screen index here so that this works
     1.8 +        // for both the Xinerama case, where we get the overall DPI,
     1.9 +        // and the regular X11 screen info case.
    1.10 +        displaydata->hdpi = (float)DisplayWidth(data->display, displaydata->screen) * 25.4f /
    1.11 +            DisplayWidthMM(data->display, displaydata->screen);
    1.12 +        displaydata->vdpi = (float)DisplayHeight(data->display, displaydata->screen) * 25.4f /
    1.13 +            DisplayHeightMM(data->display, displaydata->screen);
    1.14 +        displaydata->ddpi = SDL_ComputeDiagonalDPI(DisplayWidth(data->display, displaydata->screen),
    1.15 +                                                   DisplayHeight(data->display, displaydata->screen),
    1.16 +                                                   (float)DisplayWidthMM(data->display, displaydata->screen) / 25.4f,
    1.17 +                                                   (float)DisplayHeightMM(data->display, displaydata->screen) / 25.4f);
    1.18 +
    1.19          displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
    1.20          pixmapFormats = X11_XListPixmapFormats(data->display, &n);
    1.21          if (pixmapFormats) {
    1.22 @@ -923,6 +935,24 @@
    1.23      return 0;
    1.24  }
    1.25  
    1.26 +int
    1.27 +X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi)
    1.28 +{
    1.29 +    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
    1.30 +
    1.31 +    if (ddpi) {
    1.32 +        *ddpi = data->ddpi;
    1.33 +    }
    1.34 +    if (hdpi) {
    1.35 +        *hdpi = data->hdpi;
    1.36 +    }
    1.37 +    if (vdpi) {
    1.38 +        *vpid = data->vdpi;
    1.39 +    }
    1.40 +
    1.41 +    return data->ddpi != 0.0f ? 0 : -1;
    1.42 +}
    1.43 +
    1.44  #endif /* SDL_VIDEO_DRIVER_X11 */
    1.45  
    1.46  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/video/x11/SDL_x11modes.h	Wed Jul 29 17:18:56 2015 -0700
     2.2 +++ b/src/video/x11/SDL_x11modes.h	Wed Jul 29 17:19:02 2015 -0700
     2.3 @@ -31,6 +31,9 @@
     2.4      int scanline_pad;
     2.5      int x;
     2.6      int y;
     2.7 +    float ddpi;
     2.8 +    float hdpi;
     2.9 +    float vdpi;
    2.10  
    2.11      int use_xinerama;
    2.12      int use_xrandr;
    2.13 @@ -74,6 +77,7 @@
    2.14  extern Uint32 X11_GetPixelFormatFromVisualInfo(Display * display,
    2.15                                                 XVisualInfo * vinfo);
    2.16  extern int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect);
    2.17 +extern int X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi);
    2.18  
    2.19  #endif /* _SDL_x11modes_h */
    2.20  
     3.1 --- a/src/video/x11/SDL_x11video.c	Wed Jul 29 17:18:56 2015 -0700
     3.2 +++ b/src/video/x11/SDL_x11video.c	Wed Jul 29 17:19:02 2015 -0700
     3.3 @@ -216,6 +216,7 @@
     3.4      device->VideoQuit = X11_VideoQuit;
     3.5      device->GetDisplayModes = X11_GetDisplayModes;
     3.6      device->GetDisplayBounds = X11_GetDisplayBounds;
     3.7 +    device->GetDisplayDPI = X11_GetDisplayDPI;
     3.8      device->SetDisplayMode = X11_SetDisplayMode;
     3.9      device->SuspendScreenSaver = X11_SuspendScreenSaver;
    3.10      device->PumpEvents = X11_PumpEvents;