mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Add Delay to Screenpad Actions (#2305)
* Add Delay to Screenpad Actions Added "screenpad_delay" config * revert .net version revert .net version
This commit is contained in:
@@ -809,14 +809,14 @@ namespace GHelper.Input
|
||||
public static void ToggleScreenpad()
|
||||
{
|
||||
int toggle = AppConfig.Is("screenpad_toggle") ? 0 : 1;
|
||||
int brightness = AppConfig.Get("screenpad", 100);
|
||||
int brightness = toggle == 0 ? -10 : AppConfig.Get("screenpad", 100);
|
||||
|
||||
Program.acpi.DeviceSet(AsusACPI.ScreenPadToggle, toggle, "ScreenpadToggle");
|
||||
if (toggle > 0) Program.acpi.DeviceSet(AsusACPI.ScreenPadBrightness, Math.Max(brightness * 255 / 100, 0), "Screenpad");
|
||||
Debug.WriteLine($"Screenpad toggle = {toggle}");
|
||||
|
||||
ApplyScreenpadAction(brightness, true);
|
||||
|
||||
AppConfig.Set("screenpad_toggle", toggle);
|
||||
|
||||
|
||||
Program.toast.RunToast($"Screen Pad " + (toggle == 1 ? "On" : "Off"), toggle > 0 ? ToastIcon.BrightnessUp : ToastIcon.BrightnessDown);
|
||||
}
|
||||
|
||||
@@ -851,6 +851,37 @@ namespace GHelper.Input
|
||||
|
||||
}
|
||||
|
||||
private static System.Threading.Timer screenpadActionTimer;
|
||||
private static int screenpadBrightnessToSet;
|
||||
public static void ApplyScreenpadAction(int brightness, bool doToggle = false)
|
||||
{
|
||||
var delay = AppConfig.Get("screenpad_delay", 1500);
|
||||
|
||||
//Action
|
||||
Action<int> action = (b) =>
|
||||
{
|
||||
if (b >= 0) Program.acpi.DeviceSet(AsusACPI.ScreenPadToggle, 1, "ScreenpadOn");
|
||||
Program.acpi.DeviceSet(AsusACPI.ScreenPadBrightness, Math.Max(b * 255 / 100, 0), "Screenpad");
|
||||
if (b < 0) Program.acpi.DeviceSet(AsusACPI.ScreenPadToggle, 0, "ScreenpadOff");
|
||||
};
|
||||
|
||||
if(delay <= 0 || (brightness > 0 && brightness < 100 && doToggle == false)) //instant action
|
||||
{
|
||||
action(brightness);
|
||||
}
|
||||
else //delayed action
|
||||
{
|
||||
//Timer Approach
|
||||
if (screenpadActionTimer == null)
|
||||
{
|
||||
screenpadActionTimer = new System.Threading.Timer(_ => action(screenpadBrightnessToSet), null, Timeout.Infinite, Timeout.Infinite);
|
||||
}
|
||||
//Start Timer
|
||||
screenpadBrightnessToSet = brightness;
|
||||
screenpadActionTimer.Change(delay, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetScreenpad(int delta)
|
||||
{
|
||||
int brightness = AppConfig.Get("screenpad", 100);
|
||||
@@ -860,7 +891,6 @@ namespace GHelper.Input
|
||||
if (brightness < 0) brightness = 100;
|
||||
else if (brightness >= 100) brightness = 0;
|
||||
else brightness = -10;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -869,11 +899,7 @@ namespace GHelper.Input
|
||||
|
||||
AppConfig.Set("screenpad", brightness);
|
||||
|
||||
if (brightness >= 0) Program.acpi.DeviceSet(AsusACPI.ScreenPadToggle, 1, "ScreenpadOn");
|
||||
|
||||
Program.acpi.DeviceSet(AsusACPI.ScreenPadBrightness, Math.Max(brightness * 255 / 100, 0), "Screenpad");
|
||||
|
||||
if (brightness < 0) Program.acpi.DeviceSet(AsusACPI.ScreenPadToggle, 0, "ScreenpadOff");
|
||||
ApplyScreenpadAction(brightness);
|
||||
|
||||
string toast;
|
||||
|
||||
@@ -882,10 +908,8 @@ namespace GHelper.Input
|
||||
else toast = brightness.ToString() + "%";
|
||||
|
||||
Program.toast.RunToast($"Screen Pad {toast}", delta > 0 ? ToastIcon.BrightnessUp : ToastIcon.BrightnessDown);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void LaunchProcess(string command = "")
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user