CGDisplayCopyAllDisplayModes excludes one valid mode

When working programmatically with display modes in OS X ( documentation ), I found that CGDisplayCopyAllDisplayModes does not take into account the rightmost option that is presented in the system settings.

A simple utility that prints the size of the current display mode, and all available sizes of the display mode display this

 current size: 1920x1200 available sizes: 2880x1800 1440x900 2560x1600 2048x1280 1024x768 800x600 640x480 1680x1050 1280x800 

1920x1200 is a valid option enter image description here

All other parameters that specify system settings are presented in the list. Does anyone know why 1920x1200 might not turn on? I tried moving to another predefined value in the system prefixes, but did not enable 1920x1200 .

Edit (the accepted answer is much better than these frauds, but I leave this information just in case)

β€œScalable” display modes can be found by referencing a private API.

You can create a header file that makes private methods available: see this meaning , which I borrowed from this project .

Then you can see all modes, including scaled ones, such as

 print("Private modes:\n") var numDisplayModes: Int32 = 0 CGSGetNumberOfDisplayModes(mainDisplayID, &numDisplayModes) print("Num modes \(numDisplayModes)") for i in 0...(numDisplayModes-1) { var pmode: CGPrivDisplayMode = CGPrivDisplayMode() CGSGetDisplayModeDescriptionOfLength(mainDisplayID, CInt(i), &pmode, CInt(sizeof(CGPrivDisplayMode))) print("\t\(pmode.modeNumber): \(pmode.width)x\(pmode.height) -- \(pmode.density) \n") } 
+6
source share
1 answer

There is a public API that is only documented in the header. CGDisplayCopyAllDisplayModes() accepts the options parameter, which is a dictionary. The documents (and even the headers) say that they are not used and you must pass NULL , but you can pass the dictionary with the key kCGDisplayShowDuplicateLowResolutionModes and the value kCFBooleanTrue .

The name of the option is not entirely clear. It includes many additional modes.

Additionally, you may need to use CGDisplayModeGetPixelWidth() and CGDisplayModeGetPixelHeight() to distinguish between the point size and the pixel size of the backup storage. ( CGDisplayModeGetWidth() and CGDisplayModeGetHeight() ). By comparing these values, you can determine if the mode is scaled.)

+4
source

Source: https://habr.com/ru/post/989175/


All Articles