-
Notifications
You must be signed in to change notification settings - Fork 25
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
Provide Physical Dimensions / PPI of Displays #65
Comments
Thanks for proposing that enhancement! This may be possible in some circumstances, but not always (e.g. projectors). |
Hi @michaelwasserman, sorry for the slow response. I came up with a lot of simple use cases, some shared in this tweet thread (Watch the 27 second video and the 2 or 3 responses below). Design Tools PreviewingI think the first strong use case for web apps to have access to each displays sizes is in web based creative tools. Examples:
Shopping Item SizingIt would reduce a lot of anxiety, reduce errors, and likely save a lot of time for people when they are shopping for physical items online. Examples:
|
In case it is useful to the drafting group or others reading this thread, here is how we do this at Cuttle. Context: Cuttle is a web-based CAD tool for laser cutting. We provide a View > Zoom to Real Size feature which is helpful because you can hold up existing parts to your monitor to spot check that you got your dimensions correct before you fabricate. We need to know the pixels-per-inch of your display in order to implement this feature. We assume people might use different monitors (e.g. laptop screen vs external display) at different times. We keep in If web standards gave us the pixels-per-inch of the current display (similarly how (Due to the keystone effect, projectors also create arbitrary perspective distortions, so a single pixels-per-inch value is likely insufficient to describe the mapping from pixels to physical units in this case. I assume this is outside the scope of the standard at this time, though I can go deeper into this based on my experience at Dynamicland if you want to go down this rabbit hole!) It would be great if this feature were to make it into the standard. It would enable more digital-physical hybrid applications. |
I really appreciate the detailed use cases you've both provided, thank you! This seems like a great enhancement request. According to the definitions of Do non-web applications provide similar functionality without calibration? It seems like EDID screen size values (plus screen resolution) could be used as the basis to expose the physical dimensions / PPI of displays. |
I don't think user agents ever implement this stuff correctly. My impression is that device manufacturers have to decide when they want to report their coordinate as >1 devicePixelRatio which will likely effect the style of UIs because of responsive design. So usually wanting to ensure mobile, tablet, or desktop centric layouts are triggered by the typical app when using their device. Browser API ExperimentsI've tried various tricks using each css unit system and they all tend to report the same fixed values regardless of device. Try opening this page on any device or each screen of a single device to see for yourself (Make sure to refresh the browser when moving this window to a new display in a multi-monitor setup): https://codesandbox.io/s/ancient-wave-f8uci?file=/src/index.js. This is based on reading back the pixel dimensions based on an element set with the inches units: All devices report 96ppi but have the real PPIs of:
Native APIs for Querying PPIWhen I implemented an Electron based prototype for this in 2017, for macOS only, I was easily able to query for this information. I'm sure the latest APIs are based on the same approach. The Windows equivalent looks pretty similar. Here's the source code for my prototype. Here it is inlined: long targetScreenId = atoi(argv[1]);
long count = [[NSScreen screens] count];
// Find the screen with the same screen ID
for(int i = 0; i<count; i++){
NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
NSDictionary *description = [screen deviceDescription];
NSNumber* screenId = [description objectForKey:@"NSScreenNumber"];
if([screenId longValue] == targetScreenId){
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize(
[screenId unsignedIntValue]);
// There are 25.4 millimeters per inch:
// https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=mm+to+inches
printf("%0.2f",(displayPixelSize.width / displayPhysicalSize.width) * 25.4f);
// Exit successfully
return 0;
}
} What's next if this is interesting to this standards group? Anything else you'd like to make a compelling case? |
Something to note, my example code above doesn't factor in pixelDeviceRatio or what is called scale in Swift or backingScaleFactor in Objective-C. Here is a touched up full XCode project that will print out the ppi and devicePixelRatio of each monitor on a mac. |
Thanks again for the great info. We will consider our options to support these use cases more thoroughly as the spec continues to advance through the standardization process. I encourage other web application developers to express support for this request and share their use cases, as that can increase prioritization of this enhancement request. |
possibly related (though the discussions there we always more around "can we change CSS to make |
Yes please. Some more related content below for additional context … Most relevant is a similar issue I submitted back in 2016. Warning: it is a loooong thread of discussion, and it was closed as "won't fix" (though the comments remain active with other request for the issue to be reopened): Here's an article I wrote on the topic almost 10(!) years ago: A challenge on Twitter that still stands after almost 10 years: |
It would be very useful to be know the size of displays in physics units. This has applications in responsive designs to model users and in displaying graphics realistically.
Returning a ppi (pixels per inch) or display dimensions (size of entire display covered in pixels) in the payload of window.getScreens() would be awesome.
The text was updated successfully, but these errors were encountered: