static struct display_mode_descriptor* create_original_display_mode_descriptor(CGDirectDisplayID displayID) { static const char display_key_format[] = "Software\\Wine\\Mac Driver\\Initial Display Mode\\Display 0x%08x"; struct display_mode_descriptor* ret = NULL; struct display_mode_descriptor* desc; char display_key[sizeof(display_key_format) + 10]; HKEY hkey; DWORD type, size; DWORD refresh100; WCHAR* pixel_encoding = NULL, *end; init_original_display_mode(); snprintf(display_key, sizeof(display_key), display_key_format, CGDisplayUnitNumber(displayID)); /* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode\Display 0xnnnnnnnn */ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, display_key, 0, KEY_READ, &hkey)) return NULL; desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc)); desc->pixel_encoding = NULL; if (!read_dword(hkey, "Width", &desc->width) || !read_dword(hkey, "Height", &desc->height) || !read_dword(hkey, "RefreshRateTimes100", &refresh100) || !read_dword(hkey, "IOFlags", &desc->io_flags)) goto done; if (refresh100) desc->refresh = refresh100 / 100.0; else desc->refresh = 60; if (!read_dword(hkey, "PixelWidth", &desc->pixel_width) || !read_dword(hkey, "PixelHeight", &desc->pixel_height)) { desc->pixel_width = desc->width; desc->pixel_height = desc->height; } size = 0; if (RegQueryValueExW(hkey, pixelencodingW, 0, &type, NULL, &size) || type != REG_SZ) goto done; pixel_encoding = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); if (RegQueryValueExW(hkey, pixelencodingW, 0, &type, (BYTE*)pixel_encoding, &size) || type != REG_SZ) goto done; if ((end = memchrW(pixel_encoding, 0, size))) size = end - pixel_encoding; desc->pixel_encoding = CFStringCreateWithCharacters(NULL, (const UniChar*)pixel_encoding, size); ret = desc; done: if (!ret) free_display_mode_descriptor(desc); HeapFree(GetProcessHeap(), 0, pixel_encoding); RegCloseKey(hkey); return ret; }
void infoDisplays(void) { CGDisplayErr dErr; CGDisplayCount displayCount, i; CGDirectDisplayID mainDisplay; CGDisplayCount maxDisplays = MAX_DISPLAYS; CGDirectDisplayID onlineDisplays[MAX_DISPLAYS]; CGEventRef ourEvent = CGEventCreate(NULL); CGPoint ourLoc = CGEventGetLocation(ourEvent); CFRelease(ourEvent); mainDisplay = CGMainDisplayID(); dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount); if (dErr != kCGErrorSuccess) { fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr); exit(1); } printf("# Display_ID Resolution ____Display_Bounds____ Rotation\n"); for (i = 0; i < displayCount; i++) { CGDirectDisplayID dID = onlineDisplays[i]; printf("%-2d %10p %4lux%-4lu %5.0f %5.0f %5.0f %5.0f %3.0f %s%s%s", CGDisplayUnitNumber (dID), dID, CGDisplayPixelsWide(dID), CGDisplayPixelsHigh(dID), CGRectGetMinX (CGDisplayBounds (dID)), CGRectGetMinY (CGDisplayBounds (dID)), CGRectGetMaxX (CGDisplayBounds (dID)), CGRectGetMaxY (CGDisplayBounds (dID)), CGDisplayRotation (dID), (CGDisplayIsActive (dID)) ? "" : "[inactive]", (dID == mainDisplay) ? "[main]" : "", (CGDisplayIsBuiltin (dID)) ? "[internal]\n" : "\n"); } printf("Mouse Cursor Position: ( %5.0f , %5.0f )\n", (float)ourLoc.x, (float)ourLoc.y); exit(0); }
static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID) { BOOL ret = FALSE; char display_key_name[19]; HKEY display_hkey; CGDisplayModeRef display_mode; DWORD val; CFStringRef pixel_encoding; size_t len; WCHAR* buf = NULL; snprintf(display_key_name, sizeof(display_key_name), "Display 0x%08x", CGDisplayUnitNumber(displayID)); /* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode\Display 0xnnnnnnnn */ if (RegCreateKeyExA(parent_hkey, display_key_name, 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &display_hkey, NULL)) return FALSE; display_mode = CGDisplayCopyDisplayMode(displayID); if (!display_mode) goto fail; val = CGDisplayModeGetWidth(display_mode); if (RegSetValueExA(display_hkey, "Width", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; val = CGDisplayModeGetHeight(display_mode); if (RegSetValueExA(display_hkey, "Height", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; val = CGDisplayModeGetRefreshRate(display_mode) * 100; if (RegSetValueExA(display_hkey, "RefreshRateTimes100", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; val = CGDisplayModeGetIOFlags(display_mode); if (RegSetValueExA(display_hkey, "IOFlags", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; #if defined(MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 if (CGDisplayModeGetPixelWidth != NULL && CGDisplayModeGetPixelHeight != NULL) { val = CGDisplayModeGetPixelWidth(display_mode); if (RegSetValueExA(display_hkey, "PixelWidth", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; val = CGDisplayModeGetPixelHeight(display_mode); if (RegSetValueExA(display_hkey, "PixelHeight", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) goto fail; } #endif pixel_encoding = CGDisplayModeCopyPixelEncoding(display_mode); len = CFStringGetLength(pixel_encoding); buf = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); CFStringGetCharacters(pixel_encoding, CFRangeMake(0, len), (UniChar*)buf); buf[len] = 0; CFRelease(pixel_encoding); if (RegSetValueExW(display_hkey, pixelencodingW, 0, REG_SZ, (const BYTE*)buf, (len + 1) * sizeof(WCHAR))) goto fail; ret = TRUE; fail: HeapFree(GetProcessHeap(), 0, buf); if (display_mode) CGDisplayModeRelease(display_mode); RegCloseKey(display_hkey); if (!ret) RegDeleteKeyA(parent_hkey, display_key_name); return ret; }