| Summary: | API to get physical display size. | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Daniel Bünzli <daniel.buenzli> |
| Component: | video | Assignee: | 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 |
||
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).
(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". 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.
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. iOS doesn't have a way to get the display's DPI. Indeed, it seems there are no API for that. Maybe there will be one in the future. Though, there are a few tricks, like detecting the model and hard coding a list. http://stackoverflow.com/questions/3860305/get-ppi-of-iphone-ipad-ipod-touch-at-runtime http://stackoverflow.com/questions/8257947/ios-get-physical-screen-size-programmatically http://stackoverflow.com/questions/28573639/how-do-ruler-apps-stay-accurate-on-all-devices https://gist.github.com/baz/3073573 |
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