Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically determine native pixel resolution of Retina MacBook Pro screen on OS X?

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?

like image 563
Chris Miles Avatar asked Dec 13 '12 11:12

Chris Miles


People also ask

What is the native resolution of the 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.

How do I find the native resolution of my Mac screen?

(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 does the retina display MacBook Pro handle scaling?

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.

Do all MacBooks have a Retina Display?

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.


1 Answers

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.

like image 51
Ken Thomases Avatar answered Sep 25 '22 12:09

Ken Thomases