Skip to content

Instantly share code, notes, and snippets.

@garethjenkins
Created July 1, 2012 10:26
Show Gist options
  • Save garethjenkins/3027840 to your computer and use it in GitHub Desktop.
Save garethjenkins/3027840 to your computer and use it in GitHub Desktop.
enumerate displays using CGGetActiveDisplayList
CGDirectDisplayID displays[MAX_DISPLAYS];
uint32_t numDisplays;
uint32_t i;
CGGetActiveDisplayList(MAX_DISPLAYS, displays, &numDisplays);
for(i=0; i<numDisplays; i++)
{
CGDisplayModeRef mode;
CFIndex index, count;
CFArrayRef modeList;
modeList=CGDisplayCopyAllDisplayModes(displays[i], NULL);
count=CFArrayGetCount(modeList);
NSLog(@"\n\nmode --");
for(index=0;index<count;index++)
{
mode=(CGDisplayModeRef)CFArrayGetValueAtIndex(modeList, index);
long h=0, w=0;
h=CGDisplayModeGetHeight(mode);
w=CGDisplayModeGetWidth(mode);
uint32_t flags=CGDisplayModeGetIOFlags(mode);
NSLog(@"flags: %d", flags);
NSLog(@"w, h: %ld, %ld", w, h);
//test mode here against required params and set, using:
//CGDisplaySetDisplayMode(displays[i], mode, NULL);
}
CFRelease(modeList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment