Hi.
Trying to write my first bit of OS X code, a very simple command-line
utility to enable or disable display mirroring. I can turn mirroring
on, but can't seem to to turn it off again.
Here's the routine. Passing mirroringOn in as TRUE works as expected,
but passing in as FALSE just leaves the displays mirrored instead of
resetting them. I've been using this URL:
<http://developer.apple.com/documentation/GraphicsImaging/Reference/Quartz_Servic
es_Ref/qsref_main/chapter_1.2_section_4.html#//apple_ref/doc/uid/TP30001070-Dont
LinkChapterID_2-CGConfigureDisplayMirrorOfDisplay>
...as
my documentation and that seems to suggest passing kCGNullDirectDisplay
as the display ID to mirror should turn things off, but it it isn't
doing. What am I doing wrong?
Thanks in advance for any information,
Ian
------------------
int setMirroring(int mirroringOn) {
int returnCode;
CGDirectDisplayID activeDisplays[kMaxDisplays];
CGDisplayCount displayCount;
CGDisplayConfigRef configRef;
CGDisplayErr result;
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
CGBeginDisplayConfiguration(&configRef);
result = CGGetActiveDisplayList(kMaxDisplays, activeDisplays,
&displayCount);
if(result != CGDisplayNoErr) {
fprintf(stderr, "Error getting Active Display List: %d\n", result);
returnCode = kActiveDisplayListErr;
}
else {
CGDirectDisplayID mirrorMaster = mirroringOn ? mainDisplayID :
kCGNullDirectDisplay);
int i;
for(i = 0; i < displayCount; i++) {
if(activeDisplays[i] != mainDisplayID) {
result = CGConfigureDisplayMirrorOfDisplay(configRef,
activeDisplays[i], mainDisplayID);
if(result != CGDisplayNoErr) {
fprintf(stderr, "Error configuring display id %d,
result = %d\n", activeDisplays[i], result);
returnCode = kDisplayConfigErr;
}
}
}
}
Ian McCall - 24 Aug 2005 00:22 GMT
> result = CGConfigureDisplayMirrorOfDisplay(configRef,
> activeDisplays[i], mainDisplayID);
Sorry, this bit is actually:
CGDirectDisplayID mirrorMaster = (mirroringOn ? mainDisplayID :
kCGNullDirectDisplay);
<etc>
result = CGConfigureDisplayMirrorOfDisplay(configRef,
activeDisplays[i], mirrorMaster);
ie. I -do- make use of the mirrorMaster variable, but still see
mirroring remaining on.
Cheers,
Ian
Ian McCall - 24 Aug 2005 00:49 GMT
> result = CGGetActiveDisplayList(kMaxDisplays, activeDisplays, &displayCount);
It's always the way, isn't it? Spend ages staring at it, post the
question in publ;ic and then pretty much immediately realise what the
answer is.
That call is wrong, it should have been:
result = CGGetOnlineDisplayList(kMaxDisplays, onlineDisplays, &displayCount);
Cheers,
Ian