private void iTrackBarContrast_Scroll(object sender, EventArgs e)
        {
            // Set contrast
            Setting         contrast = new Setting((uint)iTrackBarContrast.Minimum, (uint)iTrackBarContrast.Value, (uint)iTrackBarContrast.Maximum);
            PhysicalMonitor pm       = CurrentPhysicalMonitor();

            pm.Contrast = contrast;
        }
        private void iTrackBarBrightness_Scroll(object sender, EventArgs e)
        {
            // Set brighness
            Setting         brightness = new Setting((uint)iTrackBarBrightness.Minimum, (uint)iTrackBarBrightness.Value, (uint)iTrackBarBrightness.Maximum);
            PhysicalMonitor pm         = CurrentPhysicalMonitor();

            pm.Brightness = brightness;
        }
        private void iTrackBarDriveGreen_Scroll(object sender, EventArgs e)
        {
            // Set Drive green
            Setting         green = new Setting((uint)iTrackBarDriveGreen.Minimum, (uint)iTrackBarDriveGreen.Value, (uint)iTrackBarDriveGreen.Maximum);
            PhysicalMonitor pm    = CurrentPhysicalMonitor();

            pm.DriveGreen = green;
        }
        private void iTrackBarDriveRed_Scroll(object sender, EventArgs e)
        {
            // Set Drive red
            Setting         red = new Setting((uint)iTrackBarDriveRed.Minimum, (uint)iTrackBarDriveRed.Value, (uint)iTrackBarDriveRed.Maximum);
            PhysicalMonitor pm  = CurrentPhysicalMonitor();

            pm.DriveRed = red;
        }
        private void iTrackBarGainBlue_Scroll(object sender, EventArgs e)
        {
            // Set gain red
            Setting         blue = new Setting((uint)iTrackBarGainBlue.Minimum, (uint)iTrackBarGainBlue.Value, (uint)iTrackBarGainBlue.Maximum);
            PhysicalMonitor pm   = CurrentPhysicalMonitor();

            pm.GainBlue = blue;
            UpdateColorTemperature();
        }
        private void iTrackBarGainGreen_Scroll(object sender, EventArgs e)
        {
            // Set gain green
            Setting         green = new Setting((uint)iTrackBarGainGreen.Minimum, (uint)iTrackBarGainGreen.Value, (uint)iTrackBarGainGreen.Maximum);
            PhysicalMonitor pm    = CurrentPhysicalMonitor();

            pm.GainGreen = green;
            UpdateColorTemperature();
        }
Esempio n. 7
0
        public static uint GetMonitorMinBrightness(PhysicalMonitor monitor)
        {
            uint max = 0, c = 0, min = 0;

            uint[] m = null, mi = null, cc = null;
            BrightnessInterop.GetMonitorBrightness(
                monitor.hPhysicalMonitor, m, cc, mi);
            return(min);
        }
        private void iComboBoxColorTemperature_SelectionChangeCommitted(object sender, EventArgs e)
        {
            PhysicalMonitor pm = CurrentPhysicalMonitor();

            pm.ColorTemperature = (ColorTemperature)iComboBoxColorTemperature.SelectedItem;
            WaitForPhysicalMonitorToComeBackOnline(); // Dell U2413 was being too slow again
            // We will need to fetch the new color settings
            // In fact changing color temperature often just changes color gain to some predefined value
            UpdatePhysicalMonitor();
        }
        private void iButtonColorReset_Click(object sender, EventArgs e)
        {
            // Initiate reset
            PhysicalMonitor pm = CurrentPhysicalMonitor();

            pm.RestoreFactoryColorDefault();
            WaitForPhysicalMonitorToComeBackOnline();
            // Update our UI
            UpdatePhysicalMonitor();
        }
        private void iTrackBarDriveBlue_Scroll(object sender, EventArgs e)
        {
            // Set Drive red
            Setting         blue = new Setting((uint)iTrackBarDriveBlue.Minimum, (uint)iTrackBarDriveBlue.Value, (uint)iTrackBarDriveBlue.Maximum);
            PhysicalMonitor pm   = CurrentPhysicalMonitor();

            pm.DriveBlue = blue;
            // On DELL U2413 any Drive component actually changes the contrast
            UpdatePhysicalMonitor();
        }
        /// <summary>
        ///
        /// </summary>
        private void UpdateColorTemperature()
        {
            // Color temperature
            PhysicalMonitor pm = CurrentPhysicalMonitor();

            PopulateColorTemperature();
            // We don't enforce disabling color temperature as notably Dell P2312H supports it but pretends it does not.
            iComboBoxColorTemperature.Enabled      = iCheckBoxColorTemperatureUnlock.Checked || pm.SupportsColorTemperature;
            iComboBoxColorTemperature.SelectedItem = pm.ColorTemperature;
        }
Esempio n. 12
0
        public static void SetMonitorBrightness(PhysicalMonitor physicalMonitor, float percentage)
        {
            GetMonitorBrightness(physicalMonitor.MonitorHandle, out _, out _, out var maximumBrightness);
            var newBrightness = (short)(percentage * maximumBrightness);

            if (Program.Verbosity > 0)
            {
                Console.WriteLine($"setting brightness of {physicalMonitor.MonitorHandle.ToString("X")} to {(newBrightness/100f):P}");
            }

            SetMonitorBrightness(physicalMonitor.MonitorHandle, newBrightness);
        }
        /// <summary>
        ///
        /// </summary>
        private void WaitForPhysicalMonitorToComeBackOnline()
        {
            PhysicalMonitor pm = CurrentPhysicalMonitor();
            // Wait for the monitor to come back online
            int max = 40;

            while (!pm.Construct() && max >= 0)
            {
                max--;
                Thread.Sleep(250); // Added that delay as Dell P2312H is not responsive immediately after reset
            }
        }
Esempio n. 14
0
        public static PhysicalMonitor[] GetPhysicalMonitors()
        {
            uint   monitorCounts = uint.MinValue;
            IntPtr hWnd          = Process.GetCurrentProcess().MainWindowHandle;
            IntPtr hMonitor      = MonitorInterop.MonitorFromWindow(hWnd, (uint)NativeConstantsEnum.MonitorDefaultToPrimary);
            bool   r             = BrightnessInterop.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref monitorCounts);

            PhysicalMonitor[] monitors = new PhysicalMonitor[monitorCounts];

            BrightnessInterop.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCounts, monitors);
            for (int i = 0; i < monitors.Length; i++)
            {
                monitors[i].hPhysicalMonitor = hMonitor;
            }
            return(monitors);
        }
Esempio n. 15
0
        private static bool MonitorCallback(IntPtr hMonitor, IntPtr hdcMonitor, IntPtr lpRectMonitor, IntPtr dwData)
        {
            var monitors = (List <Monitor>)GCHandle.FromIntPtr(dwData).Target;

            uint numberOfMonitors = 0;

            if (GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref numberOfMonitors))
            {
                var phisicalMonitors = new PhysicalMonitor[numberOfMonitors];
                if (GetPhysicalMonitorsFromHMONITOR(hMonitor, numberOfMonitors, phisicalMonitors))
                {
                    for (int i = 0; i < numberOfMonitors; i++)
                    {
                        monitors.Add(new Monitor(phisicalMonitors[i]));
                    }
                }
            }

            return(true);
        }
Esempio n. 16
0
        public static IReadOnlyList <PhysicalMonitor> GetPhysicalMonitors()
        {
            var physicalMonitors = new List <PhysicalMonitor>();

            bool EnumMonitorsCallback(IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data)
            {
                GetNumberOfPhysicalMonitorsFromHMonitor(monitor, out var numberOfMonitors);

                var innerPhysicalMonitors = new PhysicalMonitor[numberOfMonitors];

                GetPhysicalMonitorsFromHMonitor(monitor, numberOfMonitors, innerPhysicalMonitors);

                physicalMonitors.AddRange(innerPhysicalMonitors);
                return(true);
            }

            EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, EnumMonitorsCallback, IntPtr.Zero);

            return(physicalMonitors.AsReadOnly());
        }
        /// <summary>
        /// Update control according to currently selected physical monitor.
        /// </summary>
        private void UpdatePhysicalMonitor()
        {
            // Get our physical monitor
            PhysicalMonitor pm = CurrentPhysicalMonitor();

            // Reset buttons
            iButtonFactoryReset.Enabled = pm.SupportsRestoreFactoryDefaults;
            iButtonColorReset.Enabled   = pm.SupportsRestoreFactoryColorDefaults;

            // Monitor Technology Type
            iLabelMonitorTech.Visible = pm.SupportsTechnologyType;
            iLabelMonitorTech.Text    = pm.TechnologyTypeName;

            // Brightness update
            iTrackBarBrightness.Enabled             =
                iLabelBrightness.Enabled            =
                    iLabelBrightnessPercent.Visible = pm.SupportsBrightness;
            SetupTrackBar(iTrackBarBrightness, pm.Brightness);

            // Contrast update
            iTrackBarContrast.Enabled             =
                iLabelContrast.Enabled            =
                    iLabelContrastPercent.Visible = pm.SupportsContrast;
            SetupTrackBar(iTrackBarContrast, pm.Contrast);

            // Color temperature
            UpdateColorTemperature();

            // Gain
            iGroupBoxGain.Enabled = pm.SupportsRgbGain;
            SetupTrackBar(iTrackBarGainRed, pm.GainRed);
            SetupTrackBar(iTrackBarGainGreen, pm.GainGreen);
            SetupTrackBar(iTrackBarGainBlue, pm.GainBlue);

            // Drive
            iGroupBoxDrive.Enabled = pm.SupportsRgbDrive;
            SetupTrackBar(iTrackBarDriveRed, pm.DriveRed);
            SetupTrackBar(iTrackBarDriveGreen, pm.DriveGreen);
            SetupTrackBar(iTrackBarDriveBlue, pm.DriveBlue);
        }
Esempio n. 18
0
        public static IReadOnlyList <PhysicalMonitor> GetPhysicalMonitors()
        {
            var physMonitors = new HashSet <PhysicalMonitor>();
            var gcHandle     = GCHandle.Alloc(physMonitors, GCHandleType.Normal);

            try
            {
                var ptrHandle = GCHandle.ToIntPtr(gcHandle);

                if (NativeMethods.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, MonitorEnum, ptrHandle))
                {
                    var result = new PhysicalMonitor[physMonitors.Count];
                    physMonitors.CopyTo(result);
                    return(result);
                }

                return(Array.Empty <PhysicalMonitor>());
            }
            finally
            {
                gcHandle.Free();
            }
        }
Esempio n. 19
0
 public MonitorViewModel(PhysicalMonitor monitor, IMonitorService monitorService)
 {
     _monitor          = monitor;
     _monitorService   = monitorService;
     _cachedBrightness = (int)_monitorService.GetMonitorBrightness(MonitorPtr);
 }
Esempio n. 20
0
 protected override bool Supported(PhysicalMonitor aPhysicalMonitor)
 {
     return(aPhysicalMonitor.SupportsContrast);
 }
Esempio n. 21
0
 /// <summary>
 /// Tell if a monitor support that feature
 /// </summary>
 /// <param name="aPhysicalMonitor"></param>
 /// <returns></returns>
 protected abstract bool Supported(PhysicalMonitor aPhysicalMonitor);
Esempio n. 22
0
 protected override bool Supported(PhysicalMonitor aPhysicalMonitor)
 {
     return(aPhysicalMonitor.SupportsBrightness);
 }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private PhysicalMonitor CurrentPhysicalMonitor()
        {
            PhysicalMonitor pm = CurrentVirtualMonitor().PhysicalMonitors[iComboBoxPhysicalMonitors.SelectedIndex];

            return(pm);
        }
Esempio n. 24
0
 internal Monitor(PhysicalMonitor physicalMonitor)
 {
     _monitorHandle = physicalMonitor;
 }
        /// <summary>
        ///
        /// </summary>
        private void PopulateColorTemperature()
        {
            //
            iComboBoxColorTemperature.Items.Clear();
            //
            if (iCheckBoxColorTemperatureUnlock.Checked)
            {
                // Unlock mode provides all choices
                // This was designed to be able to test Dell monitors not reporting capabilities properly
                foreach (ColorTemperature t in Enum.GetValues(typeof(ColorTemperature)))
                {
                    iComboBoxColorTemperature.Items.Add(t);
                }

                return;
            }

            PhysicalMonitor  pm      = CurrentPhysicalMonitor();
            ColorTemperature current = pm.ColorTemperature;

            //
            iComboBoxColorTemperature.Items.Add(ColorTemperature.Unknown);

            // Add supported color temperature to our combo box
            // For those Dell monitors not reporting supported color temperature we added the current check
            // That makes sure the current profile is in the combo box

            if (pm.SupportsColorTemperature4000K || current == ColorTemperature.K4000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K4000);
            }

            if (pm.SupportsColorTemperature5000K || current == ColorTemperature.K5000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K5000);
            }

            if (pm.SupportsColorTemperature6500K || current == ColorTemperature.K6500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K6500);
            }

            if (pm.SupportsColorTemperature7500K || current == ColorTemperature.K7500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K7500);
            }

            if (pm.SupportsColorTemperature8200K || current == ColorTemperature.K8200)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K8200);
            }

            if (pm.SupportsColorTemperature9300K || current == ColorTemperature.K9300)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K9300);
            }

            if (pm.SupportsColorTemperature10000K || current == ColorTemperature.K10000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K10000);
            }

            if (pm.SupportsColorTemperature11500K || current == ColorTemperature.K11500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K11500);
            }
        }