RE: IOKit + display models
RE: IOKit + display models
- Subject: RE: IOKit + display models
- From: "Joe van Tunen" <email@hidden>
- Date: Fri, 26 Nov 2004 17:40:58 -0800
- Thread-topic: IOKit + display models
> ----------
> From: Alex Reynolds
> Reply To: email@hidden
> Sent: Thursday, November 25, 2004 7:54 PM
> To: email@hidden
> Subject: IOKit + display models
>
> I'd like to figure out how to get from the IOKit call-equivalent of:
>
> [Sond] reynolda$ ioreg -c AppleDisplay | grep DisplayVendorID
> | | | "DisplayVendorID" = 1552
> | | | "DisplayVendorID" = 4268
> [Sond] reynolda$
>
> to the corresponding list of the two monitor models connected to my machine,
> which the Display system preference says are an "Apple Studio Display" and a
> "Dell 1504FP".
>
> The files in /System/Library/Displays/Overrides/DisplayVendorID-610 are not in
> a
> consistent format as far as the information they return. I'll bet that isn't
> where this information is kept anyway.
>
> There's an entry in there that matches 1552 to an Apple Studio Display but I
> can't find anything for non-Apple displays (e.g. matching the 4268 entry to the
> Dell display).
>
> (This table must be *somewhere* if the Display system preference knows it.)
>
> Does anyone know how to bend IOKit's ear to return this information?
>
> TIA,
> Alex
>
I think IODisplayCreateInfoDictionary does everything you need. The source code is available in the IOKitUser Darwin project so you can see how it works. IODisplayTest.c in the same project (but possibly only in Darwin 6.0 or earlier) shows how to use it.
Below is an updated version of the IODisplayTest code. I couldn't figure out how to get CFBundleCopyPreferredLocalizationsFromArray or CFBundleCopyLocalizationsForPreferences to work properly so I hard coded it to get the english name.
/*
cc -o /tmp/iodt graphics.subproj/IODisplayTest.c -framework CoreGraphics -Wall -undefined warning -g
*/
#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CoreGraphics.h>
#include <IOKit/graphics/IOGraphicsLib.h>
#include <stdlib.h>
void KeyArrayCallback(const void *key, const void *value, void *context)
{
CFArrayAppendValue(context, key);
}
int main(int argc, char * argv[])
{
io_service_t service;
CFDictionaryRef dict;
CFDictionaryRef names;
CFMutableArrayRef langKeys;
CFMutableArrayRef orderLangKeys;
CFNumberRef num;
CGError err;
SInt32 numValue;
int i;
CGDisplayCount max;
CGDirectDisplayID displayIDs[8];
err = CGGetOnlineDisplayList(8, displayIDs, &max);
if(err != kCGErrorSuccess)
exit(1);
if(max > 8)
max = 8;
for(i = 0; i < max; i++ ) {
service = CGDisplayIOServicePort( displayIDs[i] );
if ( !service )
continue;
dict = IODisplayCreateInfoDictionary(service, kNilOptions );
if( dict) {
printf("Display %d\n", i);
num = CFDictionaryGetValue(dict, CFSTR(kDisplayVendorID));
if(num) {
CFNumberGetValue(num, kCFNumberSInt32Type, &numValue);
printf("vendorID %ld\n", numValue);
}
num = CFDictionaryGetValue(dict, CFSTR(kDisplayProductID));
if(num) {
CFNumberGetValue(num, kCFNumberSInt32Type, &numValue);
printf("productID %ld\n", numValue);
}
names = CFDictionaryGetValue(dict, CFSTR(kDisplayProductName));
langKeys = CFArrayCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeArrayCallBacks);
CFDictionaryApplyFunction(names, KeyArrayCallback, (void *) langKeys);
#if 0
/* doesn't work for command line tools? (always returns only the last langKey: zh_CN = Traditional Chinese) */
orderLangKeys = CFBundleCopyPreferredLocalizationsFromArray(langKeys);
#elif 0
/* doesn't work for command line tools? (always returns only the last langKey: zh_CN = Traditional Chinese) */
orderLangKeys = CFBundleCopyLocalizationsForPreferences(langKeys, NULL);
#else
orderLangKeys = CFArrayCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeArrayCallBacks);
CFArrayAppendValue(orderLangKeys, CFSTR("en_US"));
#endif
CFRelease(langKeys);
if(orderLangKeys && CFArrayGetCount(orderLangKeys)) {
char cName[256];
CFStringRef langKey;
CFStringRef localName;
langKey = CFArrayGetValueAtIndex(orderLangKeys, 0);
localName = CFDictionaryGetValue(names, langKey);
CFStringGetCString(localName, cName, sizeof(cName),
CFStringGetSystemEncoding());
printf("local name \"%s\"\n", cName);
}
CFRelease(orderLangKeys);
printf("\nAll info:\n");
CFShow(dict);
CFRelease(dict);
}
// --
/*
{
IOCFPlugInInterface ** interface;
IODisplayCreateInterface( service, kNilOptions,
kIODisplayControlInterfaceID, &interface );
}
*/
/*
{
CFMutableDictionaryRef dict;
CFNumberRef num;
SInt32 value;
dict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
for( value = 0; value < 0x60; value++) {
num = CFNumberCreate( kCFAllocatorDefault, kCFNumberSInt32Type, &value );
CFDictionarySetValue( dict, CFSTR("contrast"), num );
CFRelease(num);
err = IODisplaySetParameters( service, kNilOptions, dict );
}
CFRelease(dict);
}
*/
// --
}
exit(0);
return(0);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden