mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using WindowsDisplayAPI;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GHelper.Display
|
||||
{
|
||||
@@ -24,32 +24,24 @@ namespace GHelper.Display
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveGamma()
|
||||
{
|
||||
var display = WindowsDisplayAPI.Display.GetDisplays().Where(x => x.DisplayScreen.IsPrimary).FirstOrDefault();
|
||||
if (display is null) return;
|
||||
|
||||
gamma = display.GammaRamp;
|
||||
|
||||
Logger.WriteLine("R:" + string.Join("-", display.GammaRamp.Red));
|
||||
Logger.WriteLine("G:" + string.Join("-", display.GammaRamp.Green));
|
||||
Logger.WriteLine("B:" + string.Join("-", display.GammaRamp.Blue));
|
||||
}
|
||||
|
||||
public void RestoreGamma()
|
||||
{
|
||||
var display = WindowsDisplayAPI.Display.GetDisplays().Where(x => x.DisplayScreen.IsPrimary).FirstOrDefault();
|
||||
if (gamma is not null) display!.GammaRamp = gamma;
|
||||
}
|
||||
|
||||
public void SetGamma(int brightness = 100, int contrast = 100)
|
||||
{
|
||||
var display = WindowsDisplayAPI.Display.GetDisplays().Where(x => x.DisplayScreen.IsPrimary).FirstOrDefault();
|
||||
var bright = (float)(brightness) / 100;
|
||||
|
||||
Logger.WriteLine("Brightness: " + bright.ToString());
|
||||
|
||||
display!.GammaRamp = new DisplayGammaRamp(bright, bright, 1);
|
||||
var screenName = ScreenNative.FindLaptopScreen();
|
||||
if (screenName is null) return;
|
||||
|
||||
try
|
||||
{
|
||||
var handle = ScreenNative.CreateDC(screenName, screenName, null, IntPtr.Zero);
|
||||
var gammaRamp = new DisplayGammaRamp(bright, bright, 1).AsRamp();
|
||||
ScreenNative.SetDeviceGammaRamp(handle, ref gammaRamp);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
//ScreenBrightness.Set(60 + (int)(40 * bright));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user