예제 #1
0
        private void SetAutoBrightness(int Mode)
        {
            TimeSpan CurrentTime        = DateTime.UtcNow.TimeOfDay;
            TimeSpan TrimmedCurrentTime = new TimeSpan(CurrentTime.Hours, CurrentTime.Minutes, 0);

            SunrisetTools RisetTools = new SunrisetTools(AutoBrightnessSettings.GetLat(), AutoBrightnessSettings.GetLon());

            foreach (MONITOR mon in MonitorList)
            {
                if (TimeSpan.Compare(TrimmedCurrentTime, RisetTools.GetTodaySunrise()) == Mode)
                {
                    try { DisplayConfiguration.SetMonitorBrightness(mon.Handle, AutoBrightnessSettings.GetSunriseBrightness(), mon.Min, mon.Max); }
                    catch { }
                }
                else if (TimeSpan.Compare(TrimmedCurrentTime, RisetTools.GetTodaySunset()) == Mode)
                {
                    try { DisplayConfiguration.SetMonitorBrightness(mon.Handle, AutoBrightnessSettings.GetSunsetBrightness(), mon.Min, mon.Max); }
                    catch { }
                }
                else if (TimeSpan.Compare(TrimmedCurrentTime, RisetTools.GetTodayDawn()) == Mode)
                {
                    try { DisplayConfiguration.SetMonitorBrightness(mon.Handle, AutoBrightnessSettings.GetAstroSunriseBrightness(), mon.Min, mon.Max); }
                    catch { }
                }
                else if (TimeSpan.Compare(TrimmedCurrentTime, RisetTools.GetTodayDusk()) == Mode)
                {
                    try { DisplayConfiguration.SetMonitorBrightness(mon.Handle, AutoBrightnessSettings.GetAstroSunsetBrightness(), mon.Min, mon.Max); }
                    catch { }
                }
            }
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateMonitorList();
            SetWindowPosition();
            Show();
            Activate();
            Set_Initial_Brightness();
            AfterUpdateCheck();

            IniData data = SettingsController.GetCurrentSettings();

            DisplayConfiguration.PHYSICAL_MONITOR Handle = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetCurrentMonitor())[0];

            try
            {
                DisplayConfiguration.MonitorExtremums MonExtems = DisplayConfiguration.GetMonitorExtremums(Handle);
                double CurrentBrightness = (double)(MonExtems.Current - MonExtems.Min) / (double)(MonExtems.Max - MonExtems.Min);
                HotkeyPopupWindow.dwMinimumBrightness = MonExtems.Min;
                HotkeyPopupWindow.dwMaximumBrightness = MonExtems.Max;
                HotkeyPopupWindow.dwCurrentBrightness = MonExtems.Current;
                HotkeyPopupWindow.PercentText.Text    = (CurrentBrightness * 100).ToString();
            } catch { }
            HotkeyPopupWindow.Show();
            HotkeyPopupWindow.ShowMe(data["Misc"]["HotkeyPopupPosition"]);
        }
예제 #3
0
        private void BrightnessHotkeyEvent(bool IsUp)
        {
            (FindResource("hideMe") as Storyboard).Begin(this);

            IniData data = SettingsController.GetCurrentSettings();

            int StepSize = 5;

            if (int.TryParse(data["Hotkeys"]["StepSize"], out int StepSizeValue))
            {
                StepSize = StepSizeValue;
            }

            try
            {
                double StepDouble = (double)StepSize / 100;

                DisplayConfiguration.PHYSICAL_MONITOR Handle = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetCurrentMonitor())[0];
                /*Task.Run(() => { try { DisplayConfiguration.SetBrightnessOffset(Handle, IsUp ? StepDouble : -StepDouble); } catch { } });*/

                if (HotkeyPopupWindow.IsVisible)
                {
                    int HotkeyPopupBrightness = int.Parse(HotkeyPopupWindow.PercentText.Text);
                    int NewBrightness         = HotkeyPopupBrightness + (IsUp ? StepSize : -StepSize);

                    if (NewBrightness > 100)
                    {
                        NewBrightness = 100;
                    }
                    else if (NewBrightness < 0)
                    {
                        NewBrightness = 0;
                    }

                    Task.Run(() => { try { DisplayConfiguration.SetMonitorBrightness(Handle, (double)NewBrightness / 100, HotkeyPopupWindow.dwMinimumBrightness, HotkeyPopupWindow.dwMaximumBrightness); } catch { } });

                    HotkeyPopupWindow.PercentText.Text = NewBrightness.ToString();
                    HotkeyPopupWindow.ShowMe(data["Misc"]["HotkeyPopupPosition"]);
                }
                else
                {
                    DisplayConfiguration.MonitorExtremums MonExtems = DisplayConfiguration.GetMonitorExtremums(Handle);
                    double CurrentBrightness = (double)(MonExtems.Current - MonExtems.Min) / (double)(MonExtems.Max - MonExtems.Min);
                    Task.Run(() => { try { DisplayConfiguration.SetBrightnessOffset(Handle, IsUp ? StepDouble : -StepDouble, CurrentBrightness, MonExtems.Min, MonExtems.Max); } catch { } });
                    HotkeyPopupWindow.dwMinimumBrightness = MonExtems.Min;
                    HotkeyPopupWindow.dwMaximumBrightness = MonExtems.Max;
                    HotkeyPopupWindow.dwCurrentBrightness = MonExtems.Current;
                    HotkeyPopupWindow.PercentText.Text    = ((CurrentBrightness * 100) + (IsUp ? StepSize : -StepSize)).ToString();
                    HotkeyPopupWindow.ShowMe(data["Misc"]["HotkeyPopupPosition"]);
                }
            }
            catch { }
        }
예제 #4
0
        private void Slider_Brightness_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            PercentText.Text = Convert.ToInt32(((Slider)sender).Value).ToString();

            debounceTimer.Throttle(15, (p) =>
            {
                try
                {
                    DisplayConfiguration.PHYSICAL_MONITOR Handle = CurrentMonitor.Handle;
                    uint Min     = CurrentMonitor.Min;
                    uint Max     = CurrentMonitor.Max;
                    double Value = ((Slider)sender).Value / 100;
                    Task.Run(() => DisplayConfiguration.SetMonitorBrightness(Handle, Value, Min, Max));
                }
                catch { }
            });
        }
예제 #5
0
        private void Set_Initial_Brightness()
        {
            double Brightness = 0;

            try
            {
                Brightness = DisplayConfiguration.GetMonitorBrightness(CurrentMonitor.Handle) * 100;

                Slider_Brightness.IsEnabled = true;
                Main_Grid.ToolTip           = null;
            }
            catch
            {
                Slider_Brightness.IsEnabled = false;
                Main_Grid.ToolTip           = "This monitor is not supported. You may need to enable «DDC/CI» option in your monitor settings.";
            }

            Slider_Brightness.Value = Brightness;
            PercentText.Text        = Brightness.ToString();
        }
예제 #6
0
        private void UpdateMonitorList()
        {
            MonitorList.Clear();

            foreach (Screen screen in Screen.AllScreens)
            {
                DisplayConfiguration.PHYSICAL_MONITOR mon = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetMonitorByBounds(screen.Bounds))[0];

                string Name = screen.DeviceFriendlyName();

                if (String.IsNullOrEmpty(Name))
                {
                    Name = "Generic Monitor";
                }

                DisplayConfiguration.MonitorExtremums MonExtrs;

                try
                {
                    MonExtrs = DisplayConfiguration.GetMonitorExtremums(mon);
                }
                catch
                {
                    MonExtrs = new DisplayConfiguration.MonitorExtremums()
                    {
                        Min = 0, Max = 0
                    };
                }

                MonitorList.Add(new MONITOR(Name, mon, MonExtrs.Min, MonExtrs.Max));
            }

            Monitor_List_Combobox.ItemsSource  = MonitorList;
            Monitor_List_Combobox.SelectedItem = MonitorList[0];
            CurrentMonitor = MonitorList[0];
        }