Given a CGDirectDisplayID returned from
CGError error = CGGetActiveDisplayList(8, directDisplayIDs, &displayCount);
for the built-in screen on a Retina MacBook Pro, I would expect to fetch the native pixel dimensions using
size_t pixelWidth = CGDisplayPixelsWide(directDisplayID);
size_t pixelHeight = CGDisplayPixelsHigh(directDisplayID);
However, these calls only return the dimensions of the currently selected mode. If I change screen resolution I get back different values. I was looking to get back 2880 x 1800 on a 15" rMBP.
How do I fetch the native pixel dimensions of a Retina MacBook Pro screen?
MacBook Pro (Retina, 13-inch, Late 2012) and later displays have a 2560-by-1600 native resolution at 227 pixels per inch with support for millions of colors.
(Note that “About This Mac” always show the native (ideal) resolution of the display regardless of the resolution settings in System Preferences.) If you have more than one display attached to your Mac, you will see all of them in this window. Here’s an example. With an external display, you’ll find its native resolution listed just under its name.
How the Retina Display MacBook Pro Handles Scaling. By default, the Retina MBP ships in a pixel doubled configuration. You get the effective desktop resolution of the standard 15-inch MacBook Pro's 1440 x 900 panel, but with four physical pixels driving every single pixel represented on the screen.
These Mac computers have a built-in Retina display: MacBook Pro models: 15-inch MacBook Pro models introduced in 2012 or later, except the MacBook Pro (15-inch, Mid 2012). Native resolution: 2880 x 1800 at 220 pixels per inch. Support for millions of colors.
I think the best approach is to enumerate all of the display modes (including the 1x modes) and find the biggest 1x mode's dimensions.
You would use CGDisplayCopyAllDisplayModes()
and pass a dictionary with the key kCGDisplayShowDuplicateLowResolutionModes
mapped to kCFBooleanTrue
as the options
to get all of the modes. You can test that CGDisplayModeGetPixelWidth()
is equal to CGDisplayModeGetWidth()
to determine which are 1x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With