]> git.eshelyaron.com Git - emacs.git/commitdiff
* nsfns.m (ns_get_name_from_ioreg): New function.
authorJan Djärv <jan.h.d@swipnet.se>
Tue, 5 Nov 2013 07:51:55 +0000 (08:51 +0100)
committerJan Djärv <jan.h.d@swipnet.se>
Tue, 5 Nov 2013 07:51:55 +0000 (08:51 +0100)
(ns_screen_name): Don't use deprecated CGDisplayIOServicePort on
OSX >= 10.9.  Use ns_get_name_from_ioreg.

src/ChangeLog
src/nsfns.m

index 9ba39e20432cd1d8b750cbec29b0a16496a04deb..227b86a4cab80cebed17fc532d668db9cb351318 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-05  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * 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.
+
 2013-11-05  Paul Eggert  <eggert@cs.ucla.edu>
 
        Simplify and port recent bool vector changes.
index c6730f41aa7100a0e6cd7741f424051b818d6bf3..ee36439b1b42badc329ccc0e9c613ce6e2bb8696 100644 (file)
@@ -2358,28 +2358,86 @@ each physical monitor, use `display-monitor-attributes-list'.  */)
 }
 
 #ifdef NS_IMPL_COCOA
-/* Returns the name for the screen that DICT came from, or NULL.
+
+/* Returns the name for the screen that OBJ represents, or NULL.
    Caller must free return value.
 */
 
 static char *
-ns_screen_name (CGDirectDisplayID did)
+ns_get_name_from_ioreg (io_object_t obj)
 {
   char *name = NULL;
+
   NSDictionary *info = (NSDictionary *)
-    IODisplayCreateInfoDictionary (CGDisplayIOServicePort (did),
-                                   kIODisplayOnlyPreferredName);
-  NSDictionary *names
-    = [info objectForKey:
-              [NSString stringWithUTF8String:kDisplayProductName]];
-
-  if ([names count] > 0) {
-    NSString *n = [names objectForKey: [[names allKeys] objectAtIndex:0]];
-    if (n != nil)
-      name = xstrdup ([n UTF8String]);
-  }
+    IODisplayCreateInfoDictionary (obj, kIODisplayOnlyPreferredName);
+  NSDictionary *names = [info objectForKey:
+                                [NSString stringWithUTF8String:
+                                            kDisplayProductName]];
+
+  if ([names count] > 0)
+    {
+      NSString *n = [names objectForKey: [[names allKeys]
+                                                 objectAtIndex:0]];
+      if (n != nil) name = xstrdup ([n UTF8String]);
+    }
 
   [info release];
+
+  return name;
+}
+
+/* Returns the name for the screen that DID came from, or NULL.
+   Caller must free return value.
+*/
+
+static char *
+ns_screen_name (CGDirectDisplayID did)
+{
+  char *name = NULL;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
+  mach_port_t masterPort;
+  io_iterator_t it;
+  io_object_t obj;
+
+  // CGDisplayIOServicePort is deprecated.  Do it another (harder) way.
+
+  if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess
+      || IOServiceGetMatchingServices (masterPort,
+                                       IOServiceMatching ("IONDRVDevice"),
+                                       &it) != kIOReturnSuccess)
+    return name;
+
+  /* Must loop until we find a name.  Many devices can have the same unit
+     number (represents different GPU parts), but only one has a name.  */
+  while (! name && (obj = IOIteratorNext (it)))
+    {
+      CFMutableDictionaryRef props;
+      const void *val;
+
+      if (IORegistryEntryCreateCFProperties (obj,
+                                             &props,
+                                             kCFAllocatorDefault,
+                                             kNilOptions) == kIOReturnSuccess
+          && props != nil
+          && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
+        {
+          unsigned nr = [(NSNumber *)val unsignedIntegerValue];
+          if (nr == CGDisplayUnitNumber (did))
+            name = ns_get_name_from_ioreg (obj);
+        }
+
+      CFRelease (props);
+      IOObjectRelease (obj);
+    }
+
+  IOObjectRelease (it);
+
+#else
+
+  name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did));
+
+#endif
   return name;
 }
 #endif