Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Modified source to manage two or more monitors' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Modified source to manage two or more monitors
Authored by: juanfal on Apr 17, '09 05:56:01AM
THANKS A LOT! I have found only an annoying C++ error:
$ c++ setgetscreenres.m -framework ApplicationServices -o setgetscreenres
setgetscreenres.m: In function ‘ListDisplays’:
setgetscreenres.m:104: error: ‘for’ loop initial declaration used outside C99 mode
But you can avoid it changing lines 101-104 by:
	int	h, v, depth, freq, i;
	
	printf("Displays found: %dn", dispCount);
	for	(i = 0 ; i < dispCount ;  i++ ) {


[ Reply to This | # ]
One more thing...
Authored by: wallybear on Apr 17, '09 02:49:37PM

Ouch, that's true; I didn't get that error because I compiled it under XCode, which accepts that syntax.
I used XCode to be sure it works also on 10.4 and to make it Universal. It even builds a smaller fat binary (38Kb vs. 46Kb).

The command line compiling instructions given will generate a binary only for the CPU (and System version) of the Mac used.

To compile it as Universal from command line just change the compile command to this:

c++ setgetscreenres.m -framework ApplicationServices -o setgetscreenres -arch i386 -arch ppc

...and to make it work from OS X Panther (10.3.9) or newer, just add this flag at the end of the compile command line:

-mmacosx-version-min=10.3.9

(obviously if you want to exclude OS X Panther then use: -mmacosx-version-min=10.4 )



[ Reply to This | # ]
...a small addition...
Authored by: wallybear on Apr 18, '09 07:55:34AM
Changing my ListDisplays() function with the following, we can see which display is the primary (i.e. the one with the menu bar):

void ListDisplays( CGDisplayCount dispCount, CGDirectDisplayID *dispArray )
{
	int	h, v, depth, freq, i;
	CGDirectDisplayID mainDisplay = CGMainDisplayID();
	
		printf("Displays found: %d\n", dispCount);
		for	(i = 0 ; i < dispCount ;  i++ ) {

			GetDisplayParms(dispArray, i, &h, &v, &depth, &freq);
			printf("Display %d (id %d):  %d x %d x %d @ %dHz", i+1, dispArray[i], h, v, depth, freq);
			if ( mainDisplay == dispArray[i] ) 
				printf(" (main)\n");
			else
				printf("\n");
		}
}
With this mod, the displays listing (using setgetscreenres -l) will look like this one:

Displays found: 3
Display 1 (id 180814742):  1024 x 768 x 32 @ 75Hz
Display 2 (id 188810672):  1920 x 1080 x 32 @ 60Hz (main)
Display 3 (id 160845621):  1440 x 900 x 32 @ 60Hz
stating that Display 2 is the main display.


[ Reply to This | # ]