Skip to content

Commit 6b11dd4

Browse files
committed
Add option to bind AC and DC power
1 parent b1d94fd commit 6b11dd4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Source/Monitorian.Core/Models/Monitor/MonitorManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public BasicItem(
4646
#region Options
4747

4848
public static IReadOnlyCollection<string> Options => (new[] { PrecludeOption, PreclearOption })
49+
.Concat(PowerManagement.Options)
4950
.Concat(BrightnessConnector.Options)
5051
.Concat(DisplayInformationWatcher.Options)
5152
.ToArray();

Source/Monitorian.Core/Models/Monitor/PowerManagement.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ private struct SYSTEM_POWER_STATUS
9090
// AC/DC power source derived from winnt.h
9191
private static readonly Guid ACDC_POWER_SOURCE = new("5d3e9a59-e9d5-4b00-a6bd-ff34ff516548");
9292

93+
/// <summary>
94+
/// Options
95+
/// </summary>
96+
public static IReadOnlyCollection<string> Options => new[] { PowerBindOption };
97+
98+
private const string PowerBindOption = "/powerbind";
99+
100+
public static bool IsBound => _isBound.Value;
101+
private static readonly Lazy<bool> _isBound = new(() =>
102+
{
103+
return AppKeeper.StandardArguments.Select(x => x.ToLower()).Contains(PowerBindOption);
104+
});
105+
93106
public static Guid GetActiveScheme()
94107
{
95108
if (PowerGetActiveScheme(
@@ -330,7 +343,7 @@ public static bool SetActiveSchemeBrightness(int brightness)
330343

331344
var schemeGuid = GetActiveScheme();
332345

333-
if (isOnline.Value)
346+
if (isOnline.Value || IsBound)
334347
{
335348
if (PowerWriteACValueIndex(
336349
IntPtr.Zero,
@@ -343,7 +356,7 @@ public static bool SetActiveSchemeBrightness(int brightness)
343356
return false;
344357
}
345358
}
346-
else
359+
if (!isOnline.Value || IsBound)
347360
{
348361
if (PowerWriteDCValueIndex(
349362
IntPtr.Zero,

0 commit comments

Comments
 (0)