-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitorControlPro.ps1
More file actions
2906 lines (2736 loc) · 176 KB
/
Copy pathMonitorControlPro.ps1
File metadata and controls
2906 lines (2736 loc) · 176 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
<#
.SYNOPSIS
MonitorControl Pro v3.19.0 - Advanced Display & GPU Settings Utility
.DESCRIPTION
Comprehensive GUI for monitor DDC/CI control with VCP explorer, input switching,
color temperature presets, sync across monitors, and time-based automation.
.NOTES
Version: 3.19.0 - Enhanced with schedule timeline UI
#>
param([switch]$StartMinimized, [string]$LoadProfile)
Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms, System.Drawing, System.IO.Compression.FileSystem
$nativeCode = @"
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
public class MonitorAPI
{
[DllImport("user32.dll")]
public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFOEX lpmi);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool EnumDisplaySettingsEx(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode, uint dwFlags);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[DllImport("kernel32.dll")]
public static extern uint GetTickCount();
public delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData);
[StructLayout(LayoutKind.Sequential)]
public struct RECT { public int Left, Top, Right, Bottom; }
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO { public uint cbSize; public uint dwTime; }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MONITORINFOEX {
public int Size; public RECT Monitor; public RECT WorkArea; public uint Flags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string DeviceName;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct DISPLAY_DEVICE {
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceString;
public uint StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceKey;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct DEVMODE {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmDeviceName;
public short dmSpecVersion, dmDriverVersion, dmSize, dmDriverExtra;
public uint dmFields;
public int dmPositionX, dmPositionY;
public uint dmDisplayOrientation, dmDisplayFixedOutput;
public short dmColor, dmDuplex, dmYResolution, dmTTOption, dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmFormName;
public short dmLogPixels;
public uint dmBitsPerPel, dmPelsWidth, dmPelsHeight, dmDisplayFlags, dmDisplayFrequency;
public uint dmICMMethod, dmICMIntent, dmMediaType, dmDitherType, dmReserved1, dmReserved2, dmPanningWidth, dmPanningHeight;
}
public const int ENUM_CURRENT_SETTINGS = -1;
public const uint DISPLAY_DEVICE_ACTIVE = 1;
public const uint MONITORINFOF_PRIMARY = 1;
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, out uint pdwNumberOfPhysicalMonitors);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool GetPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, uint dwPhysicalMonitorArraySize, [Out] PHYSICAL_MONITOR[] pPhysicalMonitorArray);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool DestroyPhysicalMonitor(IntPtr hMonitor);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool GetVCPFeatureAndVCPFeatureReply(IntPtr hMonitor, byte bVCPCode, out uint pvct, out uint pdwCurrentValue, out uint pdwMaximumValue);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool SetVCPFeature(IntPtr hMonitor, byte bVCPCode, uint dwNewValue);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool GetCapabilitiesStringLength(IntPtr hMonitor, out uint pdwCapabilitiesStringLengthInCharacters);
[DllImport("dxva2.dll", SetLastError = true)]
public static extern bool CapabilitiesRequestAndCapabilitiesReply(IntPtr hMonitor, StringBuilder pszASCIICapabilitiesString, uint dwCapabilitiesStringLengthInCharacters);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PHYSICAL_MONITOR {
public IntPtr hPhysicalMonitor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string szPhysicalMonitorDescription;
}
public const byte VCP_BRIGHTNESS = 0x10, VCP_CONTRAST = 0x12, VCP_COLOR_PRESET = 0x14;
public const byte VCP_RED_GAIN = 0x16, VCP_GREEN_GAIN = 0x18, VCP_BLUE_GAIN = 0x1A;
public const byte VCP_SHARPNESS = 0x87, VCP_VOLUME = 0x62, VCP_MUTE = 0x8D;
public const byte VCP_INPUT_SOURCE = 0x60, VCP_POWER_MODE = 0xD6, VCP_DISPLAY_MODE = 0xDC;
public const byte VCP_PIP_SECONDARY_SOURCE = 0xE8, VCP_PIP_MODE = 0xE9;
public const byte VCP_RESTORE_FACTORY_DEFAULTS = 0x04, VCP_RESTORE_FACTORY_COLOR = 0x08;
public const byte VCP_VERSION = 0xDF, VCP_DISPLAY_USAGE_TIME = 0xC0;
public const uint POWER_ON = 0x01, POWER_STANDBY = 0x02, POWER_OFF = 0x04;
public const uint DISPLAY_MODE_STANDARD = 0x00, DISPLAY_MODE_PRODUCTIVITY = 0x01, DISPLAY_MODE_MOVIE = 0x03, DISPLAY_MODE_GAMES = 0x05, DISPLAY_MODE_DYNAMIC_CONTRAST = 0xF0;
public const uint PIP_MODE_OFF = 0x00, PIP_MODE_UPPER_RIGHT = 0x21, PIP_MODE_PBP_SPLIT = 0x23;
public const uint PIP_SECONDARY_HDMI1 = 0x11, PIP_SECONDARY_HDMI2 = 0x12, PIP_SECONDARY_DISPLAYPORT = 0x21;
public const uint COLOR_PRESET_SRGB = 0x01, COLOR_PRESET_5000K = 0x04, COLOR_PRESET_6500K = 0x05, COLOR_PRESET_9300K = 0x08;
[DllImport("gdi32.dll")]
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[StructLayout(LayoutKind.Sequential)]
public struct RAMP {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public ushort[] Red;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public ushort[] Green;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public ushort[] Blue;
}
public static List<IntPtr> MonitorHandles = new List<IntPtr>();
public static bool MonitorEnumCallback(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData) { MonitorHandles.Add(hMonitor); return true; }
public static List<IntPtr> GetAllMonitorHandles() { MonitorHandles.Clear(); EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, MonitorEnumCallback, IntPtr.Zero); return MonitorHandles; }
}
public class NvApiInterop
{
private const int NVAPI_OK = 0;
private const uint NVAPI_INITIALIZE_ID = 0x0150E828;
private const uint NVAPI_SET_DVC_LEVEL_ID = 0x172409B4;
[DllImport("nvapi64.dll", EntryPoint = "nvapi_QueryInterface", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr QueryInterface(uint functionId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int NvApiInitializeDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int NvApiSetDvcLevelDelegate(IntPtr displayHandle, uint outputId, int level);
private static T GetDelegate<T>(uint functionId) where T : class
{
IntPtr ptr = QueryInterface(functionId);
if (ptr == IntPtr.Zero) { return null; }
return Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
}
public static bool SetDigitalVibrance(int level, out string message)
{
if (level < 0) { level = 0; }
if (level > 100) { level = 100; }
try
{
NvApiInitializeDelegate initialize = GetDelegate<NvApiInitializeDelegate>(NVAPI_INITIALIZE_ID);
NvApiSetDvcLevelDelegate setDvcLevel = GetDelegate<NvApiSetDvcLevelDelegate>(NVAPI_SET_DVC_LEVEL_ID);
if (initialize == null || setDvcLevel == null)
{
message = "NVAPI digital vibrance entry point unavailable";
return false;
}
int status = initialize();
if (status != NVAPI_OK)
{
message = "NVAPI init failed: " + status;
return false;
}
status = setDvcLevel(IntPtr.Zero, 0, level);
if (status != NVAPI_OK)
{
message = "NVAPI digital vibrance failed: " + status;
return false;
}
message = "Digital vibrance set to " + level + "%";
return true;
}
catch (DllNotFoundException)
{
message = "nvapi64.dll not found";
return false;
}
catch (EntryPointNotFoundException)
{
message = "nvapi_QueryInterface not found";
return false;
}
catch (Exception ex)
{
message = "NVAPI digital vibrance error: " + ex.Message;
return false;
}
}
}
public class AmdAdlInterop
{
private const int ADL_OK = 0;
private const int ADL_FAN_SPEED_TYPE_PERCENT = 1;
private static bool initialized = false;
private static ADL_MAIN_MALLOC_CALLBACK mallocCallback = Alloc;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr ADL_MAIN_MALLOC_CALLBACK(int size);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Main_Control_Create(ADL_MAIN_MALLOC_CALLBACK callback, int enumConnectedAdapters);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Adapter_NumberOfAdapters_Get(ref int numAdapters);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Adapter_AdapterInfo_Get(IntPtr adapterInfo, int inputSize);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Overdrive5_Temperature_Get(int adapterIndex, int thermalControllerIndex, ref ADLTemperature temperature);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Overdrive5_CurrentActivity_Get(int adapterIndex, ref ADLPMActivity activity);
[DllImport("atiadlxx.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ADL_Overdrive5_FanSpeed_Get(int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedValue fanSpeed);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
private struct ADLAdapterInfo
{
public int Size;
public int AdapterIndex;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string UDID;
public int BusNumber;
public int DeviceNumber;
public int FunctionNumber;
public int VendorID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string AdapterName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DisplayName;
public int Present;
public int Exist;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DriverPath;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DriverPathExt;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string PNPString;
public int OSDisplayIndex;
}
[StructLayout(LayoutKind.Sequential)]
private struct ADLTemperature
{
public int Size;
public int Temperature;
}
[StructLayout(LayoutKind.Sequential)]
private struct ADLPMActivity
{
public int Size;
public int EngineClock;
public int MemoryClock;
public int Vddc;
public int ActivityPercent;
public int CurrentPerformanceLevel;
public int CurrentBusSpeed;
public int CurrentBusLanes;
public int MaximumBusLanes;
public int Reserved;
}
[StructLayout(LayoutKind.Sequential)]
private struct ADLFanSpeedValue
{
public int Size;
public int SpeedType;
public int FanSpeed;
public int Flags;
}
private static IntPtr Alloc(int size)
{
return Marshal.AllocHGlobal(size);
}
private static bool EnsureInitialized(out string message)
{
if (initialized)
{
message = "";
return true;
}
int status = ADL_Main_Control_Create(mallocCallback, 1);
if (status != ADL_OK)
{
message = "ADL init failed: " + status;
return false;
}
initialized = true;
message = "";
return true;
}
public static bool TryGetStats(out string name, out int tempC, out int utilization, out int engineClockMhz, out int memoryClockMhz, out int fanPercent, out string message)
{
name = "AMD Radeon";
tempC = 0;
utilization = 0;
engineClockMhz = 0;
memoryClockMhz = 0;
fanPercent = 0;
try
{
if (!EnsureInitialized(out message)) { return false; }
int adapterCount = 0;
int status = ADL_Adapter_NumberOfAdapters_Get(ref adapterCount);
if (status != ADL_OK || adapterCount <= 0)
{
message = "No ADL adapters";
return false;
}
int adapterSize = Marshal.SizeOf(typeof(ADLAdapterInfo));
IntPtr buffer = Marshal.AllocHGlobal(adapterSize * adapterCount);
int adapterIndex = -1;
try
{
status = ADL_Adapter_AdapterInfo_Get(buffer, adapterSize * adapterCount);
if (status != ADL_OK)
{
message = "ADL adapter query failed: " + status;
return false;
}
for (int i = 0; i < adapterCount; i++)
{
IntPtr itemPtr = new IntPtr(buffer.ToInt64() + (adapterSize * i));
ADLAdapterInfo info = (ADLAdapterInfo)Marshal.PtrToStructure(itemPtr, typeof(ADLAdapterInfo));
if (info.VendorID == 1002 || (info.AdapterName != null && info.AdapterName.ToUpperInvariant().Contains("RADEON")))
{
adapterIndex = info.AdapterIndex;
if (!String.IsNullOrWhiteSpace(info.AdapterName)) { name = info.AdapterName; }
break;
}
}
}
finally
{
Marshal.FreeHGlobal(buffer);
}
if (adapterIndex < 0)
{
message = "No AMD ADL adapter";
return false;
}
bool hasMetric = false;
ADLTemperature temp = new ADLTemperature();
temp.Size = Marshal.SizeOf(typeof(ADLTemperature));
if (ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref temp) == ADL_OK)
{
tempC = temp.Temperature / 1000;
hasMetric = true;
}
ADLPMActivity activity = new ADLPMActivity();
activity.Size = Marshal.SizeOf(typeof(ADLPMActivity));
if (ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref activity) == ADL_OK)
{
utilization = activity.ActivityPercent;
engineClockMhz = activity.EngineClock / 100;
memoryClockMhz = activity.MemoryClock / 100;
hasMetric = true;
}
ADLFanSpeedValue fan = new ADLFanSpeedValue();
fan.Size = Marshal.SizeOf(typeof(ADLFanSpeedValue));
fan.SpeedType = ADL_FAN_SPEED_TYPE_PERCENT;
if (ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref fan) == ADL_OK)
{
fanPercent = fan.FanSpeed;
hasMetric = true;
}
message = hasMetric ? "" : "ADL metrics unavailable";
return hasMetric;
}
catch (DllNotFoundException)
{
message = "atiadlxx.dll not found";
return false;
}
catch (EntryPointNotFoundException ex)
{
message = "ADL entry point missing: " + ex.Message;
return false;
}
catch (Exception ex)
{
message = "ADL error: " + ex.Message;
return false;
}
}
}
"@
try { Add-Type -TypeDefinition $nativeCode -ErrorAction SilentlyContinue } catch {}
$script:PhysicalMonitors = @()
$script:CurrentMonitorIndex = 0
$script:HasNvidia = $false
$script:HasAmd = $false
$script:HasCpuTempMonitor = $false
$script:NvidiaSmiPath = $null
$script:HardwareMonitorComputer = $null
$script:HardwareMonitorKind = $null
$script:PresentMonPath = $null
$script:FpsOverlayWindow = $null
$script:FpsOverlayText = $null
$script:FpsOverlayTimer = $null
$script:GpuTimer = $null
$script:AutoModeTimer = $null
$script:DefaultProfilesPath = "$env:APPDATA\MonitorControlPro"
$script:ProfileStorageSettingsPath = Join-Path $script:DefaultProfilesPath "profile-storage.json"
$script:ProfilesPath = $script:DefaultProfilesPath
$script:ProfileStorageMode = "Local"
if (-not (Test-Path $script:DefaultProfilesPath)) { New-Item -ItemType Directory -Path $script:DefaultProfilesPath -Force | Out-Null }
if (Test-Path $script:ProfileStorageSettingsPath) {
try {
$profileStorage = Get-Content -Path $script:ProfileStorageSettingsPath -Raw | ConvertFrom-Json
$configuredPath = [string]$profileStorage.ProfilePath
if (-not [string]::IsNullOrWhiteSpace($configuredPath)) {
$script:ProfilesPath = [System.IO.Path]::GetFullPath([Environment]::ExpandEnvironmentVariables($configuredPath))
$script:ProfileStorageMode = if ($profileStorage.Mode) { [string]$profileStorage.Mode } else { "Sync" }
}
} catch {
$script:ProfilesPath = $script:DefaultProfilesPath
$script:ProfileStorageMode = "Local"
}
}
$script:AppProfileRulesPath = Join-Path $script:ProfilesPath "app-profile-rules.json"
$script:ProfileScheduleRulesPath = Join-Path $script:ProfilesPath "profile-schedules.json"
$script:IdleDimSettingsPath = Join-Path $script:ProfilesPath "idle-dim.json"
$script:BatteryProfileSettingsPath = Join-Path $script:ProfilesPath "battery-profile.json"
$script:ProfileSchemaVersion = 2
$script:ProfileBundleSchemaVersion = 1
$script:ProfileExportsPath = Join-Path $script:ProfilesPath "exports"
$script:ProfileMetadataFiles = @("app-profile-rules.json", "profile-schedules.json", "idle-dim.json", "battery-profile.json", "profile-storage.json")
$script:UpdatingUI = $false
$script:ApplyToAll = $false
$script:AutoModeEnabled = $false
$script:WmiBrightnessAvailable = $false
$script:AmbientLightEnabled = $false
$script:AmbientLightSensor = $null
$script:AmbientLightTimer = $null
$script:AppProfileEnabled = $false
$script:AppProfileRules = @()
$script:AppProfileTimer = $null
$script:AppProfileCaptureTimer = $null
$script:UpdatingAppProfileUI = $false
$script:LastForegroundExe = $null
$script:LastAppliedAppProfileKey = $null
$script:ProfileScheduleEnabled = $false
$script:ProfileSchedules = @()
$script:ProfileScheduleTimer = $null
$script:UpdatingScheduleUI = $false
$script:LastAppliedScheduleKey = $null
$script:IdleDimEnabled = $false
$script:IdleDimMinutes = 10
$script:IdleDimBrightness = 20
$script:IdleDimRestoreOnActivity = $true
$script:IdleDimTimer = $null
$script:IdleDimActive = $false
$script:IdleDimPreviousBrightness = $null
$script:UpdatingIdleDimUI = $false
$script:BatteryProfileEnabled = $false
$script:BatteryBrightness = 35
$script:AcBrightness = 75
$script:BatteryProfileTimer = $null
$script:UpdatingBatteryProfileUI = $false
$script:LastPowerLineStatus = $null
$script:TrayIcon = $null
$script:TrayPopup = $null
$script:TrayBrightnessSlider = $null
$script:TrayBrightnessValue = $null
$script:TrayMonitorText = $null
$script:TrayLinkCheckbox = $null
$script:TrayLinkMenuItem = $null
$script:TrayPopupUpdating = $false
$script:TrayHasShownMinimizeTip = $false
$script:TraySuppressWindowStateEvent = $false
$script:IsQuitting = $false
$script:ProfileCycleIndex = -1
$script:VCPCodeDescriptions = @{
0x04 = "Factory Reset"; 0x08 = "Reset Color"; 0x10 = "Brightness"; 0x12 = "Contrast"
0x14 = "Color Preset"; 0x16 = "Red Gain"; 0x18 = "Green Gain"; 0x1A = "Blue Gain"
0x60 = "Input Source"; 0x62 = "Volume"; 0x72 = "Gamma"; 0x87 = "Sharpness"; 0x8D = "Mute"
0xC0 = "Display Usage Time"; 0xC6 = "Application Enable Key"; 0xCA = "OSD/Button Control"; 0xCC = "OSD Language"
0xCD = "Status Indicators / LED"; 0xD6 = "Power Mode"; 0xD7 = "Aux Power Output"; 0xDC = "Display Mode"; 0xDF = "VCP Version"
0xE8 = "Secondary Input Source"; 0xE9 = "PiP/PbP Mode"
}
function Get-Monitors {
$script:PhysicalMonitors = @()
$monitorHandles = [MonitorAPI]::GetAllMonitorHandles()
$monitorIndex = 1
$displayDevices = @{}
$devNum = 0
$device = New-Object MonitorAPI+DISPLAY_DEVICE
$device.cb = [System.Runtime.InteropServices.Marshal]::SizeOf($device)
while ([MonitorAPI]::EnumDisplayDevices($null, $devNum, [ref]$device, 0)) {
if ($device.StateFlags -band [MonitorAPI]::DISPLAY_DEVICE_ACTIVE) { $displayDevices[$device.DeviceName] = $device.DeviceString }
$devNum++
}
foreach ($hMonitor in $monitorHandles) {
$numMons = [uint32]0
if ([MonitorAPI]::GetNumberOfPhysicalMonitorsFromHMONITOR($hMonitor, [ref]$numMons) -and $numMons -gt 0) {
$physMons = New-Object MonitorAPI+PHYSICAL_MONITOR[] $numMons
if ([MonitorAPI]::GetPhysicalMonitorsFromHMONITOR($hMonitor, $numMons, $physMons)) {
foreach ($pm in $physMons) {
$monInfo = New-Object MonitorAPI+MONITORINFOEX
$monInfo.Size = [System.Runtime.InteropServices.Marshal]::SizeOf($monInfo)
if ([MonitorAPI]::GetMonitorInfo($hMonitor, [ref]$monInfo)) {
$devMode = New-Object MonitorAPI+DEVMODE
$devMode.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($devMode)
[MonitorAPI]::EnumDisplaySettingsEx($monInfo.DeviceName, [MonitorAPI]::ENUM_CURRENT_SETTINGS, [ref]$devMode, 0) | Out-Null
$name = if ($pm.szPhysicalMonitorDescription) { $pm.szPhysicalMonitorDescription } else {
if ($displayDevices.ContainsKey($monInfo.DeviceName)) { $displayDevices[$monInfo.DeviceName] } else { "Monitor $monitorIndex" }
}
$capabilities = ""
try {
$capLen = [uint32]0
if ([MonitorAPI]::GetCapabilitiesStringLength($pm.hPhysicalMonitor, [ref]$capLen) -and $capLen -gt 0) {
$capStr = New-Object System.Text.StringBuilder -ArgumentList ([int]$capLen)
if ([MonitorAPI]::CapabilitiesRequestAndCapabilitiesReply($pm.hPhysicalMonitor, $capStr, $capLen)) { $capabilities = $capStr.ToString() }
}
} catch {}
$script:PhysicalMonitors += [PSCustomObject]@{
Handle = $pm.hPhysicalMonitor; HMonitor = $hMonitor; Name = $name; Index = $monitorIndex
DeviceName = $monInfo.DeviceName; Width = $devMode.dmPelsWidth; Height = $devMode.dmPelsHeight
RefreshRate = $devMode.dmDisplayFrequency; IsPrimary = ($monInfo.Flags -band [MonitorAPI]::MONITORINFOF_PRIMARY) -ne 0
Left = $monInfo.Monitor.Left; Top = $monInfo.Monitor.Top; Right = $monInfo.Monitor.Right
Bottom = $monInfo.Monitor.Bottom; Capabilities = $capabilities
}
$monitorIndex++
}
}
}
}
}
if ($script:PhysicalMonitors.Count -eq 0) {
$fallbackName = if ($script:WmiBrightnessAvailable) { "Integrated Laptop Display" } else { "No DDC/CI Monitor" }
$fallbackDevice = if ($script:WmiBrightnessAvailable) { "WMI" } else { "" }
$script:PhysicalMonitors += [PSCustomObject]@{
Handle = [IntPtr]::Zero; HMonitor = [IntPtr]::Zero; Name = $fallbackName; Index = 1
DeviceName = $fallbackDevice; Width = 1920; Height = 1080; RefreshRate = 60; IsPrimary = $true
Left = 0; Top = 0; Right = 1920; Bottom = 1080; Capabilities = ""
}
}
}
function Get-VCPValue {
param([IntPtr]$Handle, [byte]$VCPCode)
$vct = [uint32]0; $cur = [uint32]0; $max = [uint32]0
$result = [MonitorAPI]::GetVCPFeatureAndVCPFeatureReply($Handle, $VCPCode, [ref]$vct, [ref]$cur, [ref]$max)
return @{ Success = $result; Current = $cur; Maximum = $max; Type = $vct }
}
function Set-VCPValue {
param([IntPtr]$Handle, [byte]$VCPCode, [uint32]$Value)
return [MonitorAPI]::SetVCPFeature($Handle, $VCPCode, $Value)
}
function Set-VCPValueWithSync {
param([byte]$VCPCode, [uint32]$Value, [switch]$Force)
if ($script:ApplyToAll -or $Force) {
foreach ($mon in $script:PhysicalMonitors) {
if ($mon.Handle -ne [IntPtr]::Zero) { Set-VCPValue -Handle $mon.Handle -VCPCode $VCPCode -Value $Value | Out-Null; Start-Sleep -Milliseconds 50 }
}
if ($VCPCode -eq [MonitorAPI]::VCP_BRIGHTNESS -and $script:WmiBrightnessAvailable) { Set-WmiBrightness -Value $Value | Out-Null }
} else {
$mon = $script:PhysicalMonitors[$script:CurrentMonitorIndex]
if ($mon.Handle -ne [IntPtr]::Zero) { Set-VCPValue -Handle $mon.Handle -VCPCode $VCPCode -Value $Value | Out-Null }
elseif ($VCPCode -eq [MonitorAPI]::VCP_BRIGHTNESS -and $script:WmiBrightnessAvailable) { Set-WmiBrightness -Value $Value | Out-Null }
}
}
function Set-GammaRamp {
param([double]$Gamma = 1.0, [double]$RedMult = 1.0, [double]$GreenMult = 1.0, [double]$BlueMult = 1.0)
$hdc = [MonitorAPI]::GetDC([IntPtr]::Zero)
if ($hdc -eq [IntPtr]::Zero) { return }
try {
$ramp = New-Object MonitorAPI+RAMP
$ramp.Red = [UInt16[]]::new(256); $ramp.Green = [UInt16[]]::new(256); $ramp.Blue = [UInt16[]]::new(256)
for ($i = 0; $i -lt 256; $i++) {
$normalized = $i / 255.0
$ramp.Red[$i] = [Math]::Min(65535, [Math]::Max(0, [int]([Math]::Pow($normalized, 1.0/$Gamma) * 65535 * $RedMult)))
$ramp.Green[$i] = [Math]::Min(65535, [Math]::Max(0, [int]([Math]::Pow($normalized, 1.0/$Gamma) * 65535 * $GreenMult)))
$ramp.Blue[$i] = [Math]::Min(65535, [Math]::Max(0, [int]([Math]::Pow($normalized, 1.0/$Gamma) * 65535 * $BlueMult)))
}
[MonitorAPI]::SetDeviceGammaRamp($hdc, [ref]$ramp) | Out-Null
} finally { [MonitorAPI]::ReleaseDC([IntPtr]::Zero, $hdc) | Out-Null }
}
function Get-TimeBasedSettings {
$hour = (Get-Date).Hour
if ($hour -ge 7 -and $hour -lt 18) { return @{ Mode = "Day"; Brightness = 80; GammaRed = 1.0; GammaGreen = 1.0; GammaBlue = 1.0 } }
elseif ($hour -ge 18 -and $hour -lt 21) { return @{ Mode = "Evening"; Brightness = 60; GammaRed = 1.0; GammaGreen = 0.95; GammaBlue = 0.85 } }
else { return @{ Mode = "Night"; Brightness = 40; GammaRed = 1.0; GammaGreen = 0.9; GammaBlue = 0.75 } }
}
function Apply-TimeBasedSettings {
$settings = Get-TimeBasedSettings
foreach ($mon in $script:PhysicalMonitors) {
if ($mon.Handle -ne [IntPtr]::Zero) { Set-VCPValue -Handle $mon.Handle -VCPCode ([MonitorAPI]::VCP_BRIGHTNESS) -Value $settings.Brightness | Out-Null; Start-Sleep -Milliseconds 50 }
}
if ($script:WmiBrightnessAvailable) { Set-WmiBrightness -Value $settings.Brightness | Out-Null }
Set-GammaRamp -Gamma 1.0 -RedMult $settings.GammaRed -GreenMult $settings.GammaGreen -BlueMult $settings.GammaBlue
return $settings
}
function Initialize-WmiBrightness {
try {
$script:WmiBrightnessAvailable = @(
Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightness -ErrorAction Stop
).Count -gt 0
} catch {
$script:WmiBrightnessAvailable = $false
}
}
function Get-WmiBrightness {
try {
$level = Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightness -ErrorAction Stop | Select-Object -First 1
if ($level -and $null -ne $level.CurrentBrightness) { return [int]$level.CurrentBrightness }
} catch {}
return $null
}
function Set-WmiBrightness {
param([int]$Value)
if (-not $script:WmiBrightnessAvailable) { return $false }
$brightness = [Math]::Max(0, [Math]::Min(100, $Value))
try {
$methods = Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods -ErrorAction Stop
foreach ($method in $methods) {
Invoke-CimMethod -InputObject $method -MethodName WmiSetBrightness -Arguments @{ Timeout = 1; Brightness = $brightness } -ErrorAction Stop | Out-Null
}
return $true
} catch {
Update-Status "WMI brightness failed: $_"
return $false
}
}
function Initialize-AmbientLightSensor {
if ($script:AmbientLightSensor) { return $true }
try {
[void][Windows.Devices.Sensors.LightSensor, Windows.Devices.Sensors, ContentType = WindowsRuntime]
$sensor = [Windows.Devices.Sensors.LightSensor]::GetDefault()
if ($sensor) {
$script:AmbientLightSensor = $sensor
return $true
}
} catch {}
return $false
}
function Get-AmbientLux {
if (-not (Initialize-AmbientLightSensor)) { return $null }
try {
$reading = $script:AmbientLightSensor.GetCurrentReading()
if ($reading -and $null -ne $reading.IlluminanceInLux) { return [double]$reading.IlluminanceInLux }
} catch {}
return $null
}
function Get-BrightnessForAmbientLux {
param([double]$Lux)
if ($Lux -lt 20) { return 25 }
if ($Lux -lt 100) { return 40 }
if ($Lux -lt 300) { return 55 }
if ($Lux -lt 800) { return 70 }
return 85
}
function Apply-AmbientLightSettings {
$lux = Get-AmbientLux
if ($null -eq $lux) {
$autoModeText.Text = "Ambient unavailable"
Update-Status "Ambient light sensor unavailable"
return
}
$brightness = Get-BrightnessForAmbientLux -Lux $lux
Set-VCPValueWithSync -VCPCode ([MonitorAPI]::VCP_BRIGHTNESS) -Value $brightness -Force
$script:UpdatingUI = $true
$brightnessSlider.Value = $brightness; $brightnessValue.Text = $brightness
$script:UpdatingUI = $false
$autoModeText.Text = "Ambient: $([math]::Round($lux, 0)) lx"
Update-Status "Ambient brightness: $brightness"
}
function Start-AmbientLightWatcher {
if (-not $script:AmbientLightEnabled) {
if ($script:AmbientLightTimer) { $script:AmbientLightTimer.Stop() }
return
}
if (-not (Initialize-AmbientLightSensor)) {
$script:AmbientLightEnabled = $false
$autoModeText.Text = ""
Update-Status "Ambient light sensor unavailable"
return
}
if (-not $script:AmbientLightTimer) {
$script:AmbientLightTimer = New-Object System.Windows.Threading.DispatcherTimer
$script:AmbientLightTimer.Interval = [TimeSpan]::FromSeconds(30)
$script:AmbientLightTimer.Add_Tick({ if ($script:AmbientLightEnabled) { Apply-AmbientLightSettings } })
}
$script:AmbientLightTimer.Start()
Apply-AmbientLightSettings
}
function Initialize-GPU {
$gpus = Get-CimInstance -ClassName Win32_VideoController -ErrorAction SilentlyContinue
foreach ($gpu in $gpus) {
if ($gpu.Name -match "NVIDIA") {
$script:HasNvidia = $true
@("${env:ProgramFiles}\NVIDIA Corporation\NVSMI\nvidia-smi.exe", "${env:SystemRoot}\System32\nvidia-smi.exe") | ForEach-Object { if (Test-Path $_) { $script:NvidiaSmiPath = $_; return } }
}
if ($gpu.Name -match "AMD|Radeon") {
$script:HasAmd = $true
}
}
}
function Get-NvidiaStats {
if (-not $script:NvidiaSmiPath) { return $null }
try {
$output = & $script:NvidiaSmiPath --query-gpu=name,temperature.gpu,utilization.gpu,memory.used,memory.total,fan.speed,power.draw,power.limit,clocks.gr --format=csv,noheader,nounits 2>$null
if ($output) {
$p = $output.Split(',').Trim()
if ($p.Count -ge 9) {
return @{ Name = $p[0]; Temp = [int]$p[1]; Util = [int]$p[2]; MemUsed = [math]::Round([double]$p[3]/1024, 1)
MemTotal = [math]::Round([double]$p[4]/1024, 1); Fan = if ($p[5] -match '\d+') { [int]$p[5] } else { 0 }
Power = [math]::Round([double]$p[6], 0); PowerLimit = [math]::Round([double]$p[7], 0); Clock = [int]$p[8] }
}
}
} catch {}
return $null
}
function Get-AmdStats {
$name = ""; $temp = 0; $util = 0; $engineClock = 0; $memoryClock = 0; $fan = 0; $message = ""
if ([AmdAdlInterop]::TryGetStats([ref]$name, [ref]$temp, [ref]$util, [ref]$engineClock, [ref]$memoryClock, [ref]$fan, [ref]$message)) {
return @{
Name = $name; Temp = $temp; Util = $util; MemUsed = 0; MemTotal = 0; Fan = $fan
Power = 0; PowerLimit = 0; Clock = $engineClock; MemoryClock = $memoryClock; Message = ""
}
}
return @{ Name = "AMD Radeon"; Temp = 0; Util = 0; MemUsed = 0; MemTotal = 0; Fan = 0; Power = 0; PowerLimit = 0; Clock = 0; MemoryClock = 0; Message = $message }
}
function Initialize-CpuMonitor {
$candidatePaths = @(
(Join-Path $PSScriptRoot "LibreHardwareMonitorLib.dll"),
(Join-Path $PSScriptRoot "OpenHardwareMonitorLib.dll"),
"${env:ProgramFiles}\LibreHardwareMonitor\LibreHardwareMonitorLib.dll",
"${env:ProgramFiles}\OpenHardwareMonitor\OpenHardwareMonitorLib.dll",
"${env:ProgramFiles(x86)}\LibreHardwareMonitor\LibreHardwareMonitorLib.dll",
"${env:ProgramFiles(x86)}\OpenHardwareMonitor\OpenHardwareMonitorLib.dll"
) | Where-Object { $_ -and (Test-Path $_) }
foreach ($path in $candidatePaths) {
try {
[System.Reflection.Assembly]::LoadFrom($path) | Out-Null
$computerType = if ($path -like "*LibreHardwareMonitor*") {
[Type]::GetType("LibreHardwareMonitor.Hardware.Computer, LibreHardwareMonitorLib", $false)
} else {
[Type]::GetType("OpenHardwareMonitor.Hardware.Computer, OpenHardwareMonitorLib", $false)
}
if (-not $computerType) { continue }
$computer = [Activator]::CreateInstance($computerType)
$computer.IsCpuEnabled = $true
$computer.Open()
$script:HardwareMonitorComputer = $computer
$script:HardwareMonitorKind = if ($path -like "*LibreHardwareMonitor*") { "LibreHardwareMonitor" } else { "OpenHardwareMonitor" }
$script:HasCpuTempMonitor = $true
return
} catch {}
}
}
function Get-CpuTemperature {
if (-not $script:HardwareMonitorComputer) { return $null }
try {
$temperatures = @()
foreach ($hardware in $script:HardwareMonitorComputer.Hardware) {
if ($hardware.HardwareType.ToString() -ne "Cpu") { continue }
$hardware.Update()
foreach ($subHardware in $hardware.SubHardware) { $subHardware.Update() }
foreach ($sensor in @($hardware.Sensors) + @($hardware.SubHardware | ForEach-Object { $_.Sensors })) {
if ($sensor -and $sensor.SensorType.ToString() -eq "Temperature" -and $null -ne $sensor.Value) {
$temperatures += [double]$sensor.Value
}
}
}
if ($temperatures.Count -gt 0) { return [math]::Round(($temperatures | Measure-Object -Maximum).Maximum, 0) }
} catch {}
return $null
}
try {
if (-not (Test-Path $script:ProfilesPath)) { New-Item -ItemType Directory -Path $script:ProfilesPath -Force | Out-Null }
} catch {
$script:ProfilesPath = $script:DefaultProfilesPath
$script:ProfileStorageMode = "Local"
$script:AppProfileRulesPath = Join-Path $script:ProfilesPath "app-profile-rules.json"
$script:ProfileScheduleRulesPath = Join-Path $script:ProfilesPath "profile-schedules.json"
$script:IdleDimSettingsPath = Join-Path $script:ProfilesPath "idle-dim.json"
$script:BatteryProfileSettingsPath = Join-Path $script:ProfilesPath "battery-profile.json"
$script:ProfileExportsPath = Join-Path $script:ProfilesPath "exports"
if (-not (Test-Path $script:ProfilesPath)) { New-Item -ItemType Directory -Path $script:ProfilesPath -Force | Out-Null }
}
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MonitorControl Pro v3.19.0" Width="640" Height="680" MinWidth="560" MinHeight="560"
Background="#0a0a0a" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip">
<Window.Resources>
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
<Grid><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition Width="20"/></Grid.ColumnDefinitions>
<Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="5" Background="#1a1a1a" BorderBrush="#333" BorderThickness="1"/>
<Path Grid.Column="1" Fill="#808080" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="Border" Property="Background" Value="#262626"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="#e0e0e0"/><Setter Property="FontFamily" Value="Segoe UI"/><Setter Property="Height" Value="28"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ComboBox"><Grid>
<ToggleButton Template="{StaticResource ComboBoxToggleButton}" Focusable="False" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
<ContentPresenter IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" Margin="10,0,28,0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<Popup Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
<Border Background="#1a1a1a" BorderThickness="1" BorderBrush="#333" CornerRadius="5" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="200" Margin="0,2,0,0">
<ScrollViewer VerticalScrollBarVisibility="Auto"><ItemsPresenter/></ScrollViewer></Border>
</Popup></Grid></ControlTemplate></Setter.Value></Setter>
</Style>
<Style TargetType="ComboBoxItem">
<Setter Property="Foreground" Value="#e0e0e0"/><Setter Property="Padding" Value="8,5"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ComboBoxItem">
<Border x:Name="Bd" Background="Transparent" Padding="{TemplateBinding Padding}" CornerRadius="3"><ContentPresenter/></Border>
<ControlTemplate.Triggers><Trigger Property="IsHighlighted" Value="True"><Setter TargetName="Bd" Property="Background" Value="#0078d4"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="Btn" TargetType="Button">
<Setter Property="Background" Value="#1a1a1a"/><Setter Property="Foreground" Value="#d0d0d0"/><Setter Property="BorderBrush" Value="#333"/>
<Setter Property="BorderThickness" Value="1"/><Setter Property="Padding" Value="10,6"/><Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontSize" Value="11"/><Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
<Border x:Name="bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="5" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bd" Property="Background" Value="#262626"/></Trigger>
<Trigger Property="IsPressed" Value="True"><Setter TargetName="bd" Property="Background" Value="#333"/></Trigger>
</ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="AccBtn" TargetType="Button" BasedOn="{StaticResource Btn}">
<Setter Property="Background" Value="#0078d4"/><Setter Property="BorderBrush" Value="#0078d4"/><Setter Property="Foreground" Value="#fff"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
<Border x:Name="bd" Background="{TemplateBinding Background}" BorderThickness="1" CornerRadius="5" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border>
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bd" Property="Background" Value="#1a88e0"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="WarnBtn" TargetType="Button" BasedOn="{StaticResource Btn}">
<Setter Property="Background" Value="#c44"/><Setter Property="BorderBrush" Value="#c44"/><Setter Property="Foreground" Value="#fff"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
<Border x:Name="bd" Background="{TemplateBinding Background}" BorderThickness="1" CornerRadius="5" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border>
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bd" Property="Background" Value="#d55"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="GreenBtn" TargetType="Button" BasedOn="{StaticResource Btn}">
<Setter Property="Background" Value="#2a9d4a"/><Setter Property="BorderBrush" Value="#2a9d4a"/><Setter Property="Foreground" Value="#fff"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
<Border x:Name="bd" Background="{TemplateBinding Background}" BorderThickness="1" CornerRadius="5" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border>
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bd" Property="Background" Value="#33b85a"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="OrangeBtn" TargetType="Button" BasedOn="{StaticResource Btn}">
<Setter Property="Background" Value="#e67e22"/><Setter Property="BorderBrush" Value="#e67e22"/><Setter Property="Foreground" Value="#fff"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
<Border x:Name="bd" Background="{TemplateBinding Background}" BorderThickness="1" CornerRadius="5" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border>
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bd" Property="Background" Value="#f39c12"/></Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style x:Key="Sld" TargetType="Slider">
<Setter Property="Height" Value="18"/><Setter Property="Minimum" Value="0"/><Setter Property="Maximum" Value="100"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Slider">
<Grid VerticalAlignment="Center">
<Border Height="4" Background="#1f1f1f" CornerRadius="2"/>
<Track x:Name="PART_Track">
<Track.DecreaseRepeatButton><RepeatButton Command="Slider.DecreaseLarge"><RepeatButton.Template>
<ControlTemplate><Border Background="{Binding Tag, RelativeSource={RelativeSource AncestorType=Slider}}" CornerRadius="2" Height="4"/></ControlTemplate>
</RepeatButton.Template></RepeatButton></Track.DecreaseRepeatButton>
<Track.Thumb><Thumb><Thumb.Template><ControlTemplate><Grid><Ellipse Width="14" Height="14" Fill="#fff"/><Ellipse Width="5" Height="5" Fill="#0a0a0a"/></Grid></ControlTemplate></Thumb.Template></Thumb></Track.Thumb>
<Track.IncreaseRepeatButton><RepeatButton Command="Slider.IncreaseLarge"><RepeatButton.Template><ControlTemplate><Border Background="Transparent"/></ControlTemplate></RepeatButton.Template></RepeatButton></Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style TargetType="TabControl"><Setter Property="Background" Value="Transparent"/><Setter Property="BorderThickness" Value="0"/></Style>
<Style TargetType="TabItem">
<Setter Property="Foreground" Value="#707070"/><Setter Property="FontFamily" Value="Segoe UI"/><Setter Property="FontSize" Value="11"/><Setter Property="Padding" Value="10,6"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="TabItem">
<Border x:Name="Bd" Background="Transparent" Padding="{TemplateBinding Padding}" CornerRadius="5,5,0,0">
<ContentPresenter ContentSource="Header" HorizontalAlignment="Center"/></Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True"><Setter TargetName="Bd" Property="Background" Value="#151515"/><Setter Property="Foreground" Value="#fff"/></Trigger>
<Trigger Property="IsMouseOver" Value="True"><Setter TargetName="Bd" Property="Background" Value="#1a1a1a"/></Trigger>
</ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="#d0d0d0"/><Setter Property="FontFamily" Value="Segoe UI"/><Setter Property="FontSize" Value="11"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="CheckBox">
<StackPanel Orientation="Horizontal">
<Border x:Name="cb" Width="16" Height="16" Background="#1a1a1a" BorderBrush="#444" BorderThickness="1" CornerRadius="3" Margin="0,0,6,0">
<Path x:Name="cm" Data="M 2 5 L 5 8 L 12 1" Stroke="#fff" StrokeThickness="2" Visibility="Collapsed" Margin="1"/></Border>
<ContentPresenter VerticalAlignment="Center"/>
</StackPanel>
<ControlTemplate.Triggers><Trigger Property="IsChecked" Value="True">
<Setter TargetName="cb" Property="Background" Value="#0078d4"/><Setter TargetName="cb" Property="BorderBrush" Value="#0078d4"/>
<Setter TargetName="cm" Property="Visibility" Value="Visible"/>
</Trigger></ControlTemplate.Triggers>
</ControlTemplate></Setter.Value></Setter>
</Style>
<Style TargetType="ProgressBar">
<Setter Property="Height" Value="5"/><Setter Property="Background" Value="#1f1f1f"/><Setter Property="Foreground" Value="#0078d4"/><Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ProgressBar"><Grid>
<Border Background="{TemplateBinding Background}" CornerRadius="3"/><Border x:Name="PART_Track"/>
<Border x:Name="PART_Indicator" Background="{TemplateBinding Foreground}" CornerRadius="3" HorizontalAlignment="Left"/>
</Grid></ControlTemplate></Setter.Value></Setter>
</Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="#1a1a1a"/><Setter Property="Foreground" Value="#e0e0e0"/><Setter Property="BorderBrush" Value="#333"/>
<Setter Property="BorderThickness" Value="1"/><Setter Property="Padding" Value="6,4"/><Setter Property="FontFamily" Value="Segoe UI"/><Setter Property="CaretBrush" Value="#fff"/>
</Style>
</Window.Resources>
<Grid Margin="12,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/>
<RowDefinition Height="8"/><RowDefinition Height="*"/><RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions><ColumnDefinition Width="Auto"/><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
<StackPanel VerticalAlignment="Center">
<TextBlock Text="MonitorControl Pro" FontSize="16" FontWeight="SemiBold" Foreground="#fff" FontFamily="Segoe UI"/>
<TextBlock Text="v3.19.0 - Click monitor to select" FontSize="9" Foreground="#505050" Margin="0,1,0,0"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<CheckBox x:Name="ApplyAllCheckbox" Content="All Monitors" VerticalAlignment="Center" Margin="0,0,10,0"/>
<Button x:Name="IdentifyBtn" Content="Identify" Style="{StaticResource Btn}" Padding="8,5" Margin="0,0,4,0"/>
<Button x:Name="RefreshBtn" Content="Refresh" Style="{StaticResource Btn}" Padding="8,5"/>
</StackPanel>
</Grid>
<Border Grid.Row="2" Background="#111" CornerRadius="6" Padding="10,8">
<Grid>
<Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
<Canvas x:Name="MonitorCanvas" Height="65" ClipToBounds="True"/>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="10,0,0,0" MinWidth="130">
<TextBlock x:Name="SelectedMonitorName" Text="No Monitor" FontSize="11" Foreground="#fff" FontWeight="SemiBold"/>
<TextBlock x:Name="SelectedMonitorRes" FontSize="9" Foreground="#707070" Margin="0,1,0,0"/>
<TextBlock x:Name="SelectedMonitorInfo" FontSize="8" Foreground="#505050" Margin="0,1,0,0"/>
</StackPanel>
</Grid>
</Border>
<TabControl Grid.Row="4">
<TabItem Header="Display">
<Border Background="#151515" CornerRadius="0,5,5,5" Padding="10"><ScrollViewer VerticalScrollBarVisibility="Auto"><Grid>
<Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/><RowDefinition Height="8"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="8"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions>
<Border Background="#1a1a1a" CornerRadius="5" Padding="10,8"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="5"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><TextBlock Text="Brightness" FontSize="10" Foreground="#909090"/><TextBlock x:Name="BrightnessValue" Text="50" FontSize="10" Foreground="#fff" FontWeight="SemiBold" HorizontalAlignment="Right"/></Grid>
<Slider x:Name="BrightnessSlider" Grid.Row="2" Value="50" Tag="#f5b800" Style="{StaticResource Sld}"/>
</Grid></Border>
<Border Grid.Column="2" Background="#1a1a1a" CornerRadius="5" Padding="10,8"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="5"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><TextBlock Text="Contrast" FontSize="10" Foreground="#909090"/><TextBlock x:Name="ContrastValue" Text="50" FontSize="10" Foreground="#fff" FontWeight="SemiBold" HorizontalAlignment="Right"/></Grid>
<Slider x:Name="ContrastSlider" Grid.Row="2" Value="50" Tag="#888" Style="{StaticResource Sld}"/>
</Grid></Border>
</Grid>
<Grid Grid.Row="2"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="5"/><ColumnDefinition Width="*"/><ColumnDefinition Width="5"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions>
<Border Background="#1a1a1a" CornerRadius="5" Padding="8,6"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="4"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><TextBlock Text="Red" FontSize="9" Foreground="#e85050"/><TextBlock x:Name="RedValue" Text="50" FontSize="9" Foreground="#fff" FontWeight="SemiBold" HorizontalAlignment="Right"/></Grid>
<Slider x:Name="RedSlider" Grid.Row="2" Value="50" Tag="#e85050" Style="{StaticResource Sld}"/>
</Grid></Border>
<Border Grid.Column="2" Background="#1a1a1a" CornerRadius="5" Padding="8,6"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="4"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><TextBlock Text="Green" FontSize="9" Foreground="#45c770"/><TextBlock x:Name="GreenValue" Text="50" FontSize="9" Foreground="#fff" FontWeight="SemiBold" HorizontalAlignment="Right"/></Grid>
<Slider x:Name="GreenSlider" Grid.Row="2" Value="50" Tag="#45c770" Style="{StaticResource Sld}"/>
</Grid></Border>
<Border Grid.Column="4" Background="#1a1a1a" CornerRadius="5" Padding="8,6"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="4"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid><TextBlock Text="Blue" FontSize="9" Foreground="#4a90e8"/><TextBlock x:Name="BlueValue" Text="50" FontSize="9" Foreground="#fff" FontWeight="SemiBold" HorizontalAlignment="Right"/></Grid>
<Slider x:Name="BlueSlider" Grid.Row="2" Value="50" Tag="#4a90e8" Style="{StaticResource Sld}"/>
</Grid></Border>