forked from navhaxs/BrightnessTray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
664 lines (550 loc) · 26.8 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
/*
This file is part of BrightnessTray.
BrightnessTray is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BrightnessTray is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BrightnessTray. If not, see <http://www.gnu.org/licenses/>.
*/
namespace BrightnessTray
{
using System;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using Microsoft.Win32;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <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 BrightnessWatcher();
eventWatcher.BrightnessChanged += EventWatcher_BrightnessChanged;
// set up Windows10 1903 taskbar theme change events
// TODO: Attach only if windows version matches
registryWatcher = new RegistryWatcher();
registryWatcher.OnUpdateStatus += RegistryWatcher_OnUpdateStatus;
CreateNotifyIcon();
this.Visibility = Visibility.Hidden;
if (!Config.showPercentageText)
{
percentageLabel.Visibility = Visibility.Collapsed;
}
}
private void RegistryWatcher_OnUpdateStatus(object sender, string e)
{
DrawIcon.updateNotifyIcon(NotifyIcon, WmiFunctions.GetBrightnessLevel());
}
/// <summary>
/// Update the slider due to a brightness changed event.
/// </summary>
private void EventWatcher_BrightnessChanged(object sender, BrightnessWatcher.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)
{
UpdateUI(int.Parse(e.newBrightness.ToString()));
}
}
private void UpdateUI(int brightnessValue)
{
this.Dispatcher.BeginInvoke((Action)(() =>
{
// 0 <= value <= 100
ignoreValueChanged = true;
this.BrightnessSlider.Value = brightnessValue;
ignoreValueChanged = false;
this.percentageLabel.Content = brightnessValue.ToString() + "%";
DrawIcon.updateNotifyIcon(NotifyIcon, brightnessValue);
}));
}
/// <summary>
/// Is the keyboard being pressed?
/// </summary>
bool isKeyDown;
/// <summary>
/// Listener to backlight change events from WMI.
/// </summary>
BrightnessWatcher eventWatcher;
/// <summary>
/// Listener to backlight change events from WMI.
/// </summary>
RegistryWatcher registryWatcher;
/// <summary>
/// Delegate for handling user preference changes (namely desktop preference changes).
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the SystemEvents class, this object is always null.</param>
/// <param name="e">A UserPreferenceChangedEventArgs that contains the event data.</param>
private delegate void UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e);
/// <summary>
/// User preferences changed event handler. Set when the window is made visible and unset when the window is hidden.
/// </summary>
private event UserPreferenceChanged PreferenceEvent;
/// <summary>
/// Gets or sets a handler for user preference changes.
/// </summary>
private UserPreferenceChangedEventHandler PreferenceEventHandler { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not we are currently blocking sleep mode 'Caffeine'.
/// </summary>
private bool CaffeineEnabled { get; set; }
/// <summary>
/// Gets or sets the window's notify icon.
/// </summary>
private System.Windows.Forms.NotifyIcon NotifyIcon { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user hid the window by clicking the notify icon a second time.
/// </summary>
private bool MouseClickToHideNotifyIcon { get; set; }
/// <summary>
/// Gets or sets a value indicating the location of the cursor when the window was last hidden by clicking the notify icon a second time.
/// </summary>
private Point MouseClickToHideNotifyIconPoint { get; set; }
/// <summary>
/// The text label in the application's tray icon context menu.
/// </summary>
private System.Windows.Forms.MenuItem mnuLabel;
/// <summary>
/// The autostart menu item (exists as a local variable so that the checked state can be toggled).
/// </summary>
private System.Windows.Forms.MenuItem mnuAutostart;
/// <summary>
/// Don't trigger a WMI brightness change action, if the value update itself was *from* WMI
/// </summary>
private bool ignoreValueChanged = false;
/// <summary>
/// Updates the display (position and appearance) of the window if it is currently visible.
/// </summary>
/// <param name="activatewindow">True if the window should be activated, false if not.</param>
public void UpdateWindowDisplayIfOpen(bool activatewindow)
{
if (this.Visibility == Visibility.Visible)
this.UpdateWindowDisplay(activatewindow);
}
/// <summary>
/// Updates the display (position and appearance) of the window.
/// </summary>
/// <param name="activatewindow">True if the window should be activated, false if not.</param>
public void UpdateWindowDisplay(bool activatewindow)
{
if (this.IsLoaded)
{
// set handlers if necessary
this.SetHandlers();
// get the handle of the window
HwndSource windowhandlesource = PresentationSource.FromVisual(this) as HwndSource;
bool glassenabled = Compatibility.IsDWMEnabled;
//// update location
Rect windowbounds = (glassenabled ? WindowPositioning.GetWindowSize(windowhandlesource.Handle) : WindowPositioning.GetWindowClientAreaSize(windowhandlesource.Handle));
// work out the current screen's DPI
Matrix screenmatrix = windowhandlesource.CompositionTarget.TransformToDevice;
double dpiX = screenmatrix.M11; // 1.0 = 96 dpi
double dpiY = screenmatrix.M22; // 1.25 = 120 dpi, etc.
Point position = WindowPositioning.GetWindowPosition(this.NotifyIcon, windowbounds.Width, windowbounds.Height, dpiX);
// translate wpf points to screen coordinates
Point screenposition = new Point(position.X / dpiX, position.Y / dpiY);
this.Left = screenposition.X;
this.Top = screenposition.Y;
// update borders
if (glassenabled)
this.Style = (Style)FindResource("AeroBorderStyle");
else
this.SetNonGlassBorder(this.IsActive);
// fix aero border if necessary
if (glassenabled)
{
// set the root border element's margin to 1 pixel
WindowBorder.Margin = new Thickness(1 / dpiX);
this.BorderThickness = new Thickness(0);
// set the background of the window to transparent (otherwise the inner border colour won't be visible)
windowhandlesource.CompositionTarget.BackgroundColor = Colors.Transparent;
// get dpi-dependent aero border width
int xmargin = Convert.ToInt32(1); // 1 unit wide
int ymargin = Convert.ToInt32(1); // 1 unit tall
NativeMethods.MARGINS margins = new NativeMethods.MARGINS() { cxLeftWidth = xmargin, cxRightWidth = xmargin, cyBottomHeight = ymargin, cyTopHeight = ymargin };
NativeMethods.DwmExtendFrameIntoClientArea(windowhandlesource.Handle, ref margins);
}
else
{
WindowBorder.Margin = new Thickness(0); // reset the margin if the DWM is disabled
this.BorderThickness = new Thickness(1 / dpiX); // set the window's border thickness to 1 pixel
}
if (activatewindow)
{
this.Show();
this.Activate();
}
}
}
#region Event Handlers
/// <summary>
/// Custom DefWindowProc function used to disable resize and update the window appearance when the window size is changed or the DWM is enabled/disabled.
/// </summary>
/// <param name="hWnd">A handle to the window procedure that received the message.</param>
/// <param name="msg">The message.</param>
/// <param name="wParam">Additional message information. The content of this parameter depends on the value of the Msg parameter (wParam).</param>
/// <param name="lParam">Additional message information. The content of this parameter depends on the value of the Msg parameter (lParam).</param>
/// <param name="handled">True if the message has been handled by the custom window procedure, false if not.</param>
/// <returns>The return value is the result of the message processing and depends on the message.</returns>
private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (this.IsLoaded && this.Visibility == Visibility.Visible)
{
switch (msg)
{
case NativeMethods.WM_NCHITTEST:
// if the mouse pointer is not over the client area of the tab
// ignore it - this disables resize on the glass chrome
if (!NativeMethods.IsOverClientArea(hWnd, wParam, lParam))
handled = true;
break;
case NativeMethods.WM_SETCURSOR:
if (!NativeMethods.IsOverClientArea(hWnd, wParam, lParam))
{
// the high word of lParam specifies the mouse message identifier
// we only want to handle mouse down messages on the border
int hiword = (int)lParam >> 16;
if (hiword == NativeMethods.WM_LBUTTONDOWN
|| hiword == NativeMethods.WM_RBUTTONDOWN
|| hiword == NativeMethods.WM_MBUTTONDOWN
|| hiword == NativeMethods.WM_XBUTTONDOWN)
{
handled = true;
this.Focus(); // focus the window
}
}
break;
case NativeMethods.WM_DWMCOMPOSITIONCHANGED:
// update window appearance accordingly
this.UpdateWindowDisplayIfOpen(false);
break;
case NativeMethods.WM_SIZE:
// update window appearance accordingly
this.UpdateWindowDisplayIfOpen(false);
break;
}
}
return IntPtr.Zero;
}
/// <summary>
/// Sets handlers for notifying the application of desktop preference changes (taskbar movements, etc.).
/// </summary>
private void SetHandlers()
{
if (this.PreferenceEvent == null && this.PreferenceEventHandler == null)
{
this.PreferenceEvent = new UserPreferenceChanged(this.DesktopPreferenceChangedHandler);
this.PreferenceEventHandler = new UserPreferenceChangedEventHandler(this.PreferenceEvent);
SystemEvents.UserPreferenceChanged += this.PreferenceEventHandler;
}
}
/// <summary>
/// Releases handlers set by SetHandlers().
/// </summary>
private void ReleaseHandlers()
{
if (this.PreferenceEvent != null || this.PreferenceEventHandler != null)
{
SystemEvents.UserPreferenceChanged -= this.PreferenceEventHandler;
this.PreferenceEvent = null;
this.PreferenceEventHandler = null;
}
}
/// <summary>
/// Handler for UserPreferenceChangedEventArgs that updates the window display when the user modifies his or her desktop.
/// Note: This does not detect taskbar changes when the taskbar is set to auto-hide.
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the SystemEvents class, this object is always null.</param>
/// <param name="e">A UserPreferenceChangedEventArgs that contains the event data.</param>
private void DesktopPreferenceChangedHandler(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.Desktop)
this.UpdateWindowDisplayIfOpen(false);
}
#endregion
/// <summary>
/// Notify icon clicked or double-clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="args">System.Windows.Forms.MouseEventArgs (which mouse button was pressed, etc.).</param>
private void NotifyIconClick(object sender, System.Windows.Forms.MouseEventArgs args)
{
// sorry if you swapped the primary mouse button
if (args.Button == System.Windows.Forms.MouseButtons.Left &&
(!this.MouseClickToHideNotifyIcon
|| (WindowPositioning.GetCursorPosition().X != this.MouseClickToHideNotifyIconPoint.X || WindowPositioning.GetCursorPosition().Y != this.MouseClickToHideNotifyIconPoint.Y)))
{
if (!this.IsLoaded)
{
this.Show();
}
this.UpdateWindowDisplay(true);
} else {
this.MouseClickToHideNotifyIcon = false;
}
}
/// <summary>
/// Sets the border of the window when the DWM is not enabled. The colour of the border depends on whether the window is active or not.
/// </summary>
/// <param name="windowactivated">True if the window is active, false if not.</param>
private void SetNonGlassBorder(bool windowactivated)
{
//if (windowactivated)
// this.Style = (Style)FindResource("ClassicBorderStyle");
//else
// this.Style = (Style)FindResource("ClassicBorderStyleInactive");
}
/// <summary>
/// Window deactivated method. Hides window if not pinned and sets deactivated border colour if DWM is disabled.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Event arguments.</param>
private void Window_Deactivated(object sender, EventArgs e)
{
this.HideWindow();
}
/// <summary>
/// Hides the window
/// </summary>
private void HideWindow()
{
// note if mouse is over the notify icon when hiding the window
// if it is, we will assume that the user clicked the icon to hide the window
this.MouseClickToHideNotifyIcon = WindowPositioning.IsCursorOverNotifyIcon(this.NotifyIcon) && WindowPositioning.IsNotificationAreaActive;
if (this.MouseClickToHideNotifyIcon)
this.MouseClickToHideNotifyIconPoint = WindowPositioning.GetCursorPosition();
this.ReleaseHandlers();
this.Visibility = Visibility.Hidden;
}
/// <summary>
/// Window closing method. Disposes of the notify icon, removes the custom window procedure and releases user preference change handlers.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Cancel event arguments.</param>
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
eventWatcher.Dispose();
// remove the notify icon
this.NotifyIcon.Visible = false;
this.NotifyIcon.Dispose();
if (this.IsLoaded)
{
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.RemoveHook(this.WndProc);
}
this.ReleaseHandlers();
}
/// <summary>
/// Exit button clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Routed event arguments.</param>
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
this.Exit();
}
/// <summary>
/// Sleep menu button clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Event arguments.</param>
private void SleepMenuEventHandler(object sender, EventArgs e)
{
System.Windows.Forms.Application.SetSuspendState(System.Windows.Forms.PowerState.Suspend, true, true);
}
/// <summary>
/// Exit menu button (notify icon) clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Event arguments.</param>
private void ExitMenuEventHandler(object sender, EventArgs e)
{
this.Exit();
}
/// <summary>
/// Close the application.
/// </summary>
private void Exit()
{
Application.Current.Shutdown();
}
/// <summary>
/// Window activated method. Sets the window border colour if the DWM is disabled.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Event arguments.</param>
private void Window_Activated(object sender, EventArgs e)
{
// update the slider to the current brightness
ignoreValueChanged = true;
UpdateUI(WmiFunctions.GetBrightnessLevel());
ignoreValueChanged = false;
if (!Compatibility.IsDWMEnabled) {
this.SetNonGlassBorder(true);
}
}
/// <summary>
/// Window loaded method. We update the window display before it is made visible, otherwise the user will see its position jump when the notify icon is first clicked.
/// </summary>
/// <param name="sender">Sender of the message.</param>
/// <param name="e">Routed event arguments.</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.UpdateWindowDisplay(false);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(this.WndProc);
}
/// <summary>
/// Creates notify icon and menu.
/// </summary>
private void CreateNotifyIcon()
{
System.Windows.Forms.NotifyIcon notifyicon;
notifyicon = new System.Windows.Forms.NotifyIcon();
var currentBrightness = WmiFunctions.GetBrightnessLevel();
//System.Windows.Forms.MenuItem mnuPin = new System.Windows.Forms.MenuItem("Pin", new EventHandler(this.PinMenuEventHandler));
System.Windows.Forms.MenuItem mnuMonitorOff = new System.Windows.Forms.MenuItem("Power off display", new EventHandler(this.MonitorOffMenuEventHandler));
System.Windows.Forms.MenuItem mnuScreenSaver = new System.Windows.Forms.MenuItem("Start screen saver", new EventHandler(this.StartScreenSaverMenuEventHandler));
System.Windows.Forms.MenuItem mnuSleep = new System.Windows.Forms.MenuItem("Enter sleep mode", new EventHandler(this.SleepMenuEventHandler));
System.Windows.Forms.MenuItem mnuCaffeine = new System.Windows.Forms.MenuItem("Caffeine", new EventHandler(this.CaffeineMenuEventHandler));
mnuAutostart = new System.Windows.Forms.MenuItem("Autostart", new EventHandler(this.AutostartMenuEventHandler));
mnuAutostart.Checked = Autostart.CheckStartupFolderShortcutsExists();
System.Windows.Forms.MenuItem mnuExit = new System.Windows.Forms.MenuItem("Close", new EventHandler(this.ExitMenuEventHandler));
mnuLabel = new System.Windows.Forms.MenuItem("");
mnuLabel.Enabled = false; // greyed-out style label
System.Windows.Forms.MenuItem[] menuitems = new System.Windows.Forms.MenuItem[]
{
mnuLabel, new System.Windows.Forms.MenuItem("-"), mnuMonitorOff, mnuScreenSaver, mnuSleep, new System.Windows.Forms.MenuItem("-"), mnuCaffeine, new System.Windows.Forms.MenuItem("-"), mnuAutostart, new System.Windows.Forms.MenuItem("-"), mnuExit
};
System.Windows.Forms.ContextMenu contextmenu = new System.Windows.Forms.ContextMenu(menuitems);
contextmenu.Popup += this.ContextMenuPopup;
notifyicon.ContextMenu = contextmenu;
notifyicon.MouseClick += this.NotifyIconClick;
notifyicon.MouseDoubleClick += this.NotifyIconClick;
notifyicon.Visible = true;
DrawIcon.updateNotifyIcon(notifyicon, currentBrightness);
this.NotifyIcon = notifyicon;
}
private void AutostartMenuEventHandler(object sender, EventArgs e)
{
if (mnuAutostart.Checked)
{
// remove autostart entry
Autostart.DeleteStartupFolderShortcut();
} else
{
// create autostart entry
Autostart.CreateStartupFolderShortcut();
}
mnuAutostart.Checked = Autostart.CheckStartupFolderShortcutsExists();
}
private void ContextMenuPopup(object sender, EventArgs e)
{
// update the slider to the current brightness
var currentBrightness = WmiFunctions.GetBrightnessLevel();
mnuLabel.Text = "Brightness: " + currentBrightness + "%";
}
private void CaffeineMenuEventHandler(object sender, EventArgs e)
{
System.Windows.Forms.MenuItem menuitem = sender as System.Windows.Forms.MenuItem;
if (menuitem != null) {
if (menuitem.Checked)
{
// reverse-of-being-checked action
Caffeine.unlockSleepMode();
} else
{
Caffeine.lockSleepMode();
}
menuitem.Checked = !menuitem.Checked;
}
}
private void MonitorOffMenuEventHandler(object sender, EventArgs e)
{
MonitorOff.TurnOffMonitor(this);
}
private void StartScreenSaverMenuEventHandler(object sender, EventArgs e)
{
MonitorOff.StartScreenSaver(this);
}
/// <summary>
/// Hyperlink clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Routed event arguments.</param>
private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
this.HideWindow(); // todo remove pinning
MonitorOff.TurnOffMonitor(this);
}
/// <summary>
/// Hyperlink clicked method.
/// </summary>
/// <param name="sender">The sender of the message.</param>
/// <param name="e">Routed event arguments.</param>
private void SleepHyperlink_Click(object sender, RoutedEventArgs e)
{
this.HideWindow(); // todo remove pinning
System.Windows.Forms.Application.SetSuspendState(System.Windows.Forms.PowerState.Suspend, true, true);
}
/// <summary>
/// Change the monitor brightness when the slider value changes.
/// </summary>
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (this.Visibility != Visibility.Visible)
return;
if (ignoreValueChanged)
return;
var newBrightness = (int) e.NewValue;
// Change the brightness in a background thread to avoid UI blocking
new Thread((data) =>
{
WmiFunctions.SetBrightnessLevel((int) newBrightness);
}).Start();
this.percentageLabel.Content = newBrightness.ToString() + "%";
DrawIcon.updateNotifyIcon(NotifyIcon, newBrightness);
}
private void Window_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
BrightnessSlider.Focus();
}
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
{
BrightnessSlider.Value += e.Delta / 60;
e.Handled = true;
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
isKeyDown = false;
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
isKeyDown = true;
}
}
}