18 #include <IOKit/graphics/IOGraphicsLib.h>
19 #include <AppKit/AppKit.h>
23 "title" :
"VuoScreenCommon",
52 #pragma clang diagnostic push
53 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
54 io_service_t port = CGDisplayIOServicePort(displayID);
55 #pragma clang diagnostic pop
57 NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(port, kIODisplayOnlyPreferredName);
59 NSData *edid = [deviceInfo objectForKey:@kIODisplayEDIDKey];
60 NSString *displayLocation = [deviceInfo objectForKey:@kIODisplayLocationKey];
61 NSString *manufacturerName = nil;
62 uint32_t serialNumber = 0;
63 uint8_t manufacturedWeek = 0;
64 uint16_t manufacturedYear = 0;
67 const unsigned char *bytes = (
const unsigned char *)[edid bytes];
69 uint16_t manufacturerId = (bytes[8] << 8) + bytes[9];
71 manufacturerName = [NSString stringWithUTF8String:manufacturer];
74 serialNumber = (bytes[15] << 24) + (bytes[14] << 16) + (bytes[13] << 8) + bytes[12];
76 manufacturedWeek = bytes[16];
77 manufacturedYear = bytes[17] + 1990;
82 if ([displayLocation rangeOfString:
@"SRXDisplayCard" options:0].location != NSNotFound)
83 manufacturerName =
@"Splashtop XDisplay";
84 else if ([displayLocation rangeOfString:
@"info_ennowelbers_proxyframebuffer_fbuffer" options:0].location != NSNotFound)
85 manufacturerName =
@"GoodDual Display";
91 if ([displayLocation rangeOfString:
@"com_yamstu_YamDisplayDriver" options:0].location != NSNotFound)
92 manufacturerName = nil;
95 [deviceInfo autorelease];
96 NSDictionary *localizedNames = [deviceInfo objectForKey:@kDisplayProductName];
98 if ([localizedNames count] > 0)
100 NSString *modelName = [localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]];
101 if ([modelName length] > 0)
103 if (manufacturerName)
104 name = [NSString stringWithFormat:@"%@: %@", manufacturerName, modelName];
112 if (manufacturerName)
113 name = manufacturerName;
118 if (serialNumber && manufacturedYear)
119 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d, %d-W%02d)", name, serialNumber, manufacturedYear, manufacturedWeek] UTF8String]);
120 else if (serialNumber)
121 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d)", name, serialNumber] UTF8String]);
122 else if (manufacturedYear)
123 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d-W%02d)", name, manufacturedYear, manufacturedWeek] UTF8String]);
134 NSDictionary *deviceDescription = [
self deviceDescription];
135 return [[deviceDescription objectForKey:@"NSScreenNumber"] integerValue];
151 for (NSScreen *nsscreen in [NSScreen screens])
168 CGRect bounds = CGDisplayBounds(display);
169 CGDisplayModeRef mode = CGDisplayCopyDisplayMode(display);
170 int backingScaleFactor = CGDisplayModeGetPixelWidth(mode) / bounds.size.width;
171 int fakeDPI = backingScaleFactor * 72;
172 CGDisplayModeRelease(mode);
175 VuoScreenType_MatchId,
177 CGDisplayIDToOpenGLDisplayMask(display),
193 NSScreen *screen = (NSScreen *)vscreen;
206 CGDirectDisplayID displays[256];
207 uint32_t displayCount = 0;
208 CGError e = CGGetOnlineDisplayList(256, displays, &displayCount);
209 if (e != kCGErrorSuccess)
212 VUserLog(
"Error: Couldn't get display info: %s", errorStr);
217 for (
int i = 0; i < displayCount; ++i)
252 CGDirectDisplayID displays[256];
253 uint32_t displayCount = 0;
254 CGError e = CGGetOnlineDisplayList(256, displays, &displayCount);
255 if (e != kCGErrorSuccess)
258 VUserLog(
"Error: Couldn't get display info: %s", errorStr);
263 if (displayCount > 1)
270 #define VuoScreen_reconfigurationCallback_showFlag(a) \
271 if (flags & a) VUserLog(" %s", #a);
279 if (flags == kCGDisplayBeginConfigurationFlag)
284 VUserLog(
"display %x, flags %x", display, flags);
300 const double notificationDelaySeconds = 0.25;
301 static dispatch_source_t timer = 0;
304 dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, notificationDelaySeconds*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, notificationDelaySeconds*NSEC_PER_SEC/10);
307 timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
308 dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, notificationDelaySeconds*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, notificationDelaySeconds*NSEC_PER_SEC/10);
309 dispatch_source_set_event_handler(timer, ^{
311 dispatch_source_cancel(timer);
313 dispatch_source_set_cancel_handler(timer, ^{
314 dispatch_release(timer);
317 dispatch_resume(timer);
348 VUserLog(
"Error: Unbalanced VuoScreen_use() / _disuse() calls.");