mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 21:30:57 +00:00
Fixed problem with no existing serial number for built-in display
This commit is contained in:
parent
e0a6772e5e
commit
8e3c423ed4
@ -57,50 +57,53 @@ static io_service_t IOServicePortFromCGDisplayID(CGDirectDisplayID displayID)
|
|||||||
|
|
||||||
while((serv = IOIteratorNext(iter)) != 0)
|
while((serv = IOIteratorNext(iter)) != 0)
|
||||||
{
|
{
|
||||||
CFDictionaryRef info;
|
CFDictionaryRef displayInfo;
|
||||||
CFIndex vendorID, productID, serialNumber;
|
|
||||||
CFNumberRef vendorIDRef, productIDRef, serialNumberRef;
|
CFNumberRef vendorIDRef;
|
||||||
|
CFNumberRef productIDRef;
|
||||||
|
CFNumberRef serialNumberRef;
|
||||||
|
|
||||||
|
NSNumber *vendorID;
|
||||||
|
NSNumber *productID;
|
||||||
|
NSNumber *serialNumber;
|
||||||
|
|
||||||
Boolean success;
|
Boolean success;
|
||||||
|
|
||||||
info = IODisplayCreateInfoDictionary(serv,
|
displayInfo = IODisplayCreateInfoDictionary(serv, kIODisplayOnlyPreferredName);
|
||||||
kIODisplayOnlyPreferredName);
|
|
||||||
|
|
||||||
vendorIDRef = CFDictionaryGetValue(info,
|
success = CFDictionaryGetValueIfPresent(displayInfo, CFSTR(kDisplayVendorID), (const void**)&vendorIDRef);
|
||||||
CFSTR(kDisplayVendorID));
|
success &= CFDictionaryGetValueIfPresent(displayInfo, CFSTR(kDisplayProductID), (const void**)&productIDRef);
|
||||||
productIDRef = CFDictionaryGetValue(info,
|
|
||||||
CFSTR(kDisplayProductID));
|
|
||||||
serialNumberRef = CFDictionaryGetValue(info,
|
|
||||||
CFSTR(kDisplaySerialNumber));
|
|
||||||
|
|
||||||
success = CFNumberGetValue(vendorIDRef, kCFNumberCFIndexType,
|
|
||||||
&vendorID);
|
|
||||||
success &= CFNumberGetValue(productIDRef, kCFNumberCFIndexType,
|
|
||||||
&productID);
|
|
||||||
success &= CFNumberGetValue(serialNumberRef, kCFNumberCFIndexType,
|
|
||||||
&serialNumber);
|
|
||||||
|
|
||||||
if(!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
CFRelease(info);
|
CFRelease(displayInfo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vendorID = (__bridge NSNumber*)vendorIDRef;
|
||||||
|
productID = (__bridge NSNumber*)productIDRef;
|
||||||
|
|
||||||
|
// If a serial number is found use it
|
||||||
|
// Otherwise serial number will be nil (= 0) which will match with the output of 'CGDisplaySerialNumber'
|
||||||
|
if(CFDictionaryGetValueIfPresent(displayInfo, CFSTR(kDisplaySerialNumber), (const void**)&serialNumberRef))
|
||||||
|
{
|
||||||
|
serialNumber = (__bridge NSNumber*)serialNumberRef;
|
||||||
|
}
|
||||||
|
|
||||||
// If the vendor and product id along with the serial don't match
|
// If the vendor and product id along with the serial don't match
|
||||||
// then we are not looking at the correct monitor.
|
// then we are not looking at the correct monitor.
|
||||||
// NOTE: The serial number is important in cases where two monitors
|
// NOTE: The serial number is important in cases where two monitors
|
||||||
// are the exact same.
|
// are the exact same.
|
||||||
if (CGDisplayVendorNumber(displayID) != vendorID ||
|
if(CGDisplayVendorNumber(displayID) != vendorID.unsignedIntValue ||
|
||||||
CGDisplayModelNumber(displayID) != productID ||
|
CGDisplayModelNumber(displayID) != productID.unsignedIntValue ||
|
||||||
CGDisplaySerialNumber(displayID) != serialNumber)
|
CGDisplaySerialNumber(displayID) != serialNumber.unsignedIntValue)
|
||||||
{
|
{
|
||||||
CFRelease(info);
|
CFRelease(displayInfo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The VendorID, Product ID, and the Serial Number all Match Up!
|
|
||||||
// Therefore we have found the appropriate display io_service
|
|
||||||
servicePort = serv;
|
servicePort = serv;
|
||||||
CFRelease(info);
|
CFRelease(displayInfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user