| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -36,108 +36,82 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <ApplicationServices/ApplicationServices.h> | 
					 | 
					 | 
					 | 
					#include <ApplicationServices/ApplicationServices.h> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// Returns the io_service_t corresponding to a CG display ID, or 0 on failure. | 
					 | 
					 | 
					 | 
					// Get the name of the specified display, or NULL | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// The io_service_t should be released with IOObjectRelease when not needed. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// | 
					 | 
					 | 
					 | 
					// | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					static io_service_t IOServicePortFromCGDisplayID(CGDirectDisplayID displayID) | 
					 | 
					 | 
					 | 
					static char* getDisplayName(CGDirectDisplayID displayID) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					{ | 
					 | 
					 | 
					 | 
					{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    io_iterator_t iter; | 
					 | 
					 | 
					 | 
					    io_iterator_t it; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    io_service_t serv, servicePort = 0; | 
					 | 
					 | 
					 | 
					    io_service_t service; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					    CFDictionaryRef info; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFMutableDictionaryRef matching = IOServiceMatching("IODisplayConnect"); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // releases matching for us | 
					 | 
					 | 
					 | 
					    if (IOServiceGetMatchingServices(kIOMasterPortDefault, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    kern_return_t err = IOServiceGetMatchingServices(kIOMasterPortDefault, | 
					 | 
					 | 
					 | 
					                                     IOServiceMatching("IODisplayConnect"), | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                             matching, | 
					 | 
					 | 
					 | 
					                                     &it) != 0) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                             &iter); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (err) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    { | 
					 | 
					 | 
					 | 
					    { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _glfwInputError(GLFW_PLATFORM_ERROR, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                        "Cocoa: Failed to get display service port iterator"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return 0; | 
					 | 
					 | 
					 | 
					        return 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    while ((serv = IOIteratorNext(iter)) != 0) | 
					 | 
					 | 
					 | 
					    while ((service = IOIteratorNext(it)) != 0) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    { | 
					 | 
					 | 
					 | 
					    { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        CFDictionaryRef info; | 
					 | 
					 | 
					 | 
					        info = IODisplayCreateInfoDictionary(service, kIODisplayOnlyPreferredName); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        CFIndex vendorID, productID; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        CFNumberRef vendorIDRef, productIDRef; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Boolean success; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        info = IODisplayCreateInfoDictionary(serv, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                             kIODisplayOnlyPreferredName); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        vendorIDRef = CFDictionaryGetValue(info, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                           CFSTR(kDisplayVendorID)); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        productIDRef = CFDictionaryGetValue(info, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            CFSTR(kDisplayProductID)); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        success = CFNumberGetValue(vendorIDRef, kCFNumberCFIndexType, | 
					 | 
					 | 
					 | 
					        CFNumberRef vendorIDRef = | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                                   &vendorID); | 
					 | 
					 | 
					 | 
					            CFDictionaryGetValue(info, CFSTR(kDisplayVendorID)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        success &= CFNumberGetValue(productIDRef, kCFNumberCFIndexType, | 
					 | 
					 | 
					 | 
					        CFNumberRef productIDRef = | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                                    &productID); | 
					 | 
					 | 
					 | 
					            CFDictionaryGetValue(info, CFSTR(kDisplayProductID)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					        if (!vendorIDRef || !productIDRef) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (!success) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        { | 
					 | 
					 | 
					 | 
					        { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            CFRelease(info); | 
					 | 
					 | 
					 | 
					            CFRelease(info); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            continue; | 
					 | 
					 | 
					 | 
					            continue; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (CGDisplayVendorNumber(displayID) != vendorID || | 
					 | 
					 | 
					 | 
					        unsigned int vendorID, productID; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            CGDisplayModelNumber(displayID) != productID) | 
					 | 
					 | 
					 | 
					        CFNumberGetValue(vendorIDRef, kCFNumberIntType, &vendorID); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        CFNumberGetValue(productIDRef, kCFNumberIntType, &productID); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (CGDisplayVendorNumber(displayID) == vendorID && | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            CGDisplayModelNumber(displayID) == productID) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        { | 
					 | 
					 | 
					 | 
					        { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            CFRelease(info); | 
					 | 
					 | 
					 | 
					            // Info dictionary is used and freed below | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            continue; | 
					 | 
					 | 
					 | 
					            break; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // we're a match | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        servicePort = serv; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        CFRelease(info); | 
					 | 
					 | 
					 | 
					        CFRelease(info); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        break; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    IOObjectRelease(iter); | 
					 | 
					 | 
					 | 
					    IOObjectRelease(it); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return servicePort; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// Get the name of the specified display | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					static char* getDisplayName(CGDirectDisplayID displayID) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					{ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    char* name; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFDictionaryRef info, names; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFStringRef value; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFIndex size; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    io_service_t serv = IOServicePortFromCGDisplayID(displayID); | 
					 | 
					 | 
					 | 
					    if (!service) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (!serv) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    { | 
					 | 
					 | 
					 | 
					    { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return strdup("Unknown"); | 
					 | 
					 | 
					 | 
					        _glfwInputError(GLFW_PLATFORM_ERROR, | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                        "Cocoa: Failed to find service port for display"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return NULL; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    info = IODisplayCreateInfoDictionary(serv, | 
					 | 
					 | 
					 | 
					    CFDictionaryRef names = | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                         kIODisplayOnlyPreferredName); | 
					 | 
					 | 
					 | 
					        CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    IOObjectRelease(serv); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    names = CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); | 
					 | 
					 | 
					 | 
					    CFStringRef nameRef; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (!names || !CFDictionaryGetValueIfPresent(names, CFSTR("en_US"), | 
					 | 
					 | 
					 | 
					    if (!names || !CFDictionaryGetValueIfPresent(names, CFSTR("en_US"), | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                                                 (const void**) &value)) | 
					 | 
					 | 
					 | 
					                                                 (const void**) &nameRef)) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    { | 
					 | 
					 | 
					 | 
					    { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // This may happen if a desktop Mac is running headless | 
					 | 
					 | 
					 | 
					        // This may happen if a desktop Mac is running headless | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _glfwInputError(GLFW_PLATFORM_ERROR, | 
					 | 
					 | 
					 | 
					        _glfwInputError(GLFW_PLATFORM_ERROR, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        "Cocoa: Failed to retrieve display name"); | 
					 | 
					 | 
					 | 
					                        "Cocoa: Failed to retrieve display name"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        CFRelease(info); | 
					 | 
					 | 
					 | 
					        CFRelease(info); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return strdup("Unknown"); | 
					 | 
					 | 
					 | 
					        return NULL; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), | 
					 | 
					 | 
					 | 
					    const CFIndex size = | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                                             kCFStringEncodingUTF8); | 
					 | 
					 | 
					 | 
					        CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef), | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    name = calloc(size + 1, 1); | 
					 | 
					 | 
					 | 
					                                          kCFStringEncodingUTF8); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFStringGetCString(value, name, size, kCFStringEncodingUTF8); | 
					 | 
					 | 
					 | 
					    char* name = calloc(size + 1, 1); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    CFStringGetCString(nameRef, name, size, kCFStringEncodingUTF8); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    CFRelease(info); | 
					 | 
					 | 
					 | 
					    CFRelease(info); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return name; | 
					 | 
					 | 
					 | 
					    return name; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -332,6 +306,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        const CGSize size = CGDisplayScreenSize(displays[i]); | 
					 | 
					 | 
					 | 
					        const CGSize size = CGDisplayScreenSize(displays[i]); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        char* name = getDisplayName(displays[i]); | 
					 | 
					 | 
					 | 
					        char* name = getDisplayName(displays[i]); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (!name) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            name = strdup("Unknown"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        monitor = _glfwAllocMonitor(name, size.width, size.height); | 
					 | 
					 | 
					 | 
					        monitor = _glfwAllocMonitor(name, size.width, size.height); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        monitor->ns.displayID  = displays[i]; | 
					 | 
					 | 
					 | 
					        monitor->ns.displayID  = displays[i]; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |