diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-10-01 22:52:20 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-10-01 22:52:20 +0300 |
commit | b0152dcac5b7e7e3112089949856019c65ce2e23 (patch) | |
tree | e03d6082c6564bc2a6c39d1f61d6391f9d35fac3 /platform | |
parent | 25ca77c3796602b52ee9dca98abbb35aa9ede773 (diff) |
Fix `screen_get_dpi` on macOS for non fractional display scales and restore documentation.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/osx/display_server_osx.mm | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 49f0e7bfa3..cd5b71890c 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -2246,11 +2246,18 @@ int DisplayServerOSX::screen_get_dpi(int p_screen) const { NSArray *screenArray = [NSScreen screens]; if ((NSUInteger)p_screen < [screenArray count]) { NSDictionary *description = [[screenArray objectAtIndex:p_screen] deviceDescription]; - NSSize displayDPI = [[description objectForKey:NSDeviceResolution] sizeValue]; - return (displayDPI.width + displayDPI.height) / 2; + + const NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + const CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + float scale = [[screenArray objectAtIndex:p_screen] backingScaleFactor]; + + float den2 = (displayPhysicalSize.width / 25.4f) * (displayPhysicalSize.width / 25.4f) + (displayPhysicalSize.height / 25.4f) * (displayPhysicalSize.height / 25.4f); + if (den2 > 0.0f) { + return ceil(sqrt(displayPixelSize.width * displayPixelSize.width + displayPixelSize.height * displayPixelSize.height) / sqrt(den2) * scale); + } } - return 96; + return 72; } float DisplayServerOSX::screen_get_scale(int p_screen) const { |