mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-04 22:07:40 +00:00
Add ExternalHelpers project and move all externally acquired dependencies there
This commit is contained in:
parent
b06ac16fba
commit
e376b9dcc8
24 changed files with 457 additions and 574 deletions
55
ExternalHelpers/WindowsSettingsBrightnessController.cs
Normal file
55
ExternalHelpers/WindowsSettingsBrightnessController.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PowerControl.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Taken from: https://gist.github.com/maxkoshevoi/b8a1ad91f4d2a9fd3931168c14080694
|
||||
/// </summary>
|
||||
public static class WindowsSettingsBrightnessController
|
||||
{
|
||||
public static int Get(double roundValue = 10.0)
|
||||
{
|
||||
return (int)(Math.Round(Get() / roundValue) * roundValue);
|
||||
}
|
||||
|
||||
public static int Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var mclass = new ManagementClass("WmiMonitorBrightness")
|
||||
{
|
||||
Scope = new ManagementScope(@"\\.\root\wmi")
|
||||
};
|
||||
using var instances = mclass.GetInstances();
|
||||
foreach (ManagementObject instance in instances)
|
||||
{
|
||||
return (byte)instance.GetPropertyValue("CurrentBrightness");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Set(int brightness)
|
||||
{
|
||||
using var mclass = new ManagementClass("WmiMonitorBrightnessMethods")
|
||||
{
|
||||
Scope = new ManagementScope(@"\\.\root\wmi")
|
||||
};
|
||||
using var instances = mclass.GetInstances();
|
||||
var args = new object[] { 1, brightness };
|
||||
foreach (ManagementObject instance in instances)
|
||||
{
|
||||
instance.InvokeMethod("WmiSetBrightness", args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue