public bool TryRestoreResolution(DisplayDevice device) { IntPtr display = displayMap[device]; if (storedModes.ContainsKey(display)) { Debug.Print("Restoring resolution."); CG.CGDisplaySwitchToMode(display, storedModes[display]); CG.CGDisplayRelease(display); displaysCaptured.Remove(display); return(true); } return(false); }
public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) { IntPtr display = displayMap[device]; IntPtr currentModePtr = CG.CGDisplayCurrentMode(display); if (!storedModes.ContainsKey(display)) { storedModes.Add(display, currentModePtr); } IntPtr displayModesPtr = CG.CGDisplayAvailableModes(display); CFArray displayModes = new CFArray(displayModesPtr); for (int j = 0; j < displayModes.Count; j++) { CFDictionary dict = new CFDictionary(displayModes[j]); int width = (int)dict.GetNumberValue("Width"); int height = (int)dict.GetNumberValue("Height"); int bpp = (int)dict.GetNumberValue("BitsPerPixel"); double freq = dict.GetNumberValue("RefreshRate"); if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && Math.Abs(freq - resolution.RefreshRate) < 1e-6) { if (!displaysCaptured.Contains(display)) { CG.CGDisplayCapture(display); } Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq); CG.CGDisplaySwitchToMode(display, displayModes[j]); return(true); } } return(false); }