Re: Screen device name?
Re: Screen device name?
- Subject: Re: Screen device name?
- From: Mike Paquette <email@hidden>
- Date: Wed, 6 Sep 2006 15:34:43 -0700
On Sep 6, 2006, at 12:51 PM, Trygve Inda wrote:
Given an NSScreen, how can I get the device name, e.g. "Cinema HD
Display"?
There is no key for this in [NSScreen deviceDescription]
Get the CGDIrectDisplayID from NSScreen. For example:
CGDirectDisplayID display = (CGDirectDisplayID) [[[[NSScreen
mainScreen] deviceDescription] @"NSScreenNumber"] unsignedIntValue];
Note: CGMainDisplayID() is a cheaper way to get the main display...
The following code extracts the localized display name as a
CFStringRef. Add error checking and recovery as appropriate.
static void KeyArrayCallback(const void *key, const void *value, void
*context) { CFArrayAppendValue(context, key); }
CFStringRef CopyLocalDisplayName(CGDirectDisplayID display)
{
CFArrayRef langKeys, orderLangKeys;
CFStringRef langKey, localName;
io_connect_t displayPort;
CFDictionaryRef dict, names;
localName = NULL;
displayPort = CGDisplayIOServicePort(display);
if ( displayPort == MACH_PORT_NULL )
return NULL; /* No physical device to get a name from */
dict = IOCreateDisplayInfoDictionary(displayPort, 0);
names = CFDictionaryGetValue( dict, CFSTR(kDisplayProductName) );
/* Extract all the display name locale keys */
langKeys = CFArrayCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeArrayCallBacks );
CFDictionaryApplyFunction( names, KeyArrayCallback, (void *)
langKeys );
/* Get the preferred order of localizations */
orderLangKeys = CFBundleCopyPreferredLocalizationsFromArray
( langKeys );
CFRelease( langKeys );
if( orderLangKeys && CFArrayGetCount(orderLangKeys) )
{
langKey = CFArrayGetValueAtIndex( orderLangKeys, 0 );
localName = CFDictionaryGetValue( names, langKey );
CFRetain( localName );
}
CFRelease(orderLangKeys);
CFRelease(dict);
return localName;
}
Mike Paquette
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden