Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to get physical display size. #1422

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 1 comment
Closed

API to get physical display size. #1422

SDLBugzilla opened this issue Feb 10, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.3
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2014-03-31 23:40:24 +0000, Daniel Bünzli wrote:

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

On 2014-08-01 18:13:25 +0000, Sylvain wrote:

Created attachment 1801
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).

On 2014-12-09 22:55:51 +0000, Philipp Wiesemann wrote:

(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".

On 2014-12-11 18:35:28 +0000, Sylvain wrote:

Created attachment 1966
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.

On 2015-09-08 07:57:01 +0000, Sylvain wrote:

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.

On 2015-09-09 00:06:01 +0000, Alex Szpakowski wrote:

iOS doesn't have a way to get the display's DPI.

On 2015-09-09 06:24:20 +0000, Sylvain wrote:

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

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 10, 2021
@icculus
Copy link
Collaborator

icculus commented Nov 30, 2021

Closing this, since SDL_GetDisplayDPI() solves the original problem.

("This doesn't work on platform X" can be filed separately as people run into problems.)

@icculus icculus closed this as completed Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants