Example #1
0
        public sealed override bool TryRestoreResolution(DisplayDevice device)
        {
            IntPtr display = HandleTo(device);

            if (storedModes.ContainsKey(display))
            {
                Debug.Print("Restoring resolution.");

                CG.DisplaySwitchToMode(display, storedModes[display]);
                //CG.DisplayRelease(display);
                displaysCaptured.Remove(display);

                return(true);
            }

            return(false);
        }
Example #2
0
        public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            IntPtr display        = HandleTo(device);
            IntPtr currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);
            }

            IntPtr  displayModesPtr = CG.DisplayAvailableModes(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 && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
//                    if (displaysCaptured.Contains(display) == false)
//                    {
//                        CG.DisplayCapture(display);
//                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return(true);
                }
            }
            return(false);
        }