Example #1
0
        private void RefreshBrightness()
        {
            foreach (DisplayConfiguration.PHYSICAL_MONITOR physicalMonitor in physicalMonitors)
            {
                try
                {
                    double newBrightness = brightnessSlider.Value;
                    if (newBrightness >= 0 && newBrightness < 25)
                    {
                        variationPos = 0;
                    }
                    else
                    if (newBrightness >= 25 && newBrightness < 50)
                    {
                        variationPos = 1;
                    }
                    else
                    if (newBrightness >= 50 && newBrightness < 75)
                    {
                        variationPos = 2;
                    }
                    else
                    if (newBrightness >= 75 && newBrightness < 100)
                    {
                        variationPos = 3;
                    }
                    else
                    {
                        variationPos = 4;
                    }
                    brightnessToggler.Content = newBrightness + "%";

                    DisplayConfiguration.SetMonitorBrightness(physicalMonitor, newBrightness / brightnessSlider.Maximum);
                }
                catch (Win32Exception e_)
                {
                    // LG Flatron W2443T sometimes causes ERROR_GEN_FAILURE when rapidly changing brightness or contrast
                    if (e_.NativeErrorCode == ERROR_GEN_FAILURE)
                    {
                        Debug.WriteLine("ERROR_GEN_FAILURE while setting brightness, rescheduling");
                        brightnessTimeout = new DispatcherTimeout(RefreshBrightness, CHANGE_DELAY);
                        break;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Example #2
0
 private void RefreshBrightness()
 {
     foreach (DisplayConfiguration.PHYSICAL_MONITOR physicalMonitor in physicalMonitors)
     {
         try
         {
             DisplayConfiguration.SetMonitorBrightness(physicalMonitor, brightnessSlider.Value / brightnessSlider.Maximum);
         }
         catch (Win32Exception e)
         {
             // The monitor configuration API tends to throw errors randomly, so we log and ignore them
             Debug.WriteLine(string.Format("Windows API threw an error when changing brightness (0x{0:X}): {1}", e.NativeErrorCode, e.Message));
             brightnessTimeout = new DispatcherTimeout(RefreshBrightness, CHANGE_DELAY);
         }
     }
 }
Example #3
0
 private void RefreshBrightness()
 {
     foreach (DisplayConfiguration.PHYSICAL_MONITOR physicalMonitor in physicalMonitors)
     {
         try
         {
             DisplayConfiguration.SetMonitorBrightness(physicalMonitor, brightnessSlider.Value / brightnessSlider.Maximum);
         }
         catch (Win32Exception e_)
         {
             // LG Flatron W2443T sometimes causes ERROR_GEN_FAILURE when rapidly changing brightness or contrast
             if (e_.NativeErrorCode == ERROR_GEN_FAILURE)
             {
                 Debug.WriteLine("ERROR_GEN_FAILURE while setting brightness, rescheduling");
                 brightnessTimeout = new DispatcherTimeout(RefreshBrightness, CHANGE_DELAY);
                 break;
             }
             else
             {
                 throw;
             }
         }
     }
 }