Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / August 2005



Tip: Looking for answers? Try searching our database.

Turning off display mirroring?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian McCall - 24 Aug 2005 00:08 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.