/// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { InitializeComponent(); // initialise flags isKeyDown = false; MouseClickToHideNotifyIcon = false; PreferenceEventHandler = null; PreferenceEvent = null; // set up listener for brightness changed events eventWatcher = new EventWatcherAsync(); eventWatcher.BrightnessChanged += EventWatcher_BrightnessChanged; CreateNotifyIcon(); this.Visibility = Visibility.Hidden; if (!Config.showPercentageText) { percentageLabel.Visibility = Visibility.Collapsed; } }
/// <summary> /// Update the slider due to a brightness changed event. /// </summary> private void EventWatcher_BrightnessChanged(object sender, EventWatcherAsync.BrightnessChangedEventArgs e) { NotifyIcon.Text = "Brightness " + e.newBrightness.ToString() + "%"; // Only update the slider if the event was generated from an external source // - and NOT caused by BrightnessTray. // This helps keep the slider free of being jerky when the user is moving it. // e.g. ignore if the user is dragging the slider, or using the scroll wheel on the slider, or up/down keys on the slider. // needs to be IsMouseOver for entire form in case of scroll wheel. if (!IsMouseOver && !isKeyDown) { this.Dispatcher.BeginInvoke((Action)(() => { int value = int.Parse(e.newBrightness.ToString()); // 0 <= value <= 100 this.BrightnessSlider.Value = value; this.percentageLabel.Content = value.ToString() + "%"; DrawIcon.updateNotifyIcon(NotifyIcon, value); })); } }