From f21b1e20453ecc9a8f508e508e5619c26c93fc6a Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:07:52 +0200 Subject: [PATCH] Separate lighting zone controls for battery/AC mode https://github.com/seerge/g-helper/issues/2739 --- app/AppConfig.cs | 5 ++ app/Extra.Designer.cs | 111 ++++++++++++++++++++++++++++++++---------- app/Extra.cs | 26 ++++++++++ app/USB/Aura.cs | 12 +++-- 4 files changed, 124 insertions(+), 30 deletions(-) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 2621e164..7d4bad04 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -196,6 +196,11 @@ public static class AppConfig return Get(name) != 0; } + public static bool IsOnBattery(string zone) + { + return Get(zone + "_bat", Get(zone)) != 0; + } + public static string GetString(string name, string empty = null) { if (config.ContainsKey(name)) diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs index 84a98aeb..4bfe0e52 100644 --- a/app/Extra.Designer.cs +++ b/app/Extra.Designer.cs @@ -117,6 +117,7 @@ namespace GHelper checkGpuApps = new CheckBox(); checkGPUFix = new CheckBox(); checkStatusLed = new CheckBox(); + checkPerKeyRGB = new CheckBox(); panelPower = new Panel(); numericHibernateAfter = new NumericUpDown(); labelHibernateAfter = new Label(); @@ -138,7 +139,10 @@ namespace GHelper buttonACPISend = new RButton(); pictureDebug = new PictureBox(); labelACPITitle = new Label(); - checkPerKeyRGB = new CheckBox(); + checkBatteryBar = new CheckBox(); + checkBatteryLid = new CheckBox(); + checkBattery = new CheckBox(); + checkBatteryLogo = new CheckBox(); panelServices.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureService).BeginInit(); panelBindingsHeader.SuspendLayout(); @@ -177,7 +181,7 @@ namespace GHelper panelServices.Controls.Add(labelServices); panelServices.Controls.Add(buttonServices); panelServices.Dock = DockStyle.Top; - panelServices.Location = new Point(15, 1680); + panelServices.Location = new Point(15, 1723); panelServices.Name = "panelServices"; panelServices.Size = new Size(949, 75); panelServices.TabIndex = 5; @@ -682,7 +686,7 @@ namespace GHelper panelBacklight.Location = new Point(15, 514); panelBacklight.Name = "panelBacklight"; panelBacklight.Padding = new Padding(0, 5, 0, 5); - panelBacklight.Size = new Size(949, 402); + panelBacklight.Size = new Size(949, 445); panelBacklight.TabIndex = 2; // // panelBacklightExtra @@ -695,7 +699,7 @@ namespace GHelper panelBacklightExtra.Controls.Add(labelSpeed); panelBacklightExtra.Controls.Add(comboKeyboardSpeed); panelBacklightExtra.Dock = DockStyle.Top; - panelBacklightExtra.Location = new Point(0, 282); + panelBacklightExtra.Location = new Point(0, 325); panelBacklightExtra.Margin = new Padding(4, 3, 4, 3); panelBacklightExtra.Name = "panelBacklightExtra"; panelBacklightExtra.Padding = new Padding(0, 0, 0, 5); @@ -761,7 +765,7 @@ namespace GHelper // panelXMG.Controls.Add(checkXMG); panelXMG.Dock = DockStyle.Top; - panelXMG.Location = new Point(0, 222); + panelXMG.Location = new Point(0, 265); panelXMG.Margin = new Padding(4, 3, 4, 3); panelXMG.Name = "panelXMG"; panelXMG.Size = new Size(949, 60); @@ -787,6 +791,10 @@ namespace GHelper tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + tableBacklight.Controls.Add(checkBatteryLogo, 0, 5); + tableBacklight.Controls.Add(checkBattery, 0, 5); + tableBacklight.Controls.Add(checkBatteryLid, 0, 5); + tableBacklight.Controls.Add(checkBatteryBar, 0, 5); tableBacklight.Controls.Add(labelBacklightKeyboard, 0, 0); tableBacklight.Controls.Add(checkAwake, 0, 1); tableBacklight.Controls.Add(checkBoot, 0, 2); @@ -811,13 +819,14 @@ namespace GHelper tableBacklight.Location = new Point(0, 5); tableBacklight.Margin = new Padding(0); tableBacklight.Name = "tableBacklight"; - tableBacklight.RowCount = 5; + tableBacklight.RowCount = 6; tableBacklight.RowStyles.Add(new RowStyle()); tableBacklight.RowStyles.Add(new RowStyle()); tableBacklight.RowStyles.Add(new RowStyle()); tableBacklight.RowStyles.Add(new RowStyle()); tableBacklight.RowStyles.Add(new RowStyle()); - tableBacklight.Size = new Size(949, 217); + tableBacklight.RowStyles.Add(new RowStyle()); + tableBacklight.Size = new Size(949, 260); tableBacklight.TabIndex = 44; // // labelBacklightKeyboard @@ -1069,7 +1078,7 @@ namespace GHelper panelSettingsHeader.Controls.Add(pictureSettings); panelSettingsHeader.Controls.Add(labelSettings); panelSettingsHeader.Dock = DockStyle.Top; - panelSettingsHeader.Location = new Point(15, 916); + panelSettingsHeader.Location = new Point(15, 959); panelSettingsHeader.Name = "panelSettingsHeader"; panelSettingsHeader.Padding = new Padding(11, 5, 11, 5); panelSettingsHeader.Size = new Size(949, 51); @@ -1139,7 +1148,7 @@ namespace GHelper panelSettings.Controls.Add(checkStatusLed); panelSettings.Controls.Add(checkPerKeyRGB); panelSettings.Dock = DockStyle.Top; - panelSettings.Location = new Point(15, 1154); + panelSettings.Location = new Point(15, 1197); panelSettings.Name = "panelSettings"; panelSettings.Padding = new Padding(20, 5, 11, 5); panelSettings.Size = new Size(949, 472); @@ -1275,13 +1284,27 @@ namespace GHelper checkStatusLed.UseVisualStyleBackColor = true; checkStatusLed.Visible = false; // + // checkPerKeyRGB + // + checkPerKeyRGB.AutoSize = true; + checkPerKeyRGB.Dock = DockStyle.Top; + checkPerKeyRGB.Location = new Point(20, 5); + checkPerKeyRGB.Margin = new Padding(4, 3, 4, 3); + checkPerKeyRGB.Name = "checkPerKeyRGB"; + checkPerKeyRGB.Padding = new Padding(3); + checkPerKeyRGB.Size = new Size(918, 42); + checkPerKeyRGB.TabIndex = 13; + checkPerKeyRGB.Text = "Per-Key RGB Keyboard"; + checkPerKeyRGB.UseVisualStyleBackColor = true; + checkPerKeyRGB.Visible = false; + // // panelPower // panelPower.Controls.Add(numericHibernateAfter); panelPower.Controls.Add(labelHibernateAfter); panelPower.Controls.Add(pictureHibernate); panelPower.Dock = DockStyle.Top; - panelPower.Location = new Point(15, 1626); + panelPower.Location = new Point(15, 1669); panelPower.Name = "panelPower"; panelPower.Size = new Size(949, 54); panelPower.TabIndex = 4; @@ -1324,7 +1347,7 @@ namespace GHelper panelAPU.Controls.Add(pictureAPUMem); panelAPU.Controls.Add(labelAPUMem); panelAPU.Dock = DockStyle.Top; - panelAPU.Location = new Point(15, 1097); + panelAPU.Location = new Point(15, 1140); panelAPU.Name = "panelAPU"; panelAPU.Padding = new Padding(11, 5, 11, 0); panelAPU.Size = new Size(949, 57); @@ -1378,7 +1401,7 @@ namespace GHelper panelCores.Controls.Add(pictureCores); panelCores.Controls.Add(label1); panelCores.Dock = DockStyle.Top; - panelCores.Location = new Point(15, 1036); + panelCores.Location = new Point(15, 1079); panelCores.Name = "panelCores"; panelCores.Padding = new Padding(11, 5, 11, 0); panelCores.Size = new Size(949, 61); @@ -1463,7 +1486,7 @@ namespace GHelper panelACPI.Controls.Add(pictureDebug); panelACPI.Controls.Add(labelACPITitle); panelACPI.Dock = DockStyle.Top; - panelACPI.Location = new Point(15, 967); + panelACPI.Location = new Point(15, 1010); panelACPI.Name = "panelACPI"; panelACPI.Padding = new Padding(11, 5, 11, 0); panelACPI.Size = new Size(949, 69); @@ -1527,19 +1550,53 @@ namespace GHelper labelACPITitle.TabIndex = 0; labelACPITitle.Text = "ACPI DEVS Test"; // - // checkPerKeyRGB + // checkBatteryBar // - checkPerKeyRGB.AutoSize = true; - checkPerKeyRGB.Dock = DockStyle.Top; - checkPerKeyRGB.Location = new Point(20, 5); - checkPerKeyRGB.Margin = new Padding(4, 3, 4, 3); - checkPerKeyRGB.Name = "checkPerKeyRGB"; - checkPerKeyRGB.Padding = new Padding(3); - checkPerKeyRGB.Size = new Size(918, 42); - checkPerKeyRGB.TabIndex = 13; - checkPerKeyRGB.Text = "Per-Key RGB Keyboard"; - checkPerKeyRGB.UseVisualStyleBackColor = true; - checkPerKeyRGB.Visible = false; + checkBatteryBar.Dock = DockStyle.Fill; + checkBatteryBar.Location = new Point(478, 217); + checkBatteryBar.Margin = new Padding(4, 0, 4, 0); + checkBatteryBar.Name = "checkBatteryBar"; + checkBatteryBar.Padding = new Padding(16, 3, 7, 3); + checkBatteryBar.Size = new Size(229, 43); + checkBatteryBar.TabIndex = 22; + checkBatteryBar.Text = "Battery"; + checkBatteryBar.UseVisualStyleBackColor = true; + // + // checkBatteryLid + // + checkBatteryLid.Dock = DockStyle.Fill; + checkBatteryLid.Location = new Point(715, 217); + checkBatteryLid.Margin = new Padding(4, 0, 4, 0); + checkBatteryLid.Name = "checkBatteryLid"; + checkBatteryLid.Padding = new Padding(16, 3, 7, 3); + checkBatteryLid.Size = new Size(230, 43); + checkBatteryLid.TabIndex = 23; + checkBatteryLid.Text = "Battery"; + checkBatteryLid.UseVisualStyleBackColor = true; + // + // checkBattery + // + checkBattery.Dock = DockStyle.Fill; + checkBattery.Location = new Point(4, 217); + checkBattery.Margin = new Padding(4, 0, 4, 0); + checkBattery.Name = "checkBattery"; + checkBattery.Padding = new Padding(16, 3, 7, 3); + checkBattery.Size = new Size(229, 43); + checkBattery.TabIndex = 24; + checkBattery.Text = "Battery"; + checkBattery.UseVisualStyleBackColor = true; + // + // checkBatteryLogo + // + checkBatteryLogo.Dock = DockStyle.Fill; + checkBatteryLogo.Location = new Point(241, 217); + checkBatteryLogo.Margin = new Padding(4, 0, 4, 0); + checkBatteryLogo.Name = "checkBatteryLogo"; + checkBatteryLogo.Padding = new Padding(16, 3, 7, 3); + checkBatteryLogo.Size = new Size(229, 43); + checkBatteryLogo.TabIndex = 25; + checkBatteryLogo.Text = "Battery"; + checkBatteryLogo.UseVisualStyleBackColor = true; // // Extra // @@ -1726,5 +1783,9 @@ namespace GHelper private CheckBox checkBWIcon; private CheckBox checkStatusLed; private CheckBox checkPerKeyRGB; + private CheckBox checkBatteryLogo; + private CheckBox checkBattery; + private CheckBox checkBatteryLid; + private CheckBox checkBatteryBar; } } \ No newline at end of file diff --git a/app/Extra.cs b/app/Extra.cs index 7e1b5ad6..c46a3446 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -298,44 +298,52 @@ namespace GHelper // Keyboard checkAwake.Checked = AppConfig.IsNotFalse("keyboard_awake"); + checkBattery.Checked = AppConfig.IsOnBattery("keyboard_awake"); checkBoot.Checked = AppConfig.IsNotFalse("keyboard_boot"); checkSleep.Checked = AppConfig.IsNotFalse("keyboard_sleep"); checkShutdown.Checked = AppConfig.IsNotFalse("keyboard_shutdown"); // Lightbar checkAwakeBar.Checked = AppConfig.IsNotFalse("keyboard_awake_bar"); + checkBatteryBar.Checked = AppConfig.IsOnBattery("keyboard_awake_bar"); checkBootBar.Checked = AppConfig.IsNotFalse("keyboard_boot_bar"); checkSleepBar.Checked = AppConfig.IsNotFalse("keyboard_sleep_bar"); checkShutdownBar.Checked = AppConfig.IsNotFalse("keyboard_shutdown_bar"); // Lid checkAwakeLid.Checked = AppConfig.IsNotFalse("keyboard_awake_lid"); + checkBatteryLid.Checked = AppConfig.IsOnBattery("keyboard_awake_lid"); checkBootLid.Checked = AppConfig.IsNotFalse("keyboard_boot_lid"); checkSleepLid.Checked = AppConfig.IsNotFalse("keyboard_sleep_lid"); checkShutdownLid.Checked = AppConfig.IsNotFalse("keyboard_shutdown_lid"); // Logo checkAwakeLogo.Checked = AppConfig.IsNotFalse("keyboard_awake_logo"); + checkBatteryLogo.Checked = AppConfig.IsOnBattery("keyboard_awake_logo"); checkBootLogo.Checked = AppConfig.IsNotFalse("keyboard_boot_logo"); checkSleepLogo.Checked = AppConfig.IsNotFalse("keyboard_sleep_logo"); checkShutdownLogo.Checked = AppConfig.IsNotFalse("keyboard_shutdown_logo"); checkAwake.CheckedChanged += CheckPower_CheckedChanged; + checkBattery.CheckedChanged += CheckPower_CheckedChanged; checkBoot.CheckedChanged += CheckPower_CheckedChanged; checkSleep.CheckedChanged += CheckPower_CheckedChanged; checkShutdown.CheckedChanged += CheckPower_CheckedChanged; checkAwakeBar.CheckedChanged += CheckPower_CheckedChanged; + checkBatteryBar.CheckedChanged += CheckPower_CheckedChanged; checkBootBar.CheckedChanged += CheckPower_CheckedChanged; checkSleepBar.CheckedChanged += CheckPower_CheckedChanged; checkShutdownBar.CheckedChanged += CheckPower_CheckedChanged; checkAwakeLid.CheckedChanged += CheckPower_CheckedChanged; + checkBatteryLid.CheckedChanged += CheckPower_CheckedChanged; checkBootLid.CheckedChanged += CheckPower_CheckedChanged; checkSleepLid.CheckedChanged += CheckPower_CheckedChanged; checkShutdownLid.CheckedChanged += CheckPower_CheckedChanged; checkAwakeLogo.CheckedChanged += CheckPower_CheckedChanged; + checkBatteryLogo.CheckedChanged += CheckPower_CheckedChanged; checkBootLogo.CheckedChanged += CheckPower_CheckedChanged; checkSleepLogo.CheckedChanged += CheckPower_CheckedChanged; checkShutdownLogo.CheckedChanged += CheckPower_CheckedChanged; @@ -347,6 +355,7 @@ namespace GHelper { labelBacklightBar.Visible = false; checkAwakeBar.Visible = false; + checkBatteryBar.Visible = false; checkBootBar.Visible = false; checkSleepBar.Visible = false; checkShutdownBar.Visible = false; @@ -354,12 +363,14 @@ namespace GHelper labelBacklightLid.Visible = false; checkAwakeLid.Visible = false; + checkBatteryLid.Visible = false; checkBootLid.Visible = false; checkSleepLid.Visible = false; checkShutdownLid.Visible = false; labelBacklightLogo.Visible = false; checkAwakeLogo.Visible = false; + checkBatteryLogo.Visible = false; checkBootLogo.Visible = false; checkSleepLogo.Visible = false; checkShutdownLogo.Visible = false; @@ -368,6 +379,7 @@ namespace GHelper if (!AppConfig.IsStrix() && !AppConfig.IsZ13()) { labelBacklightKeyboard.Visible = false; + checkBattery.Visible = false; } //checkAutoToggleClamshellMode.Visible = clamshellControl.IsExternalDisplayConnected(); @@ -765,6 +777,20 @@ namespace GHelper AppConfig.Set("keyboard_sleep_logo", (checkSleepLogo.Checked ? 1 : 0)); AppConfig.Set("keyboard_shutdown_logo", (checkShutdownLogo.Checked ? 1 : 0)); + if (checkBattery.Visible) + { + AppConfig.Set("keyboard_awake_bat", (checkBattery.Checked ? 1 : 0)); + AppConfig.Set("keyboard_awake_bar_bat", (checkBatteryBar.Checked ? 1 : 0)); + AppConfig.Set("keyboard_awake_lid_bat", (checkBatteryLid.Checked ? 1 : 0)); + AppConfig.Set("keyboard_awake_logo_bat", (checkBatteryLogo.Checked ? 1 : 0)); + } else + { + AppConfig.Remove("keyboard_awake_bat"); + AppConfig.Remove("keyboard_awake_bar_bat"); + AppConfig.Remove("keyboard_awake_lid_bat"); + AppConfig.Remove("keyboard_awake_logo_bat"); + } + Aura.ApplyPower(); } diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index 2d7a214c..2cc9c599 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -354,34 +354,36 @@ namespace GHelper.USB public static void ApplyPower() { + bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online; + AuraPower flags = new(); // Keyboard - flags.AwakeKeyb = AppConfig.IsNotFalse("keyboard_awake"); + flags.AwakeKeyb = onBattery ? AppConfig.IsOnBattery("keyboard_awake") : AppConfig.IsNotFalse("keyboard_awake"); flags.BootKeyb = AppConfig.IsNotFalse("keyboard_boot"); flags.SleepKeyb = AppConfig.IsNotFalse("keyboard_sleep"); flags.ShutdownKeyb = AppConfig.IsNotFalse("keyboard_shutdown"); // Logo - flags.AwakeLogo = AppConfig.IsNotFalse("keyboard_awake_logo"); + flags.AwakeLogo = onBattery ? AppConfig.IsOnBattery("keyboard_awake_logo") : AppConfig.IsNotFalse("keyboard_awake_logo"); flags.BootLogo = AppConfig.IsNotFalse("keyboard_boot_logo"); flags.SleepLogo = AppConfig.IsNotFalse("keyboard_sleep_logo"); flags.ShutdownLogo = AppConfig.IsNotFalse("keyboard_shutdown_logo"); // Lightbar - flags.AwakeBar = AppConfig.IsNotFalse("keyboard_awake_bar"); + flags.AwakeBar = onBattery ? AppConfig.IsOnBattery("keyboard_awake_bar") : AppConfig.IsNotFalse("keyboard_awake_bar"); flags.BootBar = AppConfig.IsNotFalse("keyboard_boot_bar"); flags.SleepBar = AppConfig.IsNotFalse("keyboard_sleep_bar"); flags.ShutdownBar = AppConfig.IsNotFalse("keyboard_shutdown_bar"); // Lid - flags.AwakeLid = AppConfig.IsNotFalse("keyboard_awake_lid"); + flags.AwakeLid = onBattery ? AppConfig.IsOnBattery("keyboard_awake_lid") : AppConfig.IsNotFalse("keyboard_awake_lid"); flags.BootLid = AppConfig.IsNotFalse("keyboard_boot_lid"); flags.SleepLid = AppConfig.IsNotFalse("keyboard_sleep_lid"); flags.ShutdownLid = AppConfig.IsNotFalse("keyboard_shutdown_lid"); // Rear Bar - flags.AwakeRear = AppConfig.IsNotFalse("keyboard_awake_lid"); + flags.AwakeRear = onBattery ? AppConfig.IsOnBattery("keyboard_awake_lid") : AppConfig.IsNotFalse("keyboard_awake_lid"); flags.BootRear = AppConfig.IsNotFalse("keyboard_boot_lid"); flags.SleepRear = AppConfig.IsNotFalse("keyboard_sleep_lid"); flags.ShutdownRear = AppConfig.IsNotFalse("keyboard_shutdown_lid");