aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2013-11-05 08:51:55 +0100
committerJan Djärv2013-11-05 08:51:55 +0100
commitceb486d4970c9080d2974d6852de9e9eb846d990 (patch)
treed4e870f0c2346eb6b0894e7514e0602b9dda9446 /src
parenta67c4ae05909874c97f86b11dcb8ddc88b3e960c (diff)
downloademacs-ceb486d4970c9080d2974d6852de9e9eb846d990.tar.gz
emacs-ceb486d4970c9080d2974d6852de9e9eb846d990.zip
* nsfns.m (ns_get_name_from_ioreg): New function.
(ns_screen_name): Don't use deprecated CGDisplayIOServicePort on OSX >= 10.9. Use ns_get_name_from_ioreg.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/nsfns.m84
2 files changed, 77 insertions, 13 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 9ba39e20432..227b86a4cab 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12013-11-05 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsfns.m (ns_get_name_from_ioreg): New function.
4 (ns_screen_name): Don't use deprecated CGDisplayIOServicePort on
5 OSX >= 10.9. Use ns_get_name_from_ioreg.
6
12013-11-05 Paul Eggert <eggert@cs.ucla.edu> 72013-11-05 Paul Eggert <eggert@cs.ucla.edu>
2 8
3 Simplify and port recent bool vector changes. 9 Simplify and port recent bool vector changes.
diff --git a/src/nsfns.m b/src/nsfns.m
index c6730f41aa7..ee36439b1b4 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2358,28 +2358,86 @@ each physical monitor, use `display-monitor-attributes-list'. */)
2358} 2358}
2359 2359
2360#ifdef NS_IMPL_COCOA 2360#ifdef NS_IMPL_COCOA
2361/* Returns the name for the screen that DICT came from, or NULL. 2361
2362/* Returns the name for the screen that OBJ represents, or NULL.
2362 Caller must free return value. 2363 Caller must free return value.
2363*/ 2364*/
2364 2365
2365static char * 2366static char *
2366ns_screen_name (CGDirectDisplayID did) 2367ns_get_name_from_ioreg (io_object_t obj)
2367{ 2368{
2368 char *name = NULL; 2369 char *name = NULL;
2370
2369 NSDictionary *info = (NSDictionary *) 2371 NSDictionary *info = (NSDictionary *)
2370 IODisplayCreateInfoDictionary (CGDisplayIOServicePort (did), 2372 IODisplayCreateInfoDictionary (obj, kIODisplayOnlyPreferredName);
2371 kIODisplayOnlyPreferredName); 2373 NSDictionary *names = [info objectForKey:
2372 NSDictionary *names 2374 [NSString stringWithUTF8String:
2373 = [info objectForKey: 2375 kDisplayProductName]];
2374 [NSString stringWithUTF8String:kDisplayProductName]]; 2376
2375 2377 if ([names count] > 0)
2376 if ([names count] > 0) { 2378 {
2377 NSString *n = [names objectForKey: [[names allKeys] objectAtIndex:0]]; 2379 NSString *n = [names objectForKey: [[names allKeys]
2378 if (n != nil) 2380 objectAtIndex:0]];
2379 name = xstrdup ([n UTF8String]); 2381 if (n != nil) name = xstrdup ([n UTF8String]);
2380 } 2382 }
2381 2383
2382 [info release]; 2384 [info release];
2385
2386 return name;
2387}
2388
2389/* Returns the name for the screen that DID came from, or NULL.
2390 Caller must free return value.
2391*/
2392
2393static char *
2394ns_screen_name (CGDirectDisplayID did)
2395{
2396 char *name = NULL;
2397
2398#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
2399 mach_port_t masterPort;
2400 io_iterator_t it;
2401 io_object_t obj;
2402
2403 // CGDisplayIOServicePort is deprecated. Do it another (harder) way.
2404
2405 if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess
2406 || IOServiceGetMatchingServices (masterPort,
2407 IOServiceMatching ("IONDRVDevice"),
2408 &it) != kIOReturnSuccess)
2409 return name;
2410
2411 /* Must loop until we find a name. Many devices can have the same unit
2412 number (represents different GPU parts), but only one has a name. */
2413 while (! name && (obj = IOIteratorNext (it)))
2414 {
2415 CFMutableDictionaryRef props;
2416 const void *val;
2417
2418 if (IORegistryEntryCreateCFProperties (obj,
2419 &props,
2420 kCFAllocatorDefault,
2421 kNilOptions) == kIOReturnSuccess
2422 && props != nil
2423 && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
2424 {
2425 unsigned nr = [(NSNumber *)val unsignedIntegerValue];
2426 if (nr == CGDisplayUnitNumber (did))
2427 name = ns_get_name_from_ioreg (obj);
2428 }
2429
2430 CFRelease (props);
2431 IOObjectRelease (obj);
2432 }
2433
2434 IOObjectRelease (it);
2435
2436#else
2437
2438 name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did));
2439
2440#endif
2383 return name; 2441 return name;
2384} 2442}
2385#endif 2443#endif