From 98a0c2135504bb4f89dfbfd8aaec74fd2a6cd079 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Fri, 4 Aug 2023 21:36:44 +0200 Subject: [PATCH] Bindings fixes --- app/AppConfig.cs | 57 +++++++++++++++++++++++++++++++ app/AsusUSB.cs | 10 ++---- app/Extra.cs | 66 ++++++++++++++++++++---------------- app/Input/InputDispatcher.cs | 43 ++++++++++------------- app/Settings.cs | 6 ++-- 5 files changed, 117 insertions(+), 65 deletions(-) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 2f33845a..e3f5e062 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -260,4 +260,61 @@ public static class AppConfig Set(name + "_" + Modes.GetCurrent(), value); } + public static bool IsAlly() + { + return ContainsModel("RC71"); + } + + public static bool NoMKeys() + { + return ContainsModel("Z13") || + ContainsModel("FX706") || + ContainsModel("FA506") || + ContainsModel("FX506") || + ContainsModel("Duo") || + ContainsModel("FX505"); + } + + public static bool IsTUF() + { + return ContainsModel("TUF"); + } + + // Devices with bugged bios command to change brightness + public static bool SwappedBrightness() + { + return ContainsModel("FA506IH") || ContainsModel("FX506LU"); + } + + + public static bool IsDUO() + { + return ContainsModel("Duo"); + } + + // G14 2020 has no aura, but media keys instead + public static bool NoAura() + { + return ContainsModel("GA401I") && !ContainsModel("GA401IHR"); + } + + public static bool NoAuraColor() + { + return ContainsModel("GA401") || ContainsModel("X13"); + } + + public static bool IsStrix() + { + return ContainsModel("Strix"); + } + + public static bool IsZ13() + { + return ContainsModel("Z13"); + } + + public static bool HasTabletMode() + { + return ContainsModel("X16") || ContainsModel("X13"); + } } diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 77a7f5e9..aee9a163 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -60,8 +60,8 @@ namespace GHelper public static Color Color1 = Color.White; public static Color Color2 = Color.Black; - static bool isTuf = AppConfig.ContainsModel("Tuf"); - static bool isStrix = AppConfig.ContainsModel("Strix"); + static bool isTuf = AppConfig.IsTUF(); + static bool isStrix = AppConfig.IsStrix(); static System.Timers.Timer timer = new System.Timers.Timer(2000); @@ -214,10 +214,6 @@ namespace GHelper } } - public static bool HasColor() - { - return AppConfig.ContainsModel("GA401") || AppConfig.ContainsModel("X13"); - } public static bool HasSecondColor() { @@ -581,7 +577,7 @@ namespace GHelper device.CloseDevice(); } - if (AppConfig.ContainsModel("TUF")) + if (isTuf) Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed); }); diff --git a/app/Extra.cs b/app/Extra.cs index a97fb967..678aa8ae 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -91,31 +91,6 @@ namespace GHelper { InitializeComponent(); - // Change text and hide irrelevant options on the ROG Ally, - // which is a bit of a special case piece of hardware. - if (AppConfig.ContainsModel("RC71")) - { - // The back paddles both seem to issue the same code; - // so we'll replace "M1/M2" with one field, for now. - // (Eventually, we should learn how Asus' software tells the difference.) - labelM1.Text = "Back Paddles"; - labelM2.Visible = false; - comboM2.Visible = false; - textM2.Visible = false; - - // Re-label M3 and M4 to match the front labels. - labelM3.Text = "Ctrl Center"; - labelM4.Text = "ROG"; - - // Hide all of the FN options, as the Ally has no special keyboard FN key. - labelFNC.Visible = false; - comboFNC.Visible = false; - textFNC.Visible = false; - labelFNF4.Visible = false; - comboFNF4.Visible = false; - textFNF4.Visible = false; - } - labelBindings.Text = Properties.Strings.KeyBindings; labelBacklightTitle.Text = Properties.Strings.LaptopBacklight; labelSettings.Text = Properties.Strings.Other; @@ -147,13 +122,39 @@ namespace GHelper Text = Properties.Strings.ExtraSettings; - if (AppConfig.ContainsModel("Duo")) + if (AppConfig.IsDUO()) { customActions.Add("screenpad_down", Properties.Strings.ScreenPadDown); customActions.Add("screenpad_up", Properties.Strings.ScreenPadUp); } - if (InputDispatcher.NoMKeys()) + + // Change text and hide irrelevant options on the ROG Ally, + // which is a bit of a special case piece of hardware. + if (AppConfig.IsAlly()) + { + // The back paddles both seem to issue the same code; + // so we'll replace "M1/M2" with one field, for now. + // (Eventually, we should learn how Asus' software tells the difference.) + labelM1.Text = "Back Paddles"; + labelM2.Visible = false; + comboM2.Visible = false; + textM2.Visible = false; + + // Re-label M3 and M4 to match the front labels. + labelM3.Text = "Ctrl Center"; + labelM4.Text = "ROG"; + + // Hide all of the FN options, as the Ally has no special keyboard FN key. + labelFNC.Visible = false; + comboFNC.Visible = false; + textFNC.Visible = false; + labelFNF4.Visible = false; + comboFNF4.Visible = false; + textFNF4.Visible = false; + } + + if (AppConfig.NoMKeys()) { labelM1.Text = "FN+F2"; labelM2.Text = "FN+F3"; @@ -162,7 +163,12 @@ namespace GHelper labelFNF4.Visible = comboFNF4.Visible = textFNF4.Visible = false; } - if (!AppConfig.ContainsModel("TUF")) + if (AppConfig.NoAura()) + { + labelFNF4.Visible = comboFNF4.Visible = textFNF4.Visible = false; + } + + if (!AppConfig.IsTUF()) { labelFNE.Visible = comboFNE.Visible = textFNE.Visible = false; } @@ -236,7 +242,7 @@ namespace GHelper checkSleepLogo.CheckedChanged += CheckPower_CheckedChanged; checkShutdownLogo.CheckedChanged += CheckPower_CheckedChanged; - if (!AppConfig.ContainsModel("Strix")) + if (!AppConfig.IsStrix()) { labelBacklightBar.Visible = false; checkAwakeBar.Visible = false; @@ -244,7 +250,7 @@ namespace GHelper checkSleepBar.Visible = false; checkShutdownBar.Visible = false; - if (!AppConfig.ContainsModel("Z13")) + if (!AppConfig.IsZ13()) { labelBacklightLid.Visible = false; checkAwakeLid.Visible = false; diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index e4422a71..986fcf25 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -19,6 +19,8 @@ namespace GHelper.Input static ModeControl modeControl = Program.modeControl; static ScreenControl screenControl = new ScreenControl(); + static bool isTUF = AppConfig.IsTUF(); + KeyboardListener listener; KeyboardHook hook = new KeyboardHook(); @@ -112,7 +114,7 @@ namespace GHelper.Input hook.RegisterHotKey(ModifierKeys.Shift, Keys.VolumeUp); } - if (!AppConfig.ContainsModel("Z13")) + if (!AppConfig.IsZ13() && !AppConfig.IsAlly()) { if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown); if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp); @@ -147,33 +149,23 @@ namespace GHelper.Input } - public static bool NoMKeys() - { - return AppConfig.ContainsModel("Z13") || - AppConfig.ContainsModel("FX706") || - AppConfig.ContainsModel("FA506") || - AppConfig.ContainsModel("FX506") || - AppConfig.ContainsModel("Duo") || - AppConfig.ContainsModel("FX505"); - } - - static bool SwappedBrightness() - { - return (AppConfig.ContainsModel("FA506IH") || AppConfig.ContainsModel("FX506LU")); - } static void SetBrightness(int delta) { - var brightness = ScreenBrightness.Get(); + int brightness = -1; + + if (isTUF) brightness = ScreenBrightness.Get(); - if (delta > 0 || SwappedBrightness()) HandleOptimizationEvent(32); + if (delta > 0 || AppConfig.SwappedBrightness()) HandleOptimizationEvent(32); else HandleOptimizationEvent(16); - if (!AppConfig.ContainsModel("TUF")) return; + if (isTUF) + { + Thread.Sleep(100); + if (brightness == ScreenBrightness.Get()) + Program.toast.RunToast(ScreenBrightness.Adjust(delta) + "%", (delta < 0 ) ? ToastIcon.BrightnessDown : ToastIcon.BrightnessUp); + } - Thread.Sleep(100); - if (brightness == ScreenBrightness.Get()) - Program.toast.RunToast(ScreenBrightness.Adjust(delta) + "%", (delta < 0 ) ? ToastIcon.BrightnessDown : ToastIcon.BrightnessUp); } public void KeyPressed(object sender, KeyPressedEventArgs e) @@ -183,7 +175,7 @@ namespace GHelper.Input { Logger.WriteLine(e.Key.ToString()); - if (NoMKeys()) + if (AppConfig.NoMKeys()) { switch (e.Key) { @@ -199,7 +191,7 @@ namespace GHelper.Input } } - if (AppConfig.ContainsModel("Z13") || AppConfig.ContainsModel("Duo")) + if (AppConfig.IsZ13() || AppConfig.IsDUO()) { switch (e.Key) { @@ -209,7 +201,7 @@ namespace GHelper.Input } } - if (AppConfig.ContainsModel("GA401I") && !AppConfig.ContainsModel("GA401IHR")) + if (AppConfig.NoAura()) { switch (e.Key) { @@ -273,6 +265,7 @@ namespace GHelper.Input default: break; } + } if (e.Modifier == (ModifierKeys.Control | ModifierKeys.Shift)) @@ -432,7 +425,7 @@ namespace GHelper.Input { // The ROG Ally uses different M-key codes. // We'll special-case the translation of those. - if (AppConfig.ContainsModel("RC71")) + if (AppConfig.IsAlly()) { switch(EventID) { diff --git a/app/Settings.cs b/app/Settings.cs index 4381ca52..139c2ed6 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -631,12 +631,12 @@ namespace GHelper comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; - if (AsusUSB.HasColor()) + if (AppConfig.NoAuraColor()) { panelColor.Visible = false; } - if (AppConfig.ContainsModel("GA401I")) + if (AppConfig.NoAura()) { comboKeyboard.Visible = false; } @@ -930,7 +930,7 @@ namespace GHelper if (Program.acpi.IsXGConnected()) AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light")); - if (AppConfig.ContainsModel("X16") || AppConfig.ContainsModel("X13")) InputDispatcher.TabletMode(); + if (AppConfig.HasTabletMode()) InputDispatcher.TabletMode(); }