17 #include <IOKit/graphics/IOGraphicsLib.h>
20 #ifndef NS_RETURNS_INNER_POINTER
21 #define NS_RETURNS_INNER_POINTER
23 #include <AppKit/AppKit.h>
27 "title" :
"VuoScreenCommon",
56 #pragma clang diagnostic push
57 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
58 io_service_t port = CGDisplayIOServicePort(displayID);
59 #pragma clang diagnostic pop
61 NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(port, kIODisplayOnlyPreferredName);
63 NSData *edid = [deviceInfo objectForKey:@kIODisplayEDIDKey];
64 NSString *displayLocation = [deviceInfo objectForKey:@kIODisplayLocationKey];
65 NSString *manufacturerName = nil;
66 uint32_t serialNumber = 0;
67 uint8_t manufacturedWeek = 0;
68 uint16_t manufacturedYear = 0;
71 const unsigned char *bytes = (
const unsigned char *)[edid bytes];
73 uint16_t manufacturerId = (bytes[8] << 8) + bytes[9];
75 manufacturerName = [NSString stringWithUTF8String:manufacturer];
78 serialNumber = (bytes[15] << 24) + (bytes[14] << 16) + (bytes[13] << 8) + bytes[12];
80 manufacturedWeek = bytes[16];
81 manufacturedYear = bytes[17] + 1990;
86 if ([displayLocation rangeOfString:
@"SRXDisplayCard" options:0].location != NSNotFound)
87 manufacturerName =
@"Splashtop XDisplay";
88 else if ([displayLocation rangeOfString:
@"info_ennowelbers_proxyframebuffer_fbuffer" options:0].location != NSNotFound)
89 manufacturerName =
@"GoodDual Display";
95 if ([displayLocation rangeOfString:
@"com_yamstu_YamDisplayDriver" options:0].location != NSNotFound)
96 manufacturerName = nil;
99 [deviceInfo autorelease];
100 NSDictionary *localizedNames = [deviceInfo objectForKey:@kDisplayProductName];
101 NSString *name = nil;
102 if ([localizedNames count] > 0)
104 NSString *modelName = [localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]];
105 if ([modelName length] > 0)
107 if (manufacturerName)
108 name = [NSString stringWithFormat:@"%@: %@", manufacturerName, modelName];
116 if (manufacturerName)
117 name = manufacturerName;
122 if (serialNumber && manufacturedYear)
123 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d, %d-W%02d)", name, serialNumber, manufacturedYear, manufacturedWeek] UTF8String]);
124 else if (serialNumber)
125 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d)", name, serialNumber] UTF8String]);
126 else if (manufacturedYear)
127 return VuoText_make([[NSString stringWithFormat:
@"%@ (%d-W%02d)", name, manufacturedYear, manufacturedWeek] UTF8String]);
138 NSDictionary *deviceDescription = [
self deviceDescription];
139 return [[deviceDescription objectForKey:@"NSScreenNumber"] integerValue];
155 for (NSScreen *nsscreen in [NSScreen screens])
172 CGRect bounds = CGDisplayBounds(display);
173 CGDisplayModeRef mode = CGDisplayCopyDisplayMode(display);
174 int backingScaleFactor = CGDisplayModeGetPixelWidth(mode) / bounds.size.width;
175 int fakeDPI = backingScaleFactor * 72;
176 CGDisplayModeRelease(mode);
179 VuoScreenType_MatchId,
181 CGDisplayIDToOpenGLDisplayMask(display),
197 NSScreen *screen = (NSScreen *)vscreen;
210 CGDirectDisplayID displays[256];
211 uint32_t displayCount = 0;
212 CGError e = CGGetOnlineDisplayList(256, displays, &displayCount);
213 if (e != kCGErrorSuccess)
216 VUserLog(
"Error: Couldn't get display info: %s", errorStr);
221 for (
int i = 0; i < displayCount; ++i)
254 CGDirectDisplayID displays[256];
255 uint32_t displayCount = 0;
256 CGError e = CGGetOnlineDisplayList(256, displays, &displayCount);
257 if (e != kCGErrorSuccess)
260 VUserLog(
"Error: Couldn't get display info: %s", errorStr);
265 if (displayCount > 1)
272 #define VuoScreen_reconfigurationCallback_showFlag(a) \
273 if (flags & a) VUserLog(" %s", #a);
281 if (flags == kCGDisplayBeginConfigurationFlag)
286 VUserLog(
"display %x, flags %x", display, flags);
302 const double notificationDelaySeconds = 0.25;
303 static dispatch_source_t timer = 0;
306 dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, notificationDelaySeconds*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, notificationDelaySeconds*NSEC_PER_SEC/10);
309 timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
310 dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, notificationDelaySeconds*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, notificationDelaySeconds*NSEC_PER_SEC/10);
311 dispatch_source_set_event_handler(timer, ^{
313 dispatch_source_cancel(timer);
315 dispatch_source_set_cancel_handler(timer, ^{
316 dispatch_release(timer);
319 dispatch_resume(timer);
350 VUserLog(
"Error: Unbalanced VuoScreen_use() / _disuse() calls.");