We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2473

Summary: API to get physical display size.
Product: SDL Reporter: Daniel Bünzli <daniel.buenzli>
Component: videoAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 CC: alfred, amaranth72, philipp.wiesemann, sylvain.becker
Version: 2.0.3   
Hardware: All   
OS: All   
Attachments: beginning of patch to add SDL_GetDisplayPhysicalSize
beginning of patch to add SDL_GetDisplayPhysicalSize

Description Daniel Bünzli 2014-03-31 23:40:24 UTC
With all the different display resolutions one gets nowadays, it would be nice to have an API to get the physical display size in millimeters so that one can work with physical units (which is also useful for human factors like touch target sizes, etc.). 

Something like:

int SDL_GetDisplayPhysicalSize(int displayIndex, int* w, int* h)
 
The cocoa implementation would look like 

int
Cocoa_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * display, int * w, int * h)
{
    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    CGSize cgsize;

    cgsize = CGDisplayScreenSize(displaydata->display);
    *w = (int)cgsize.width;
    *h = (int)cgsize.height;
    return 0;
}

And this answer has a few hints for linux:

http://stackoverflow.com/questions/2621439/how-to-get-screen-dpi-linux-mac-programatically
Comment 1 Sylvain 2014-08-01 18:13:25 UTC
Created attachment 1801 [details]
beginning of patch to add SDL_GetDisplayPhysicalSize

Here's the beginning of a patch to add this function.

I have tested it only on linux and android.
Not sure that the display_index really matches the physical screen.

There is also the Cocoa and WinRt functions but not tested, and IOS (empty).
Comment 2 Philipp Wiesemann 2014-12-09 22:55:51 UTC
(In reply to Sylvain from comment #1)
> Here's the beginning of a patch to add this function.

Thank you for working on a patch. Here are some maybe possible improvements.

The new function SDL_GetDisplayPhysicalSize() requires both width and height to be no NULL pointer. This is not consistent with other functions like SDL_GetWindowSize(). These functions only require one pointer to be no NULL pointer which allows querying only one size.

SDL_GetDisplayPhysicalSize() still returns 0 if the platform-specific implementation failed (or is #ifed like in the patch) which could mean that the returned sizes are not valid. There are return values are documented for "out of range" and "no implemented" but there for this case.

The patch removes a #define in SDL_gesture.c which is unrelated.

There is a typo in every "millimeters".
Comment 3 Sylvain 2014-12-11 18:35:28 UTC
Created attachment 1966 [details]
beginning of patch to add SDL_GetDisplayPhysicalSize

Hello, thanks for you remarks, here's a new version of the patch!

Still need some help for the others platforms. For IOS/MacOSX/WinRT, functions are there, just need the implementation.
Comment 4 Sylvain 2015-09-08 07:57:01 UTC
I have seen that SDL_GetDisplayDPI function was added recently: 

https://hg.libsdl.org/SDL/rev/4df28b087060
https://hg.libsdl.org/SDL/rev/0652406e46c6

So SDL_GetDisplayPhysicalSize may not be needed any-more, or simply could be reimplemented, because the physical size should be easily deduced from DPI and pixel size.

Though, it would be great to have the SDL_GetDisplayDPI for other platforms: e.g android, ios ...  

Maybe some stuff could be picked from the patch of SDL_GetDisplayPhysicalSize.
Comment 5 Alex Szpakowski 2015-09-09 00:06:01 UTC
iOS doesn't have a way to get the display's DPI.