Repository navigation
Expand file tree
/
Copy pathSettings.cs
More file actions
2210 lines (1791 loc) · 78.1 KB
/
Copy pathSettings.cs
File metadata and controls
2210 lines (1791 loc) · 78.1 KB
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using GHelper.Ally;
using GHelper.AnimeMatrix;
using GHelper.AutoUpdate;
using GHelper.Battery;
using GHelper.Display;
using GHelper.Fan;
using GHelper.Gpu;
using GHelper.Helpers;
using GHelper.Input;
using GHelper.Mode;
using GHelper.Peripherals;
using GHelper.Peripherals.Mouse;
using GHelper.Properties;
using GHelper.UI;
using GHelper.USB;
using System.Diagnostics;
using System.Timers;
namespace GHelper
{
public partial class SettingsForm : RForm
{
ContextMenuStrip contextMenuStrip = new CustomContextMenu();
ToolStripMenuItem menuEco, menuStandard, menuUltimate, menuOptimized;
DonateControl donateControl;
public GPUModeControl gpuControl;
public AllyControl allyControl;
AutoUpdateControl updateControl;
AsusMouseSettings? mouseSettings;
public AniMatrixControl matrixControl;
public static System.Timers.Timer sensorTimer = default!;
private static readonly bool sensorsAlways = AppConfig.Is("sensors_always");
private readonly System.Windows.Forms.Timer batteryTimer = new() { Interval = 200 };
public Matrix? matrixForm;
public Fans? fansForm;
public Extra? extraForm;
public Updates? updatesForm;
public Handheld? handheldForm;
static long lastRefresh;
static long lastBatteryRefresh;
static long lastLostFocus;
bool isGpuSection = true;
bool isMuxGpu = true;
bool batteryMouseOver = false;
bool batteryFullMouseOver = false;
bool sliderGammaIgnore = false;
bool activateCheck = false;
public SettingsForm()
{
InitializeComponent();
InitTheme(true);
gpuControl = new GPUModeControl(this);
updateControl = new AutoUpdateControl(this);
matrixControl = new AniMatrixControl(this);
allyControl = new AllyControl(this);
buttonSilent.Text = Properties.Strings.Silent;
buttonBalanced.Text = Properties.Strings.Balanced;
buttonTurbo.Text = Properties.Strings.Turbo;
buttonFans.Text = Properties.Strings.FansPower;
buttonEco.Text = Properties.Strings.EcoMode;
buttonUltimate.Text = Properties.Strings.UltimateMode;
buttonStandard.Text = Properties.Strings.StandardMode;
buttonOptimized.Text = Properties.Strings.Optimized;
buttonStopGPU.Text = Properties.Strings.StopGPUApps;
buttonScreenAuto.Text = Properties.Strings.AutoMode;
buttonMiniled.Text = Properties.Strings.Multizone;
buttonKeyboardColor.Text = Properties.Strings.Color;
buttonKeyboard.Text = Properties.Strings.Extra;
labelPerf.Text = Properties.Strings.PerformanceMode;
labelGPU.Text = Properties.Strings.GPUMode;
labelSreen.Text = Properties.Strings.LaptopScreen;
UpdateKeyboardLabel();
labelMatrix.Text = Properties.Strings.AnimeMatrix;
labelBatteryTitle.Text = Properties.Strings.BatteryChargeLimit;
checkMatrix.Text = Properties.Strings.TurnOffOnBattery;
checkMatrixLid.Text = Properties.Strings.DisableOnLidClose;
checkStartup.Text = Properties.Strings.RunOnStartup;
buttonMatrix.Text = Properties.Strings.PictureGif;
buttonQuit.Text = Properties.Strings.Quit;
buttonUpdates.Text = Properties.Strings.Updates;
buttonDonate.Text = Properties.Strings.Donate;
buttonController.Text = Properties.Strings.Controller;
labelAlly.Text = Properties.Strings.AllyController;
// Accessible Labels
panelMatrix.AccessibleName = Properties.Strings.AnimeMatrix;
sliderBattery.AccessibleName = Properties.Strings.BatteryChargeLimit;
buttonQuit.AccessibleName = Properties.Strings.Quit;
buttonUpdates.AccessibleName = Properties.Strings.BiosAndDriverUpdates;
panelPerformance.AccessibleName = Properties.Strings.PerformanceMode;
buttonSilent.AccessibleName = Properties.Strings.Silent;
buttonBalanced.AccessibleName = Properties.Strings.Balanced;
buttonTurbo.AccessibleName = Properties.Strings.Turbo;
buttonFans.AccessibleName = Properties.Strings.FansAndPower;
panelGPU.AccessibleName = Properties.Strings.GPUMode;
buttonEco.AccessibleName = Properties.Strings.EcoMode;
buttonStandard.AccessibleName = Properties.Strings.StandardMode;
buttonOptimized.AccessibleName = Properties.Strings.Optimized;
buttonUltimate.AccessibleName = Properties.Strings.UltimateMode;
panelScreen.AccessibleName = Properties.Strings.LaptopScreen;
buttonScreenAuto.AccessibleName = Properties.Strings.AutoMode;
//button60Hz.AccessibleName = "60Hz Refresh Rate";
//button120Hz.AccessibleName = "Maximum Refresh Rate";
panelKeyboard.AccessibleName = Properties.Strings.LaptopKeyboard;
buttonKeyboard.AccessibleName = Properties.Strings.ExtraSettings;
buttonKeyboardColor.AccessibleName = Properties.Strings.LaptopKeyboard + " " + Properties.Strings.Color;
comboKeyboard.AccessibleName = Properties.Strings.LaptopBacklight;
FormClosing += SettingsForm_FormClosing;
Deactivate += SettingsForm_LostFocus;
Activated += SettingsForm_Focused;
buttonSilent.BorderColor = colorEco;
buttonBalanced.BorderColor = colorStandard;
buttonTurbo.BorderColor = colorTurbo;
buttonFans.BorderColor = colorCustom;
buttonEco.BorderColor = colorEco;
buttonStandard.BorderColor = colorStandard;
buttonUltimate.BorderColor = colorTurbo;
buttonOptimized.BorderColor = colorEco;
buttonXGM.BorderColor = colorTurbo;
button60Hz.BorderColor = colorGray;
button120Hz.BorderColor = colorGray;
buttonScreenAuto.BorderColor = colorGray;
buttonMiniled.BorderColor = colorTurbo;
buttonEnergySaver.BackColor = colorEco;
buttonEnergySaver.ForeColor = SystemColors.ControlLightLight;
buttonEnergySaver.Click += ButtonEnergySaver_Click;
buttonAmdOled.BackColor = colorTurbo;
buttonAmdOled.ForeColor = SystemColors.ControlLightLight;
buttonAmdOled.Click += ButtonAmdOled_Click;
buttonArmoury.BackColor = colorTurbo;
buttonArmoury.ForeColor = SystemColors.ControlLightLight;
buttonArmoury.Click += ButtonArmoury_Click;
buttonSilent.Click += ButtonSilent_Click;
buttonBalanced.Click += ButtonBalanced_Click;
buttonTurbo.Click += ButtonTurbo_Click;
buttonEco.Click += ButtonEco_Click;
buttonStandard.Click += ButtonStandard_Click;
buttonUltimate.Click += ButtonUltimate_Click;
buttonOptimized.Click += ButtonOptimized_Click;
buttonStopGPU.Click += ButtonStopGPU_Click;
VisibleChanged += SettingsForm_VisibleChanged;
button60Hz.Click += Button60Hz_Click;
button120Hz.Click += Button120Hz_Click;
buttonScreenAuto.Click += ButtonScreenAuto_Click;
buttonMiniled.Click += ButtonMiniled_Click;
buttonFHD.Click += ButtonFHD_Click;
buttonHDRControl.Click += ButtonHDRControl_Click;
buttonQuit.Click += ButtonQuit_Click;
buttonKeyboardColor.Click += ButtonKeyboardColor_Click;
buttonKeyboardColor.Swatch2Click += ButtonKeyboardColor2_Click;
buttonFans.Click += ButtonFans_Click;
buttonKeyboard.Click += ButtonKeyboard_Click;
buttonController.Click += ButtonHandheld_Click;
labelCPUFan.Click += LabelCPUFan_Click;
labelGPUFan.Click += LabelCPUFan_Click;
comboMatrix.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrixRunning.DropDownStyle = ComboBoxStyle.DropDownList;
comboInterval.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrix.DropDownClosed += ComboMatrix_SelectedValueChanged;
comboMatrixRunning.DropDownClosed += ComboMatrixRunning_SelectedValueChanged;
comboInterval.DropDownClosed += ComboInterval_DropDownClosed;
buttonMatrix.Click += ButtonMatrix_Click;
checkStartup.Checked = Startup.IsScheduled();
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
labelVersion.Click += LabelVersion_Click;
labelVersion.ForeColor = Color.FromArgb(128, Color.Gray);
buttonOptimized.MouseMove += ButtonOptimized_MouseHover;
buttonOptimized.MouseLeave += ButtonGPU_MouseLeave;
buttonEco.MouseMove += ButtonEco_MouseHover;
buttonEco.MouseLeave += ButtonGPU_MouseLeave;
buttonStandard.MouseMove += ButtonStandard_MouseHover;
buttonStandard.MouseLeave += ButtonGPU_MouseLeave;
buttonUltimate.MouseMove += ButtonUltimate_MouseHover;
buttonUltimate.MouseLeave += ButtonGPU_MouseLeave;
tableGPU.MouseMove += ButtonXGM_MouseMove;
tableGPU.MouseLeave += ButtonGPU_MouseLeave;
buttonXGM.Click += ButtonXGM_Click;
buttonScreenAuto.MouseMove += ButtonScreenAuto_MouseHover;
buttonScreenAuto.MouseLeave += ButtonScreen_MouseLeave;
button60Hz.MouseMove += Button60Hz_MouseHover;
button60Hz.MouseLeave += ButtonScreen_MouseLeave;
button120Hz.MouseMove += Button120Hz_MouseHover;
button120Hz.MouseLeave += ButtonScreen_MouseLeave;
buttonFHD.MouseMove += ButtonFHD_MouseHover;
buttonFHD.MouseLeave += ButtonScreen_MouseLeave;
buttonUpdates.Click += ButtonUpdates_Click;
sliderBattery.MouseUp += SliderBattery_MouseUp;
sliderBattery.KeyUp += SliderBattery_KeyUp;
sliderBattery.ValueChanged += SliderBattery_ValueChanged;
batteryTimer.Tick += (_, _) => { batteryTimer.Stop(); BatteryControl.SetBatteryChargeLimit(sliderBattery.Value); };
if (AppConfig.IsChargeLimit6080()) sliderBattery.supportedValues = new() { 60, 65, 70, 75, 80, 100 };
sensorTimer = new System.Timers.Timer(AppConfig.Get("sensor_timer", 1000));
sensorTimer.Elapsed += OnTimedEvent;
sensorTimer.Enabled = sensorsAlways;
labelCharge.MouseEnter += PanelBattery_MouseEnter;
labelCharge.MouseLeave += PanelBattery_MouseLeave;
labelBattery.Click += LabelBattery_Click;
buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
buttonPeripheral3.Click += ButtonPeripheral_Click;
buttonPeripheral1.MouseEnter += ButtonPeripheral_MouseEnter;
buttonPeripheral2.MouseEnter += ButtonPeripheral_MouseEnter;
buttonPeripheral3.MouseEnter += ButtonPeripheral_MouseEnter;
buttonBatteryFull.MouseEnter += ButtonBatteryFull_MouseEnter;
buttonBatteryFull.MouseLeave += ButtonBatteryFull_MouseLeave;
buttonBatteryFull.Click += ButtonBatteryFull_Click;
buttonControllerMode.Click += ButtonControllerMode_Click;
buttonBacklight.Click += ButtonBacklight_Click;
buttonFPS.Click += ButtonFPS_Click;
buttonOverlay.Click += ButtonOverlay_Click;
buttonOverlay.BorderColor = colorStandard;
buttonAutoTDP.Click += ButtonAutoTDP_Click;
buttonAutoTDP.BorderColor = colorTurbo;
Text = "G-Helper " + (ProcessHelper.IsUserAdministrator() ? "—" : "-") + " " + AppConfig.GetModelShort();
TopMost = AppConfig.Is("topmost");
//This will auto position the window again when it resizes. Might mess with position if people drag the window somewhere else.
this.Resize += SettingsForm_Resize;
VisualiseFnLock();
buttonFnLock.Click += ButtonFnLock_Click;
labelVisual.Click += LabelVisual_Click;
labelCharge.Click += LabelCharge_Click;
donateControl = new DonateControl(this, buttonDonate);
donateControl.Init();
labelBacklight.ForeColor = colorStandard;
labelBacklight.Click += LabelBacklight_Click;
panelPerformance.Focus();
InitVisual();
}
private void ButtonArmoury_Click(object? sender, EventArgs e)
{
var dialogResult = MessageBox.Show(this, "Armoury Crate is active, download official uninstaller app?", "Armoury Crate", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes) AsusService.RunArmouryUninstaller();
}
private void ButtonAmdOled_Click(object? sender, EventArgs e)
{
AmdDisplay.RunAdrenaline();
activateCheck = true;
}
private void LabelBattery_Click(object? sender, EventArgs e)
{
HardwareControl.chargeWatt = !HardwareControl.chargeWatt;
RefreshSensors(true);
}
private void ButtonEnergySaver_Click(object? sender, EventArgs e)
{
KeyboardHook.KeyKeyPress(Keys.LWin, Keys.A);
activateCheck = true;
}
private void LabelBacklight_Click(object? sender, EventArgs e)
{
if (AppConfig.IsDynamicLighting() && DynamicLightingHelper.IsEnabled()) DynamicLightingHelper.OpenSettings();
}
private void ButtonFHD_Click(object? sender, EventArgs e)
{
ScreenControl.ToogleFHD();
}
private void ButtonHDRControl_Click(object? sender, EventArgs e)
{
ScreenControl.ToogleHDRControl();
}
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
{
VisualiseBatteryTitle(sliderBattery.Value);
}
private void SliderBattery_KeyUp(object? sender, KeyEventArgs e)
{
batteryTimer.Stop();
batteryTimer.Start();
}
private void SliderBattery_MouseUp(object? sender, MouseEventArgs e)
{
batteryTimer.Stop();
batteryTimer.Start();
}
private void ButtonAutoTDP_Click(object? sender, EventArgs e)
{
allyControl.ToggleAutoTDP();
}
private void LabelCharge_Click(object? sender, EventArgs e)
{
BatteryControl.BatteryReport();
}
private void LabelVisual_Click(object? sender, EventArgs e)
{
labelVisual.Visible = false;
VisualControl.forceVisual = true;
}
public void InitVisual()
{
if (AppConfig.Is("hide_visual")) return;
if (AppConfig.IsOLED())
{
panelGamma.Visible = true;
sliderGamma.Visible = true;
labelGammaTitle.Text = Properties.Strings.FlickerFreeDimming + " / " + Properties.Strings.VisualMode;
VisualiseBrightness();
sliderGamma.ValueChanged += SliderGamma_ValueChanged;
sliderGamma.MouseUp += SliderGamma_ValueChanged;
}
else
{
labelGammaTitle.Text = Properties.Strings.VisualMode;
}
var gamuts = VisualControl.GetGamutModes();
// Color profiles exist
if (gamuts.Count > 0)
{
tableVisual.ColumnCount = 3;
buttonInstallColor.Visible = false;
}
else
{
// If it's possible to retrieve color profiles
if (ColorProfileHelper.ProfileExists())
{
tableVisual.ColumnCount = 2;
buttonInstallColor.Text = Properties.Strings.DownloadColorProfiles;
buttonInstallColor.Visible = true;
buttonInstallColor.Click += ButtonInstallColorProfile_Click;
panelGamma.Visible = true;
tableVisual.Visible = true;
}
return;
}
panelGamma.Visible = true;
tableVisual.Visible = true;
var visualValue = (SplendidCommand)AppConfig.Get("visual", (int)VisualControl.GetDefaultVisualMode());
var colorTempValue = AppConfig.Get("color_temp", VisualControl.DefaultColorTemp);
comboVisual.DropDownStyle = ComboBoxStyle.DropDownList;
comboVisual.DataSource = new BindingSource(VisualControl.GetVisualModes(), null);
comboVisual.DisplayMember = "Value";
comboVisual.ValueMember = "Key";
comboVisual.SelectedValue = visualValue;
comboColorTemp.DropDownStyle = ComboBoxStyle.DropDownList;
comboColorTemp.DataSource = new BindingSource(VisualControl.GetTemperatures(), null);
comboColorTemp.DisplayMember = "Value";
comboColorTemp.ValueMember = "Key";
comboColorTemp.SelectedValue = colorTempValue;
VisualControl.SetVisual(visualValue, colorTempValue, true);
comboVisual.SelectedValueChanged += ComboVisual_SelectedValueChanged;
comboVisual.Visible = true;
VisualiseDisabled();
comboColorTemp.SelectedValueChanged += ComboVisual_SelectedValueChanged;
comboColorTemp.Visible = true;
if (gamuts.Count <= 1) return;
comboGamut.DropDownStyle = ComboBoxStyle.DropDownList;
comboGamut.DataSource = new BindingSource(gamuts, null);
comboGamut.DisplayMember = "Value";
comboGamut.ValueMember = "Key";
comboGamut.SelectedValue = (SplendidGamut)AppConfig.Get("gamut", (int)VisualControl.GetDefaultGamut());
comboGamut.SelectedValueChanged += ComboGamut_SelectedValueChanged;
comboGamut.Visible = true;
}
public void CycleVisualMode(int delta)
{
if (comboVisual.Items.Count < 1) return;
if (delta > 0)
{
if (comboVisual.SelectedIndex < comboVisual.Items.Count - 1)
comboVisual.SelectedIndex += 1;
else
comboVisual.SelectedIndex = 0;
}
else
{
if (comboVisual.SelectedIndex > 0)
comboVisual.SelectedIndex -= 1;
else
comboVisual.SelectedIndex = comboVisual.Items.Count - 1;
}
Program.toast.RunToast(comboVisual.GetItemText(comboVisual.SelectedItem), ToastIcon.BrightnessUp);
}
private async void ButtonInstallColorProfile_Click(object? sender, EventArgs e)
{
await ColorProfileHelper.InstallProfile();
InitVisual();
}
private void ComboGamut_SelectedValueChanged(object? sender, EventArgs e)
{
VisualControl.SetGamut((int)comboGamut.SelectedValue);
}
private void ComboVisual_SelectedValueChanged(object? sender, EventArgs e)
{
VisualControl.SetVisual((SplendidCommand)comboVisual.SelectedValue, (int)comboColorTemp.SelectedValue);
VisualiseDisabled();
}
public void VisualiseBrightness()
{
if (InvokeRequired) { Invoke(VisualiseBrightness); return; }
sliderGammaIgnore = true;
sliderGamma.Value = VisualControl.GetBrightness();
labelGamma.Text = sliderGamma.Value + "%";
sliderGammaIgnore = false;
}
public void VisualiseAmdOled(bool status = false)
{
if (InvokeRequired) { Invoke(() => VisualiseAmdOled(status)); return; }
buttonAmdOled.Visible = status;
}
public void VisualiseArmoury(bool status = false)
{
if (InvokeRequired) { Invoke(() => VisualiseArmoury(status)); return; }
buttonArmoury.Visible = status;
}
public void VisualiseDisabled()
{
comboGamut.Enabled = comboColorTemp.Enabled = (SplendidCommand)AppConfig.Get("visual") != SplendidCommand.Disabled;
}
public void VisualiseGamut()
{
if (InvokeRequired) { Invoke(VisualiseGamut); return; }
if (comboGamut.Items.Count > 0) comboGamut.SelectedIndex = 0;
}
private void SliderGamma_ValueChanged(object? sender, EventArgs e)
{
if (sliderGammaIgnore) return;
VisualControl.SetBrightness(sliderGamma.Value);
}
private void ButtonOverlay_Click(object? sender, EventArgs e)
{
ToggleOverlay();
}
private void ButtonHandheld_Click(object? sender, EventArgs e)
{
if (handheldForm == null || handheldForm.Text == "")
{
handheldForm = new Handheld();
AddOwnedForm(handheldForm);
}
if (handheldForm.Visible)
{
handheldForm.Close();
}
else
{
//handheldForm.FormPosition();
handheldForm.Show();
}
}
private void ButtonFPS_Click(object? sender, EventArgs e)
{
allyControl.ToggleFPSLimit();
}
private void ButtonBacklight_Click(object? sender, EventArgs e)
{
allyControl.ToggleBacklight();
}
private void ButtonControllerMode_Click(object? sender, EventArgs e)
{
allyControl.ToggleMode();
}
public void VisualiseAlly(bool visible = false)
{
if (!visible) return;
if (InvokeRequired) { Invoke(() => VisualiseAlly(visible)); return; }
panelAlly.Visible = true;
panelKeyboardTitle.Visible = false;
panelKeyboard.Padding = new Padding(panelKeyboard.Padding.Left, 0, panelKeyboard.Padding.Right, panelKeyboard.Padding.Bottom);
buttonOverlay.Text = Properties.Strings.Overlay;
buttonOverlay.Activated = AppConfig.IsOverlay();
tableAMD.Visible = true;
}
public void VisualiseController(ControllerMode mode)
{
switch (mode)
{
case ControllerMode.Gamepad:
buttonControllerMode.Text = "Gamepad";
break;
case ControllerMode.Mouse:
buttonControllerMode.Text = "Mouse";
break;
case ControllerMode.Skip:
buttonControllerMode.Text = "Skip";
break;
default:
buttonControllerMode.Text = "Auto";
break;
}
}
public void VisualiseBacklight(int backlight)
{
if (InvokeRequired) { Invoke(() => VisualiseBacklight(backlight)); return; }
buttonBacklight.Text = Math.Round((double)backlight * 33.33).ToString() + "%";
}
public void VisualiseFPSLimit(int limit)
{
if (InvokeRequired) { Invoke(() => VisualiseFPSLimit(limit)); return; }
buttonFPS.Text = "FPS Limit " + ((limit > 0 && limit <= 120) ? limit : "OFF");
}
public void VisualiseAutoTDP(bool status)
{
Logger.WriteLine($"Auto TDP: {status}");
buttonAutoTDP.Activated = status;
}
private void SettingsForm_Focused(object? sender, EventArgs e)
{
if (activateCheck)
{
buttonEnergySaver.Visible = PowerNative.GetBatterySaverStatus();
buttonAmdOled.Visible = AmdDisplay.IsOledPowerOptimization();
activateCheck = false;
}
}
private void SettingsForm_LostFocus(object? sender, EventArgs e)
{
lastLostFocus = DateTimeOffset.Now.ToUnixTimeMilliseconds();
}
private void ButtonBatteryFull_Click(object? sender, EventArgs e)
{
BatteryControl.ToggleBatteryLimitFull();
}
private void ButtonBatteryFull_MouseLeave(object? sender, EventArgs e)
{
batteryFullMouseOver = false;
RefreshSensors(true);
}
private void ButtonBatteryFull_MouseEnter(object? sender, EventArgs e)
{
batteryFullMouseOver = true;
labelCharge.Text = Properties.Strings.BatteryLimitFull;
}
private void SettingsForm_Resize(object? sender, EventArgs e)
{
if (WindowState != FormWindowState.Normal)
{
WindowState = FormWindowState.Normal;
return;
}
Left = Screen.FromControl(this).WorkingArea.Width - 10 - Width;
Top = Screen.FromControl(this).WorkingArea.Height - 10 - Height;
}
private void PanelBattery_MouseEnter(object? sender, EventArgs e)
{
batteryMouseOver = true;
ShowBatteryWear();
}
private void PanelBattery_MouseLeave(object? sender, EventArgs e)
{
batteryMouseOver = false;
RefreshSensors(true);
}
private void ShowBatteryWear()
{
//Refresh again only after 15 Minutes since the last refresh
if (lastBatteryRefresh == 0 || Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastBatteryRefresh) > 15 * 60_000)
{
lastBatteryRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds();
HardwareControl.RefreshBatteryHealth();
}
if (HardwareControl.batteryHealth != -1)
{
labelCharge.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%";
}
}
private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
{
sensorTimer.Enabled = this.Visible || sensorsAlways;
if (this.Visible)
{
Task.Run((Action)RefreshPeripheralsBattery);
updateControl.CheckForUpdates();
BeginInvoke(new Action(() =>
{
ScreenControl.InitScreen();
VisualizeXGM();
buttonEnergySaver.Visible = PowerNative.GetBatterySaverStatus();
}));
}
}
private void RefreshPeripheralsBattery()
{
PeripheralsProvider.RefreshBatteryForAllDevices(true);
}
private void ButtonUpdates_Click(object? sender, EventArgs e)
{
if (updatesForm == null || updatesForm.Text == "")
{
updatesForm = new Updates();
AddOwnedForm(updatesForm);
}
if (updatesForm.Visible)
{
updatesForm.Close();
}
else
{
updatesForm.Show();
}
}
public void VisualiseMatrixPicture(string image)
{
if (matrixForm == null || matrixForm.Text == "") return;
matrixForm.VisualiseMatrix(image);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == NativeMethods.WM_POWERBROADCAST && m.WParam == (IntPtr)NativeMethods.PBT_APMSUSPEND)
{
Logger.WriteLine("System Suspend");
Program.modeControl.SleepReset();
m.Result = (IntPtr)1;
}
if (m.Msg == NativeMethods.WM_POWERBROADCAST && m.WParam == (IntPtr)NativeMethods.PBT_APMRESUMEAUTOMATIC)
{
Logger.WriteLine("System Resume");
BatteryControl.AutoBattery();
m.Result = (IntPtr)1;
}
if (m.Msg == NativeMethods.WM_POWERBROADCAST && m.WParam == (IntPtr)NativeMethods.PBT_POWERSETTINGCHANGE)
{
var settings = (NativeMethods.POWERBROADCAST_SETTING)m.GetLParam(typeof(NativeMethods.POWERBROADCAST_SETTING));
if (settings.PowerSetting == NativeMethods.PowerSettingGuid.LIDSWITCH_STATE_CHANGE)
{
switch (settings.Data)
{
case 0:
Logger.WriteLine("Lid Closed");
BatteryControl.AutoBattery();
InputDispatcher.lidClose = AniMatrixControl.lidClose = true;
Aura.ApplyBrightness(0, "Lid");
matrixControl.SetLidMode();
break;
case 1:
Logger.WriteLine("Lid Open");
InputDispatcher.InitFNLock();
InputDispatcher.lidClose = AniMatrixControl.lidClose = false;
Aura.ApplyBrightness(InputDispatcher.GetBacklight(), "Lid");
matrixControl.SetLidMode();
break;
}
}
else
{
switch (settings.Data)
{
case 0:
Logger.WriteLine("Monitor Power Off");
Aura.SleepBrightness();
Program.hardwareOverlay?.SuspendForDisplayOff();
break;
case 1:
Logger.WriteLine("Monitor Power On");
if (!Program.SetAutoModes(wakeup: true)) BatteryControl.AutoBattery();
Program.hardwareOverlay?.ResumeForDisplayOn();
break;
case 2:
Logger.WriteLine("Monitor Dimmed");
break;
}
}
m.Result = (IntPtr)1;
}
if (m.Msg == Program.WM_TASKBARCREATED)
{
Logger.WriteLine("Taskbar created, re-creating tray icon");
if (Program.trayIcon is not null) Program.trayIcon.Visible = true;
}
try
{
base.WndProc(ref m);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
public void SetContextMenu()
{
var currentMode = Modes.GetCurrent();
foreach (ToolStripItem item in contextMenuStrip.Items.Cast<ToolStripItem>().ToList())
{
if (item is ToolStripMenuItem menuItem) menuItem.Dispose();
}
contextMenuStrip.Items.Clear();
contextMenuStrip.ShowCheckMargin = true;
contextMenuStrip.ImageScalingSize = new Size(16, 16);
contextMenuStrip.ShowImageMargin = false;
Padding padding = new Padding(5, 5, 5, 5);
var title = new ToolStripMenuItem(Properties.Strings.PerformanceMode);
title.Margin = padding;
title.Enabled = false;
contextMenuStrip.Items.Add(title);
foreach (var mode in Modes.GetDictonary())
{
var menuMode = new ToolStripMenuItem(mode.Value);
menuMode.Tag = mode.Key;
menuMode.Click += (sender, args) => { Program.modeControl.SetPerformanceMode(mode.Key); };
menuMode.Margin = padding;
menuMode.Checked = (mode.Key == currentMode);
contextMenuStrip.Items.Add(menuMode);
}
contextMenuStrip.Items.Add("-");
if (isGpuSection)
{
var titleGPU = new ToolStripMenuItem(Properties.Strings.GPUMode);
titleGPU.Margin = padding;
titleGPU.Enabled = false;
contextMenuStrip.Items.Add(titleGPU);
menuEco = new ToolStripMenuItem(Properties.Strings.EcoMode);
menuEco.Click += ButtonEco_Click;
menuEco.Margin = padding;
menuEco.Checked = buttonEco.Activated;
contextMenuStrip.Items.Add(menuEco);
menuStandard = new ToolStripMenuItem(Properties.Strings.StandardMode);
menuStandard.Click += ButtonStandard_Click;
menuStandard.Margin = padding;
menuStandard.Checked = buttonStandard.Activated;
contextMenuStrip.Items.Add(menuStandard);
menuUltimate = new ToolStripMenuItem(Properties.Strings.UltimateMode);
menuUltimate.Click += ButtonUltimate_Click;
menuUltimate.Margin = padding;
menuUltimate.Checked = buttonUltimate.Activated;
menuUltimate.Visible = isMuxGpu;
contextMenuStrip.Items.Add(menuUltimate);
menuOptimized = new ToolStripMenuItem(Properties.Strings.Optimized);
menuOptimized.Click += ButtonOptimized_Click;
menuOptimized.Margin = padding;
menuOptimized.Checked = buttonOptimized.Activated;
contextMenuStrip.Items.Add(menuOptimized);
contextMenuStrip.Items.Add("-");
}
var bwIcon = new ToolStripMenuItem(Properties.Strings.BWTrayIcon);
bwIcon.Margin = padding;
bwIcon.Checked = AppConfig.IsBWIcon();
bwIcon.Click += (sender, args) =>
{
bwIcon.Checked = !bwIcon.Checked;
AppConfig.Set("bw_icon", bwIcon.Checked ? 1 : 0);
VisualiseIcon();
};
contextMenuStrip.Items.Add(bwIcon);
contextMenuStrip.Items.Add("-");
var menuOverlay = new ToolStripMenuItem(Properties.Strings.Overlay);
menuOverlay.Click += (sender, args) => ToggleOverlay();
menuOverlay.Margin = padding;
menuOverlay.Checked = AppConfig.IsOverlay();
contextMenuStrip.Items.Add(menuOverlay);
var menuOverlayGameOnly = new ToolStripMenuItem(Properties.Strings.OverlayOnlyInGames);
menuOverlayGameOnly.Click += (sender, args) => ToggleOverlayGameOnly();
menuOverlayGameOnly.Margin = padding;
menuOverlayGameOnly.Checked = AppConfig.IsOverlayGameOnly();
menuOverlayGameOnly.Enabled = AppConfig.IsOverlay();
contextMenuStrip.Items.Add(menuOverlayGameOnly);
var quit = new ToolStripMenuItem(Properties.Strings.Quit);
quit.Click += ButtonQuit_Click;
quit.Margin = padding;
contextMenuStrip.Items.Add(quit);
//contextMenuStrip.ShowCheckMargin = true;
contextMenuStrip.Renderer = new CustomMenuRenderer();
InitContextMenuTheme();
if (Program.trayIcon is not null) Program.trayIcon.ContextMenuStrip = contextMenuStrip;
}
public void InitContextMenuTheme()
{
if (contextMenuStrip is not null)
{
contextMenuStrip.BackColor = this.BackColor;
contextMenuStrip.ForeColor = this.ForeColor;
}
donateControl?.ApplyTheme();
}
private void ButtonXGM_Click(object? sender, EventArgs e)
{
gpuControl.ToggleXGM();
}
public void SetVersionLabel(string label, bool update = false)
{
if (InvokeRequired)
Invoke(delegate
{
labelVersion.Text = label;
if (update) labelVersion.ForeColor = colorTurbo;
});
else
{
labelVersion.Text = label;
if (update) labelVersion.ForeColor = colorTurbo;
}
}
private void LabelVersion_Click(object? sender, EventArgs e)
{
updateControl.Update();
}
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
{
Program.settingsForm.RefreshSensors();
}
private void ButtonFHD_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = "Switch to " + ((buttonFHD.Text == "FHD") ? "UHD" : "FHD") + " Mode";
}
private void Button120Hz_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.MaxRefreshTooltip;
}
private void Button60Hz_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.MinRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}
private void ButtonScreen_MouseLeave(object? sender, EventArgs e)
{
labelTipScreen.Text = "";
}
private void ButtonScreenAuto_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.AutoRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}
private void ButtonUltimate_MouseHover(object? sender, EventArgs e)