Skip to content

Commit

Permalink
Added brightness adjustment step
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Sep 16, 2024
1 parent ef76998 commit d0f0bd9
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions app/Input/InputDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,31 @@ static void CustomKey(string configKey = "m3")
}


static void SetBrightness(int delta)
static void SetBrightness(bool up)
{
int brightness = -1;

if (isTUF) brightness = ScreenBrightness.Get();
if (AppConfig.SwappedBrightness()) delta = -delta;
if (AppConfig.SwappedBrightness()) up = !up;

Program.acpi.DeviceSet(AsusACPI.UniversalControl, delta > 0 ? AsusACPI.Brightness_Up : AsusACPI.Brightness_Down, "Brightness");
int step = AppConfig.Get("brightness_step", 10);
if (step != 10)
{
Program.toast.RunToast(ScreenBrightness.Adjust(up ? step : -step) + "%", up ? ToastIcon.BrightnessUp : ToastIcon.BrightnessDown);
return;
}

Program.acpi.DeviceSet(AsusACPI.UniversalControl, up ? AsusACPI.Brightness_Up : AsusACPI.Brightness_Down, "Brightness");

if (isTUF)
{
if (AppConfig.SwappedBrightness()) return;
if (delta < 0 && brightness <= 0) return;
if (delta > 0 && brightness >= 100) return;
if (!up && brightness <= 0) return;
if (up && brightness >= 100) return;

Thread.Sleep(100);
if (brightness == ScreenBrightness.Get())
Program.toast.RunToast(ScreenBrightness.Adjust(delta) + "%", (delta < 0) ? ToastIcon.BrightnessDown : ToastIcon.BrightnessUp);
Program.toast.RunToast(ScreenBrightness.Adjust(up ? step : -step) + "%", up ? ToastIcon.BrightnessUp : ToastIcon.BrightnessDown);
}

}
Expand Down Expand Up @@ -294,10 +301,10 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
HandleEvent(199); // Backlight cycle
return;
case Keys.F5:
SetBrightness(-10);
SetBrightness(false);
return;
case Keys.F6:
SetBrightness(+10);
SetBrightness(true);
return;
case Keys.F7:
KeyboardHook.KeyKeyPress(Keys.LWin, Keys.P);
Expand Down Expand Up @@ -365,10 +372,10 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
KeyboardHook.KeyPress(Keys.Snapshot);
break;
case Keys.F7:
SetBrightness(-10);
SetBrightness(false);
break;
case Keys.F8:
SetBrightness(+10);
SetBrightness(true);
break;
case Keys.F9:
KeyboardHook.KeyKeyPress(Keys.LWin, Keys.P);
Expand Down Expand Up @@ -417,10 +424,10 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
switch (e.Key)
{
case Keys.F1:
SetBrightness(-10);
SetBrightness(false);
break;
case Keys.F2:
SetBrightness(10);
SetBrightness(true);
break;
case Keys.F3:
Program.settingsForm.gpuControl.ToggleXGM(true);
Expand Down Expand Up @@ -462,11 +469,11 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
{
case Keys.VolumeDown:
// Screen brightness down on CTRL+VolDown
SetBrightness(-10);
SetBrightness(false);
break;
case Keys.VolumeUp:
// Screen brightness up on CTRL+VolUp
SetBrightness(+10);
SetBrightness(true);
break;
}
}
Expand Down Expand Up @@ -563,10 +570,10 @@ public static void KeyProcess(string name = "m3")
if (AppConfig.IsVivoZenbook()) Program.acpi.DeviceSet(AsusACPI.MicMuteLed, muteStatus ? 1 : 0, "MicmuteLed");
break;
case "brightness_up":
SetBrightness(+10);
SetBrightness(true);
break;
case "brightness_down":
SetBrightness(-10);
SetBrightness(false);
break;
case "screenpad_up":
SetScreenpad(10);
Expand Down Expand Up @@ -777,7 +784,7 @@ static void HandleOptimizationEvent(int EventID)
}
else
{
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.Brightness_Down, "Brightness");
SetBrightness(false);
}
break;
case 32: // FN+F8
Expand All @@ -792,7 +799,7 @@ static void HandleOptimizationEvent(int EventID)
}
else
{
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.Brightness_Up, "Brightness");
SetBrightness(true);
}
break;
case 133: // Camera Toggle
Expand Down

0 comments on commit d0f0bd9

Please sign in to comment.