From 1472004d4b8dc5797b287c2d3415e683d3393cb9 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 28 May 2023 12:02:29 +0200 Subject: [PATCH] Backlight timeouts --- app/AsusUSB.cs | 2 +- app/Extra.Designer.cs | 30 +++++++++++++++++++++++++++--- app/Extra.cs | 9 +++++++-- app/InputDispatcher.cs | 19 +++++++++++++++---- app/Properties/Strings.Designer.cs | 13 +++++++++++-- app/Properties/Strings.resx | 7 +++++-- app/Properties/Strings.uk.resx | 24 ++++++++++++++++++++++++ 7 files changed, 90 insertions(+), 14 deletions(-) diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 0480d6ac..bfced2ba 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -319,7 +319,7 @@ namespace GHelper Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg)); device.WriteFeatureData(payload); device.CloseDevice(); - return 1; + //return 1; } return 0; diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs index ae2754da..afaa3655 100644 --- a/app/Extra.Designer.cs +++ b/app/Extra.Designer.cs @@ -86,6 +86,8 @@ namespace GHelper checkUSBC = new CheckBox(); checkNoOverdrive = new CheckBox(); checkTopmost = new CheckBox(); + numericBacklightPluggedTime = new NumericUpDown(); + labelBacklightTimeoutPlugged = new Label(); groupBindings.SuspendLayout(); tableKeys.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); @@ -96,6 +98,7 @@ namespace GHelper panelXMG.SuspendLayout(); tableBacklight.SuspendLayout(); groupOther.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericBacklightPluggedTime).BeginInit(); SuspendLayout(); // // groupBindings @@ -302,13 +305,15 @@ namespace GHelper groupLight.Dock = DockStyle.Top; groupLight.Location = new Point(10, 334); groupLight.Name = "groupLight"; - groupLight.Size = new Size(954, 516); + groupLight.Size = new Size(954, 563); groupLight.TabIndex = 1; groupLight.TabStop = false; groupLight.Text = "Keyboard Backlight"; // // panelBacklightExtra // + panelBacklightExtra.Controls.Add(numericBacklightPluggedTime); + panelBacklightExtra.Controls.Add(labelBacklightTimeoutPlugged); panelBacklightExtra.Controls.Add(numericBacklightTime); panelBacklightExtra.Controls.Add(labelBacklightTimeout); panelBacklightExtra.Controls.Add(labelBrightness); @@ -318,7 +323,7 @@ namespace GHelper panelBacklightExtra.Dock = DockStyle.Top; panelBacklightExtra.Location = new Point(3, 319); panelBacklightExtra.Name = "panelBacklightExtra"; - panelBacklightExtra.Size = new Size(948, 194); + panelBacklightExtra.Size = new Size(948, 241); panelBacklightExtra.TabIndex = 43; // // numericBacklightTime @@ -668,7 +673,7 @@ namespace GHelper groupOther.Controls.Add(checkNoOverdrive); groupOther.Controls.Add(checkTopmost); groupOther.Dock = DockStyle.Top; - groupOther.Location = new Point(10, 850); + groupOther.Location = new Point(10, 897); groupOther.Name = "groupOther"; groupOther.Size = new Size(954, 276); groupOther.TabIndex = 2; @@ -726,6 +731,22 @@ namespace GHelper checkTopmost.Text = Strings.WindowTop; checkTopmost.UseVisualStyleBackColor = true; // + // numericBacklightPluggedTime + // + numericBacklightPluggedTime.Location = new Point(655, 181); + numericBacklightPluggedTime.Maximum = new decimal(new int[] { 3600, 0, 0, 0 }); + numericBacklightPluggedTime.Name = "numericBacklightPluggedTime"; + numericBacklightPluggedTime.Size = new Size(240, 39); + numericBacklightPluggedTime.TabIndex = 49; + // + // labelBacklightTimeoutPlugged + // + labelBacklightTimeoutPlugged.Location = new Point(13, 183); + labelBacklightTimeoutPlugged.Name = "labelBacklightTimeoutPlugged"; + labelBacklightTimeoutPlugged.Size = new Size(636, 45); + labelBacklightTimeoutPlugged.TabIndex = 48; + labelBacklightTimeoutPlugged.Text = "Seconds to turn off backlight when plugged"; + // // Extra // AutoScaleDimensions = new SizeF(13F, 32F); @@ -761,6 +782,7 @@ namespace GHelper tableBacklight.ResumeLayout(false); groupOther.ResumeLayout(false); groupOther.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)numericBacklightPluggedTime).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -822,5 +844,7 @@ namespace GHelper private RComboBox comboM2; private TextBox textM2; private TextBox textM1; + private NumericUpDown numericBacklightPluggedTime; + private Label labelBacklightTimeoutPlugged; } } \ No newline at end of file diff --git a/app/Extra.cs b/app/Extra.cs index 9348781a..1fa9053d 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -84,7 +84,9 @@ namespace GHelper labelSpeed.Text = Properties.Strings.AnimationSpeed; labelBrightness.Text = Properties.Strings.Brightness; + labelBacklightTimeout.Text = Properties.Strings.BacklightTimeout; + labelBacklightTimeoutPlugged.Text = Properties.Strings.BacklightTimeoutPlugged; checkKeyboardAuto.Text = Properties.Strings.KeyboardAuto; checkNoOverdrive.Text = Properties.Strings.DisableOverdrive; @@ -209,16 +211,19 @@ namespace GHelper checkXMG.Checked = !(AppConfig.getConfig("xmg_light") == 0); checkXMG.CheckedChanged += CheckXMG_CheckedChanged; - int kb_timeout = AppConfig.getConfig("keyboard_timeout"); - numericBacklightTime.Value = (kb_timeout >= 0) ? kb_timeout : 60; + numericBacklightTime.Value = AppConfig.getConfig("keyboard_timeout", 60); + numericBacklightPluggedTime.Value = AppConfig.getConfig("keyboard_ac_timeout", 0); numericBacklightTime.ValueChanged += NumericBacklightTime_ValueChanged; + numericBacklightPluggedTime.ValueChanged += NumericBacklightTime_ValueChanged; } private void NumericBacklightTime_ValueChanged(object? sender, EventArgs e) { AppConfig.setConfig("keyboard_timeout", (int)numericBacklightTime.Value); + AppConfig.setConfig("keyboard_ac_timeout", (int)numericBacklightPluggedTime.Value); + Program.inputDispatcher.InitBacklightTimer(); } private void CheckXMG_CheckedChanged(object? sender, EventArgs e) diff --git a/app/InputDispatcher.cs b/app/InputDispatcher.cs index 00241065..23854f2c 100644 --- a/app/InputDispatcher.cs +++ b/app/InputDispatcher.cs @@ -93,8 +93,14 @@ namespace GHelper private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) { TimeSpan iddle = NativeMethods.GetIdleTime(); - int kb_timeout = AppConfig.getConfig("keyboard_timeout", 60); - + + int kb_timeout; + + if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online) + kb_timeout = AppConfig.getConfig("keyboard_ac_timeout", 0); + else + kb_timeout = AppConfig.getConfig("keyboard_timeout", 60); + if (kb_timeout == 0) return; if (backlight && iddle.TotalSeconds > kb_timeout) @@ -109,7 +115,7 @@ namespace GHelper AsusUSB.ApplyBrightness(AppConfig.getConfig("keyboard_brightness")); } - //Debug.WriteLine(iddle.TotalSeconds); + Debug.WriteLine(iddle.TotalSeconds); } public void Init() @@ -121,8 +127,13 @@ namespace GHelper if (!OptimizationService.IsRunning()) listener = new KeyboardListener(HandleEvent); - timer.Enabled = (AppConfig.getConfig("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online); + InitBacklightTimer(); + } + public void InitBacklightTimer() + { + timer.Enabled = (AppConfig.getConfig("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online) || + (AppConfig.getConfig("keyboard_ac_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); } diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs index 10bc4f80..4620c5c0 100644 --- a/app/Properties/Strings.Designer.cs +++ b/app/Properties/Strings.Designer.cs @@ -277,7 +277,7 @@ namespace GHelper.Properties { } /// - /// Looks up a localized string similar to Seconds to turn off backlight on battery. + /// Looks up a localized string similar to Backlight timeout on battery. /// internal static string BacklightTimeout { get { @@ -285,6 +285,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Backlight timeout when plugged (0 - always on). + /// + internal static string BacklightTimeoutPlugged { + get { + return ResourceManager.GetString("BacklightTimeoutPlugged", resourceCulture); + } + } + /// /// Looks up a localized string similar to Balanced. /// @@ -484,7 +493,7 @@ namespace GHelper.Properties { } /// - /// Looks up a localized string similar to Fan: . + /// Looks up a localized string similar to Fan: . /// internal static string FanSpeed { get { diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx index eb95ab75..67eb4212 100644 --- a/app/Properties/Strings.resx +++ b/app/Properties/Strings.resx @@ -190,7 +190,10 @@ Awake - Seconds to turn off backlight on battery + Backlight timeout on battery + + + Backlight timeout when plugged (0 - always on) Balanced @@ -259,7 +262,7 @@ Fans and Power - Fan: + Fan: Fans + Power diff --git a/app/Properties/Strings.uk.resx b/app/Properties/Strings.uk.resx index a42c7f2f..3653fb5f 100644 --- a/app/Properties/Strings.uk.resx +++ b/app/Properties/Strings.uk.resx @@ -189,6 +189,12 @@ Робота + + Тайм-аут підсвітки на батареї + + + Тайм-аут підсвітки на зарядці (0 - завжди ввімкнено) + Баланс @@ -324,6 +330,9 @@ Мультизони + + Вимкнути мікрофон + Відкрити вікно G-Helper @@ -333,6 +342,9 @@ Вмикає Еко на батареї та Стандартний на зарядці + + Вимикати GPU на зарядці від USB-C в режимі Авто + Інше @@ -387,6 +399,12 @@ Аура + + Міні-лед (якщо підтримується) + + + Вимкнути екран + Турбо @@ -405,9 +423,15 @@ Версія + + Зменшення гучності + Вимкнення звуку + + Збільшення гучності + Тримати вікно завжди зверху