Ejemplo n.º 1
0
 private void ScheduleHiding()
 {
     if (hideTimeout != null)
     {
         hideTimeout.Cancel();
     }
     hideTimeout = new DispatcherTimeout(() => Visibility = Visibility.Hidden, HIDING_DELAY);
 }
Ejemplo n.º 2
0
 private void brightnessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
 {
     if (brightnessTimeout != null)
     {
         brightnessTimeout.Cancel();
     }
     brightnessTimeout = new DispatcherTimeout(RefreshBrightness, CHANGE_DELAY);
     ScheduleHiding();
 }
Ejemplo n.º 3
0
 private void ScheduleHiding()
 {
     hideStoryboard.Stop(this);
     if (hideTimeout != null)
     {
         hideTimeout.Cancel();
     }
     hideTimeout = new DispatcherTimeout(() => hideStoryboard.Begin(this, true), HIDING_DELAY);
 }
Ejemplo n.º 4
0
 private void contrastSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (contrastTimeout != null)
     {
         contrastTimeout.Cancel();
     }
     contrastTimeout = new DispatcherTimeout(RefreshContrast, CHANGE_DELAY);
     ScheduleHiding();
 }
Ejemplo n.º 5
0
 private void brightnessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (brightnessTimeout != null)
     {
         brightnessTimeout.Cancel();
     }
     brightnessTimeout = new DispatcherTimeout(RefreshBrightness, CHANGE_DELAY);
     ScheduleHiding();
 }
Ejemplo n.º 6
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;
                    }
                }
            }
        }
Ejemplo n.º 7
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);
         }
     }
 }
Ejemplo n.º 8
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;
             }
         }
     }
 }
Ejemplo n.º 9
0
 private void contrastSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
 {
     if (contrastTimeout != null)
     {
         contrastTimeout.Cancel();
     }
     contrastTimeout = new DispatcherTimeout(RefreshContrast, CHANGE_DELAY);
     ScheduleHiding();
 }
Ejemplo n.º 10
0
 private void ScheduleHiding()
 {
     hideStoryboard.Stop(this);
     if (hideTimeout != null)
     {
         hideTimeout.Cancel();
     }
     hideTimeout = new DispatcherTimeout(() => hideStoryboard.Begin(this, true), HIDING_DELAY);
 }
Ejemplo n.º 11
0
 private void RefreshContrast()
 {
     foreach (DisplayConfiguration.PHYSICAL_MONITOR physicalMonitor in physicalMonitors)
     {
         try
         {
             DisplayConfiguration.SetMonitorContrast(physicalMonitor, contrastSlider.Value / contrastSlider.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 contrast, rescheduling");
                 contrastTimeout = new DispatcherTimeout(RefreshContrast, CHANGE_DELAY);
                 break;
             }
             else
             {
                 throw;
             }
         }
     }
 }