Save backlight levels per battery / power

This commit is contained in:
Serge
2023-06-02 12:57:09 +02:00
parent b97a06eb56
commit 4f6db4ae0a
5 changed files with 143 additions and 136 deletions

View File

@@ -249,7 +249,7 @@ namespace GHelper
} }
public static void ApplyBrightness(int brightness) public static void ApplyBrightness(int brightness, string log = "Backlight")
{ {
if (AppConfig.ContainsModel("TUF")) if (AppConfig.ContainsModel("TUF"))
@@ -266,7 +266,7 @@ namespace GHelper
{ {
device.OpenDevice(); device.OpenDevice();
device.WriteFeatureData(msg); device.WriteFeatureData(msg);
Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg)); Logger.WriteLine(log + ":" + BitConverter.ToString(msg));
device.CloseDevice(); device.CloseDevice();
} }

175
app/Extra.Designer.cs generated
View File

@@ -33,21 +33,24 @@ namespace GHelper
{ {
groupBindings = new GroupBox(); groupBindings = new GroupBox();
tableKeys = new TableLayoutPanel(); tableKeys = new TableLayoutPanel();
labelFNC = new Label();
textM2 = new TextBox(); textM2 = new TextBox();
textM1 = new TextBox(); textM1 = new TextBox();
comboM1 = new RComboBox(); comboM1 = new RComboBox();
labelM1 = new Label(); labelM1 = new Label();
labelFNF4 = new Label();
comboFNF4 = new RComboBox();
comboM4 = new RComboBox(); comboM4 = new RComboBox();
comboM3 = new RComboBox(); comboM3 = new RComboBox();
textFNF4 = new TextBox();
textM4 = new TextBox(); textM4 = new TextBox();
textM3 = new TextBox(); textM3 = new TextBox();
labelM4 = new Label(); labelM4 = new Label();
labelM3 = new Label(); labelM3 = new Label();
labelM2 = new Label(); labelM2 = new Label();
comboM2 = new RComboBox(); comboM2 = new RComboBox();
labelFNF4 = new Label();
comboFNF4 = new RComboBox();
textFNF4 = new TextBox();
comboFNC = new RComboBox();
textFNC = new TextBox();
pictureHelp = new PictureBox(); pictureHelp = new PictureBox();
groupLight = new GroupBox(); groupLight = new GroupBox();
panelBacklightExtra = new Panel(); panelBacklightExtra = new Panel();
@@ -86,13 +89,9 @@ namespace GHelper
checkFnLock = new CheckBox(); checkFnLock = new CheckBox();
checkGpuApps = new CheckBox(); checkGpuApps = new CheckBox();
checkAutoApplyWindowsPowerMode = new CheckBox(); checkAutoApplyWindowsPowerMode = new CheckBox();
checkKeyboardAuto = new CheckBox();
checkUSBC = new CheckBox(); checkUSBC = new CheckBox();
checkNoOverdrive = new CheckBox(); checkNoOverdrive = new CheckBox();
checkTopmost = new CheckBox(); checkTopmost = new CheckBox();
labelFNC = new Label();
comboFNC = new RComboBox();
textFNC = new TextBox();
groupBindings.SuspendLayout(); groupBindings.SuspendLayout();
tableKeys.SuspendLayout(); tableKeys.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit();
@@ -108,12 +107,13 @@ namespace GHelper
// //
// groupBindings // groupBindings
// //
groupBindings.AutoSizeMode = AutoSizeMode.GrowAndShrink;
groupBindings.Controls.Add(tableKeys); groupBindings.Controls.Add(tableKeys);
groupBindings.Controls.Add(pictureHelp); groupBindings.Controls.Add(pictureHelp);
groupBindings.Dock = DockStyle.Top; groupBindings.Dock = DockStyle.Top;
groupBindings.Location = new Point(10, 10); groupBindings.Location = new Point(10, 10);
groupBindings.Name = "groupBindings"; groupBindings.Name = "groupBindings";
groupBindings.Size = new Size(954, 376); groupBindings.Size = new Size(954, 360);
groupBindings.TabIndex = 0; groupBindings.TabIndex = 0;
groupBindings.TabStop = false; groupBindings.TabStop = false;
groupBindings.Text = "Key Bindings"; groupBindings.Text = "Key Bindings";
@@ -152,12 +152,21 @@ namespace GHelper
tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 48F)); tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 48F));
tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 22F)); tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 22F));
tableKeys.Size = new Size(897, 318); tableKeys.Size = new Size(900, 308);
tableKeys.TabIndex = 10; tableKeys.TabIndex = 10;
// //
// labelFNC
//
labelFNC.AutoSize = true;
labelFNC.Location = new Point(13, 258);
labelFNC.Name = "labelFNC";
labelFNC.Size = new Size(80, 32);
labelFNC.TabIndex = 15;
labelFNC.Text = "FN+C:";
//
// textM2 // textM2
// //
textM2.Location = new Point(538, 63); textM2.Location = new Point(541, 63);
textM2.Name = "textM2"; textM2.Name = "textM2";
textM2.PlaceholderText = "action"; textM2.PlaceholderText = "action";
textM2.Size = new Size(346, 39); textM2.Size = new Size(346, 39);
@@ -165,7 +174,7 @@ namespace GHelper
// //
// textM1 // textM1
// //
textM1.Location = new Point(538, 13); textM1.Location = new Point(541, 13);
textM1.Name = "textM1"; textM1.Name = "textM1";
textM1.PlaceholderText = "action"; textM1.PlaceholderText = "action";
textM1.Size = new Size(346, 39); textM1.Size = new Size(346, 39);
@@ -177,7 +186,7 @@ namespace GHelper
comboM1.ButtonColor = Color.FromArgb(255, 255, 255); comboM1.ButtonColor = Color.FromArgb(255, 255, 255);
comboM1.FormattingEnabled = true; comboM1.FormattingEnabled = true;
comboM1.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); comboM1.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom });
comboM1.Location = new Point(188, 13); comboM1.Location = new Point(189, 13);
comboM1.Name = "comboM1"; comboM1.Name = "comboM1";
comboM1.Size = new Size(312, 40); comboM1.Size = new Size(312, 40);
comboM1.TabIndex = 11; comboM1.TabIndex = 11;
@@ -191,32 +200,13 @@ namespace GHelper
labelM1.TabIndex = 9; labelM1.TabIndex = 9;
labelM1.Text = "M1:"; labelM1.Text = "M1:";
// //
// labelFNF4
//
labelFNF4.AutoSize = true;
labelFNF4.Location = new Point(13, 210);
labelFNF4.Name = "labelFNF4";
labelFNF4.Size = new Size(90, 32);
labelFNF4.TabIndex = 6;
labelFNF4.Text = "FN+F4:";
//
// comboFNF4
//
comboFNF4.BorderColor = Color.White;
comboFNF4.ButtonColor = Color.FromArgb(255, 255, 255);
comboFNF4.FormattingEnabled = true;
comboFNF4.Location = new Point(188, 213);
comboFNF4.Name = "comboFNF4";
comboFNF4.Size = new Size(312, 40);
comboFNF4.TabIndex = 7;
//
// comboM4 // comboM4
// //
comboM4.BorderColor = Color.White; comboM4.BorderColor = Color.White;
comboM4.ButtonColor = Color.FromArgb(255, 255, 255); comboM4.ButtonColor = Color.FromArgb(255, 255, 255);
comboM4.FormattingEnabled = true; comboM4.FormattingEnabled = true;
comboM4.Items.AddRange(new object[] { Strings.PerformanceMode, Strings.OpenGHelper, Strings.Custom }); comboM4.Items.AddRange(new object[] { Strings.PerformanceMode, Strings.OpenGHelper, Strings.Custom });
comboM4.Location = new Point(188, 163); comboM4.Location = new Point(189, 163);
comboM4.Name = "comboM4"; comboM4.Name = "comboM4";
comboM4.Size = new Size(312, 40); comboM4.Size = new Size(312, 40);
comboM4.TabIndex = 3; comboM4.TabIndex = 3;
@@ -227,22 +217,14 @@ namespace GHelper
comboM3.ButtonColor = Color.FromArgb(255, 255, 255); comboM3.ButtonColor = Color.FromArgb(255, 255, 255);
comboM3.FormattingEnabled = true; comboM3.FormattingEnabled = true;
comboM3.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); comboM3.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom });
comboM3.Location = new Point(188, 113); comboM3.Location = new Point(189, 113);
comboM3.Name = "comboM3"; comboM3.Name = "comboM3";
comboM3.Size = new Size(312, 40); comboM3.Size = new Size(312, 40);
comboM3.TabIndex = 1; comboM3.TabIndex = 1;
// //
// textFNF4
//
textFNF4.Location = new Point(538, 213);
textFNF4.Name = "textFNF4";
textFNF4.PlaceholderText = "action";
textFNF4.Size = new Size(346, 39);
textFNF4.TabIndex = 8;
//
// textM4 // textM4
// //
textM4.Location = new Point(538, 163); textM4.Location = new Point(541, 163);
textM4.Name = "textM4"; textM4.Name = "textM4";
textM4.PlaceholderText = "action"; textM4.PlaceholderText = "action";
textM4.Size = new Size(346, 39); textM4.Size = new Size(346, 39);
@@ -250,7 +232,7 @@ namespace GHelper
// //
// textM3 // textM3
// //
textM3.Location = new Point(538, 113); textM3.Location = new Point(541, 113);
textM3.Name = "textM3"; textM3.Name = "textM3";
textM3.PlaceholderText = "action"; textM3.PlaceholderText = "action";
textM3.Size = new Size(346, 39); textM3.Size = new Size(346, 39);
@@ -289,11 +271,56 @@ namespace GHelper
comboM2.ButtonColor = Color.FromArgb(255, 255, 255); comboM2.ButtonColor = Color.FromArgb(255, 255, 255);
comboM2.FormattingEnabled = true; comboM2.FormattingEnabled = true;
comboM2.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); comboM2.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom });
comboM2.Location = new Point(188, 63); comboM2.Location = new Point(189, 63);
comboM2.Name = "comboM2"; comboM2.Name = "comboM2";
comboM2.Size = new Size(312, 40); comboM2.Size = new Size(312, 40);
comboM2.TabIndex = 12; comboM2.TabIndex = 12;
// //
// labelFNF4
//
labelFNF4.AutoSize = true;
labelFNF4.Location = new Point(13, 210);
labelFNF4.Name = "labelFNF4";
labelFNF4.Size = new Size(90, 32);
labelFNF4.TabIndex = 6;
labelFNF4.Text = "FN+F4:";
//
// comboFNF4
//
comboFNF4.BorderColor = Color.White;
comboFNF4.ButtonColor = Color.FromArgb(255, 255, 255);
comboFNF4.FormattingEnabled = true;
comboFNF4.Location = new Point(189, 213);
comboFNF4.Name = "comboFNF4";
comboFNF4.Size = new Size(312, 40);
comboFNF4.TabIndex = 7;
//
// textFNF4
//
textFNF4.Location = new Point(541, 213);
textFNF4.Name = "textFNF4";
textFNF4.PlaceholderText = "action";
textFNF4.Size = new Size(346, 39);
textFNF4.TabIndex = 8;
//
// comboFNC
//
comboFNC.BorderColor = Color.White;
comboFNC.ButtonColor = Color.FromArgb(255, 255, 255);
comboFNC.FormattingEnabled = true;
comboFNC.Location = new Point(189, 261);
comboFNC.Name = "comboFNC";
comboFNC.Size = new Size(312, 40);
comboFNC.TabIndex = 16;
//
// textFNC
//
textFNC.Location = new Point(541, 261);
textFNC.Name = "textFNC";
textFNC.PlaceholderText = "action";
textFNC.Size = new Size(346, 39);
textFNC.TabIndex = 17;
//
// pictureHelp // pictureHelp
// //
pictureHelp.BackgroundImage = Resources.icons8_help_64; pictureHelp.BackgroundImage = Resources.icons8_help_64;
@@ -312,7 +339,7 @@ namespace GHelper
groupLight.Controls.Add(panelXMG); groupLight.Controls.Add(panelXMG);
groupLight.Controls.Add(tableBacklight); groupLight.Controls.Add(tableBacklight);
groupLight.Dock = DockStyle.Top; groupLight.Dock = DockStyle.Top;
groupLight.Location = new Point(10, 386); groupLight.Location = new Point(10, 370);
groupLight.Name = "groupLight"; groupLight.Name = "groupLight";
groupLight.Size = new Size(954, 563); groupLight.Size = new Size(954, 563);
groupLight.TabIndex = 1; groupLight.TabIndex = 1;
@@ -695,14 +722,13 @@ namespace GHelper
groupOther.Controls.Add(checkFnLock); groupOther.Controls.Add(checkFnLock);
groupOther.Controls.Add(checkGpuApps); groupOther.Controls.Add(checkGpuApps);
groupOther.Controls.Add(checkAutoApplyWindowsPowerMode); groupOther.Controls.Add(checkAutoApplyWindowsPowerMode);
groupOther.Controls.Add(checkKeyboardAuto);
groupOther.Controls.Add(checkUSBC); groupOther.Controls.Add(checkUSBC);
groupOther.Controls.Add(checkNoOverdrive); groupOther.Controls.Add(checkNoOverdrive);
groupOther.Controls.Add(checkTopmost); groupOther.Controls.Add(checkTopmost);
groupOther.Dock = DockStyle.Top; groupOther.Dock = DockStyle.Top;
groupOther.Location = new Point(10, 949); groupOther.Location = new Point(10, 933);
groupOther.Name = "groupOther"; groupOther.Name = "groupOther";
groupOther.Size = new Size(954, 352); groupOther.Size = new Size(954, 300);
groupOther.TabIndex = 2; groupOther.TabIndex = 2;
groupOther.TabStop = false; groupOther.TabStop = false;
groupOther.Text = "Other"; groupOther.Text = "Other";
@@ -710,7 +736,7 @@ namespace GHelper
// checkFnLock // checkFnLock
// //
checkFnLock.AutoSize = true; checkFnLock.AutoSize = true;
checkFnLock.Location = new Point(25, 89); checkFnLock.Location = new Point(25, 44);
checkFnLock.MaximumSize = new Size(780, 0); checkFnLock.MaximumSize = new Size(780, 0);
checkFnLock.Name = "checkFnLock"; checkFnLock.Name = "checkFnLock";
checkFnLock.Size = new Size(397, 36); checkFnLock.Size = new Size(397, 36);
@@ -721,7 +747,7 @@ namespace GHelper
// checkGpuApps // checkGpuApps
// //
checkGpuApps.AutoSize = true; checkGpuApps.AutoSize = true;
checkGpuApps.Location = new Point(25, 128); checkGpuApps.Location = new Point(25, 83);
checkGpuApps.Name = "checkGpuApps"; checkGpuApps.Name = "checkGpuApps";
checkGpuApps.Size = new Size(544, 36); checkGpuApps.Size = new Size(544, 36);
checkGpuApps.TabIndex = 48; checkGpuApps.TabIndex = 48;
@@ -731,28 +757,17 @@ namespace GHelper
// checkAutoApplyWindowsPowerMode // checkAutoApplyWindowsPowerMode
// //
checkAutoApplyWindowsPowerMode.AutoSize = true; checkAutoApplyWindowsPowerMode.AutoSize = true;
checkAutoApplyWindowsPowerMode.Location = new Point(25, 296); checkAutoApplyWindowsPowerMode.Location = new Point(25, 251);
checkAutoApplyWindowsPowerMode.Name = "checkAutoApplyWindowsPowerMode"; checkAutoApplyWindowsPowerMode.Name = "checkAutoApplyWindowsPowerMode";
checkAutoApplyWindowsPowerMode.Size = new Size(416, 36); checkAutoApplyWindowsPowerMode.Size = new Size(416, 36);
checkAutoApplyWindowsPowerMode.TabIndex = 47; checkAutoApplyWindowsPowerMode.TabIndex = 47;
checkAutoApplyWindowsPowerMode.Text = "Auto Adjust Windows Power Mode"; checkAutoApplyWindowsPowerMode.Text = "Auto Adjust Windows Power Mode";
checkAutoApplyWindowsPowerMode.UseVisualStyleBackColor = true; checkAutoApplyWindowsPowerMode.UseVisualStyleBackColor = true;
// //
// checkKeyboardAuto
//
checkKeyboardAuto.AutoSize = true;
checkKeyboardAuto.Location = new Point(25, 50);
checkKeyboardAuto.MaximumSize = new Size(780, 0);
checkKeyboardAuto.Name = "checkKeyboardAuto";
checkKeyboardAuto.Size = new Size(712, 36);
checkKeyboardAuto.TabIndex = 46;
checkKeyboardAuto.Text = Strings.KeyboardAuto;
checkKeyboardAuto.UseVisualStyleBackColor = true;
//
// checkUSBC // checkUSBC
// //
checkUSBC.AutoSize = true; checkUSBC.AutoSize = true;
checkUSBC.Location = new Point(25, 170); checkUSBC.Location = new Point(25, 125);
checkUSBC.Name = "checkUSBC"; checkUSBC.Name = "checkUSBC";
checkUSBC.Size = new Size(659, 36); checkUSBC.Size = new Size(659, 36);
checkUSBC.TabIndex = 4; checkUSBC.TabIndex = 4;
@@ -762,7 +777,7 @@ namespace GHelper
// checkNoOverdrive // checkNoOverdrive
// //
checkNoOverdrive.AutoSize = true; checkNoOverdrive.AutoSize = true;
checkNoOverdrive.Location = new Point(25, 212); checkNoOverdrive.Location = new Point(25, 167);
checkNoOverdrive.Name = "checkNoOverdrive"; checkNoOverdrive.Name = "checkNoOverdrive";
checkNoOverdrive.Size = new Size(307, 36); checkNoOverdrive.Size = new Size(307, 36);
checkNoOverdrive.TabIndex = 3; checkNoOverdrive.TabIndex = 3;
@@ -772,47 +787,20 @@ namespace GHelper
// checkTopmost // checkTopmost
// //
checkTopmost.AutoSize = true; checkTopmost.AutoSize = true;
checkTopmost.Location = new Point(25, 254); checkTopmost.Location = new Point(25, 209);
checkTopmost.Name = "checkTopmost"; checkTopmost.Name = "checkTopmost";
checkTopmost.Size = new Size(390, 36); checkTopmost.Size = new Size(390, 36);
checkTopmost.TabIndex = 1; checkTopmost.TabIndex = 1;
checkTopmost.Text = Strings.WindowTop; checkTopmost.Text = Strings.WindowTop;
checkTopmost.UseVisualStyleBackColor = true; checkTopmost.UseVisualStyleBackColor = true;
// //
// labelFNC
//
labelFNC.AutoSize = true;
labelFNC.Location = new Point(13, 258);
labelFNC.Name = "labelFNC";
labelFNC.Size = new Size(80, 32);
labelFNC.TabIndex = 15;
labelFNC.Text = "FN+C:";
//
// comboFNC
//
comboFNC.BorderColor = Color.White;
comboFNC.ButtonColor = Color.FromArgb(255, 255, 255);
comboFNC.FormattingEnabled = true;
comboFNC.Location = new Point(188, 261);
comboFNC.Name = "comboFNC";
comboFNC.Size = new Size(312, 40);
comboFNC.TabIndex = 16;
//
// textFNC
//
textFNC.Location = new Point(538, 261);
textFNC.Name = "textFNC";
textFNC.PlaceholderText = "action";
textFNC.Size = new Size(346, 39);
textFNC.TabIndex = 17;
//
// Extra // Extra
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
AutoSize = true; AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoSizeMode = AutoSizeMode.GrowAndShrink;
ClientSize = new Size(974, 1262); ClientSize = new Size(974, 1247);
Controls.Add(groupOther); Controls.Add(groupOther);
Controls.Add(groupLight); Controls.Add(groupLight);
Controls.Add(groupBindings); Controls.Add(groupBindings);
@@ -894,7 +882,6 @@ namespace GHelper
private CheckBox checkXMG; private CheckBox checkXMG;
private Label labelBacklightTimeout; private Label labelBacklightTimeout;
private NumericUpDown numericBacklightTime; private NumericUpDown numericBacklightTime;
private CheckBox checkKeyboardAuto;
private CheckBox checkAutoApplyWindowsPowerMode; private CheckBox checkAutoApplyWindowsPowerMode;
private TableLayoutPanel tableKeys; private TableLayoutPanel tableKeys;
private Label labelM1; private Label labelM1;

View File

@@ -94,7 +94,6 @@ namespace GHelper
labelBacklightTimeout.Text = Properties.Strings.BacklightTimeout; labelBacklightTimeout.Text = Properties.Strings.BacklightTimeout;
labelBacklightTimeoutPlugged.Text = Properties.Strings.BacklightTimeoutPlugged; labelBacklightTimeoutPlugged.Text = Properties.Strings.BacklightTimeoutPlugged;
checkKeyboardAuto.Text = Properties.Strings.KeyboardAuto;
checkNoOverdrive.Text = Properties.Strings.DisableOverdrive; checkNoOverdrive.Text = Properties.Strings.DisableOverdrive;
checkTopmost.Text = Properties.Strings.WindowTop; checkTopmost.Text = Properties.Strings.WindowTop;
checkUSBC.Text = Properties.Strings.OptimizedUSBC; checkUSBC.Text = Properties.Strings.OptimizedUSBC;
@@ -199,9 +198,6 @@ namespace GHelper
checkTopmost.Checked = (AppConfig.getConfig("topmost") == 1); checkTopmost.Checked = (AppConfig.getConfig("topmost") == 1);
checkTopmost.CheckedChanged += CheckTopmost_CheckedChanged; ; checkTopmost.CheckedChanged += CheckTopmost_CheckedChanged; ;
checkKeyboardAuto.Checked = (AppConfig.getConfig("keyboard_auto") == 1);
checkKeyboardAuto.CheckedChanged += CheckKeyboardAuto_CheckedChanged;
checkNoOverdrive.Checked = (AppConfig.getConfig("no_overdrive") == 1); checkNoOverdrive.Checked = (AppConfig.getConfig("no_overdrive") == 1);
checkNoOverdrive.CheckedChanged += CheckNoOverdrive_CheckedChanged; checkNoOverdrive.CheckedChanged += CheckNoOverdrive_CheckedChanged;
@@ -283,10 +279,6 @@ namespace GHelper
Program.settingsForm.AutoScreen(true); Program.settingsForm.AutoScreen(true);
} }
private void CheckKeyboardAuto_CheckedChanged(object? sender, EventArgs e)
{
AppConfig.setConfig("keyboard_auto", (checkKeyboardAuto.Checked ? 1 : 0));
}
private void CheckTopmost_CheckedChanged(object? sender, EventArgs e) private void CheckTopmost_CheckedChanged(object? sender, EventArgs e)
{ {

View File

@@ -53,7 +53,7 @@ namespace GHelper
public class InputDispatcher public class InputDispatcher
{ {
System.Timers.Timer timer = new System.Timers.Timer(1000); System.Timers.Timer timer = new System.Timers.Timer(1000);
public bool backlight = true; public bool backlightActivity = true;
public static Keys keyProfile = Keys.F5; public static Keys keyProfile = Keys.F5;
public static Keys keyApp = Keys.F12; public static Keys keyApp = Keys.F12;
@@ -80,8 +80,9 @@ namespace GHelper
private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{ {
TimeSpan iddle = NativeMethods.GetIdleTime(); if (GetBacklight() == 0) return;
TimeSpan iddle = NativeMethods.GetIdleTime();
int kb_timeout; int kb_timeout;
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online) if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
@@ -91,16 +92,16 @@ namespace GHelper
if (kb_timeout == 0) return; if (kb_timeout == 0) return;
if (backlight && iddle.TotalSeconds > kb_timeout) if (backlightActivity && iddle.TotalSeconds > kb_timeout)
{ {
backlight = false; backlightActivity = false;
AsusUSB.ApplyBrightness(0); AsusUSB.ApplyBrightness(0, "Timeout");
} }
if (!backlight && iddle.TotalSeconds < kb_timeout) if (!backlightActivity && iddle.TotalSeconds < kb_timeout)
{ {
backlight = true; backlightActivity = true;
AsusUSB.ApplyBrightness(AppConfig.getConfig("keyboard_brightness")); SetBacklightAuto();
} }
//Debug.WriteLine(iddle.TotalSeconds); //Debug.WriteLine(iddle.TotalSeconds);
@@ -410,33 +411,61 @@ namespace GHelper
if (!OptimizationService.IsRunning()) OptimizationEvent(EventID); if (!OptimizationService.IsRunning()) OptimizationEvent(EventID);
} }
static int GetBacklight()
{
int backlight_power = AppConfig.getConfig("keyboard_brightness", 1);
int backlight_battery = AppConfig.getConfig("keyboard_brightness_ac", 1);
bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
return onBattery ? Math.Min(backlight_battery, backlight_power) : Math.Max(backlight_battery, backlight_power);
}
public static void SetBacklightAuto()
{
AsusUSB.ApplyBrightness(GetBacklight(), "Auto");
}
public static void SetBacklight(int delta)
{
int backlight_power = AppConfig.getConfig("keyboard_brightness", 1);
int backlight_battery = AppConfig.getConfig("keyboard_brightness_ac", 1);
bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
int backlight = onBattery ? backlight_battery : backlight_power;
if (delta >= 4)
backlight = (++backlight % 4);
else
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
if (onBattery)
AppConfig.setConfig("keyboard_brightness_ac", backlight);
else
AppConfig.setConfig("keyboard_brightness", backlight);
AsusUSB.ApplyBrightness(backlight, "HotKey");
string[] backlightNames = new string[] { "Off", "Low", "Mid", "Max" };
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, backlightNames[backlight], delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
}
static void OptimizationEvent(int EventID) static void OptimizationEvent(int EventID)
{ {
// Asus Optimization service Events // Asus Optimization service Events
int backlight = AppConfig.getConfig("keyboard_brightness");
string[] backlightNames = new string[] { "Off", "Low", "Mid", "Max" };
switch (EventID) switch (EventID)
{ {
case 197: // FN+F2 case 197: // FN+F2
backlight = Math.Max(0, backlight - 1); SetBacklight(-1);
AppConfig.setConfig("keyboard_brightness", backlight);
AsusUSB.ApplyBrightness(backlight);
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, backlightNames[backlight], ToastIcon.BacklightDown);
break; break;
case 196: // FN+F3 case 196: // FN+F3
backlight = Math.Min(3, backlight + 1); SetBacklight(1);
AppConfig.setConfig("keyboard_brightness", backlight);
AsusUSB.ApplyBrightness(backlight);
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, backlightNames[backlight], ToastIcon.BacklightUp);
break; break;
case 199: // ON Z13 - FN+F11 - cycles backlight case 199: // ON Z13 - FN+F11 - cycles backlight
if (++backlight > 3) backlight = 0; SetBacklight(4);
AppConfig.setConfig("keyboard_brightness", backlight);
AsusUSB.ApplyBrightness(backlight);
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, backlightNames[backlight], ToastIcon.BacklightUp);
break; break;
case 16: // FN+F7 case 16: // FN+F7
Program.acpi.DeviceSet(AsusACPI.UniversalControl, 0x10, "Brightness"); Program.acpi.DeviceSet(AsusACPI.UniversalControl, 0x10, "Brightness");

View File

@@ -181,6 +181,13 @@ namespace GHelper
CheckForUpdatesAsync(); CheckForUpdatesAsync();
}); });
Activated += SettingsForm_Activated;
}
private void SettingsForm_Activated(object? sender, EventArgs e)
{
if (fans != null && fans.Text != "") fans.BringToFront();
} }
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
@@ -1279,15 +1286,7 @@ namespace GHelper
public void AutoKeyboard() public void AutoKeyboard()
{ {
AsusUSB.Init(); AsusUSB.Init();
InputDispatcher.SetBacklightAuto();
int backlight = AppConfig.getConfig("keyboard_brightness");
if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)
AsusUSB.ApplyBrightness(0);
else
AsusUSB.ApplyBrightness(backlight);
} }
public void AutoPerformance() public void AutoPerformance()