From 92d1b97b9549a190dc110240bf6447fa90a74c7c Mon Sep 17 00:00:00 2001 From: seerge Date: Fri, 10 Mar 2023 21:50:20 +0100 Subject: [PATCH] Fix for UI lag on GPU switch --- ASUSWmi.cs | 3 +- Fans.Designer.cs | 79 ++++++++++++++++++++++++------------------------ GHelper.csproj | 2 +- Program.cs | 14 +++------ Settings.cs | 46 +++++++++++++++++++--------- 5 files changed, 80 insertions(+), 64 deletions(-) diff --git a/ASUSWmi.cs b/ASUSWmi.cs index 416f3e4a..3a72ef81 100644 --- a/ASUSWmi.cs +++ b/ASUSWmi.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using GHelper; +using System.Diagnostics; using System.Management; using System.Runtime.InteropServices; diff --git a/Fans.Designer.cs b/Fans.Designer.cs index 8a1f0871..7cac9dc6 100644 --- a/Fans.Designer.cs +++ b/Fans.Designer.cs @@ -66,7 +66,6 @@ // // panelFans // - panelFans.AutoSize = true; panelFans.Controls.Add(checkBoost); panelFans.Controls.Add(labelFans); panelFans.Controls.Add(checkAuto); @@ -75,19 +74,18 @@ panelFans.Controls.Add(buttonApply); panelFans.Controls.Add(chartCPU); panelFans.Dock = DockStyle.Left; - panelFans.Location = new Point(363, 0); - panelFans.Margin = new Padding(10); - panelFans.MinimumSize = new Size(872, 1089); + panelFans.Location = new Point(364, 0); + panelFans.Margin = new Padding(10, 10, 10, 10); panelFans.Name = "panelFans"; - panelFans.Padding = new Padding(10); - panelFans.Size = new Size(872, 1089); + panelFans.Padding = new Padding(10, 10, 10, 10); + panelFans.Size = new Size(824, 1092); panelFans.TabIndex = 12; // // checkBoost // checkBoost.AutoSize = true; checkBoost.ForeColor = SystemColors.ControlText; - checkBoost.Location = new Point(512, 15); + checkBoost.Location = new Point(484, 16); checkBoost.Margin = new Padding(4, 2, 4, 2); checkBoost.Name = "checkBoost"; checkBoost.Size = new Size(320, 36); @@ -99,7 +97,8 @@ // labelFans.AutoSize = true; labelFans.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelFans.Location = new Point(24, 15); + labelFans.Location = new Point(24, 16); + labelFans.Margin = new Padding(4, 0, 4, 0); labelFans.Name = "labelFans"; labelFans.Size = new Size(138, 32); labelFans.TabIndex = 28; @@ -109,7 +108,7 @@ // checkAuto.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; checkAuto.AutoSize = true; - checkAuto.Location = new Point(411, 1030); + checkAuto.Location = new Point(383, 1030); checkAuto.Margin = new Padding(4, 2, 4, 2); checkAuto.Name = "checkAuto"; checkAuto.Size = new Size(165, 36); @@ -122,20 +121,20 @@ chartGPU.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; chartArea1.Name = "ChartArea1"; chartGPU.ChartAreas.Add(chartArea1); - chartGPU.Location = new Point(22, 547); + chartGPU.Location = new Point(22, 548); chartGPU.Margin = new Padding(4, 2, 4, 2); chartGPU.Name = "chartGPU"; - chartGPU.Size = new Size(810, 460); + chartGPU.Size = new Size(784, 460); chartGPU.TabIndex = 16; chartGPU.Text = "chart1"; // // buttonReset // buttonReset.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonReset.Location = new Point(22, 1025); + buttonReset.Location = new Point(20, 1024); buttonReset.Margin = new Padding(4, 2, 4, 2); buttonReset.Name = "buttonReset"; - buttonReset.Size = new Size(231, 44); + buttonReset.Size = new Size(232, 44); buttonReset.TabIndex = 15; buttonReset.Text = "Factory Defaults"; buttonReset.UseVisualStyleBackColor = true; @@ -143,7 +142,7 @@ // buttonApply // buttonApply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonApply.Location = new Point(584, 1025); + buttonApply.Location = new Point(550, 1024); buttonApply.Margin = new Padding(4, 2, 4, 2); buttonApply.Name = "buttonApply"; buttonApply.Size = new Size(248, 44); @@ -157,9 +156,9 @@ chartArea2.Name = "ChartArea1"; chartCPU.ChartAreas.Add(chartArea2); chartCPU.Location = new Point(22, 66); - chartCPU.Margin = new Padding(10); + chartCPU.Margin = new Padding(10, 10, 10, 10); chartCPU.Name = "chartCPU"; - chartCPU.Size = new Size(810, 460); + chartCPU.Size = new Size(780, 460); chartCPU.TabIndex = 13; chartCPU.Text = "chartCPU"; // @@ -175,15 +174,18 @@ panelPower.Controls.Add(labelInfo); panelPower.Dock = DockStyle.Left; panelPower.Location = new Point(0, 0); + panelPower.Margin = new Padding(10, 10, 10, 10); panelPower.Name = "panelPower"; - panelPower.Size = new Size(363, 1089); + panelPower.Padding = new Padding(10, 10, 10, 10); + panelPower.Size = new Size(364, 1092); panelPower.TabIndex = 13; // // labelPowerLimits // labelPowerLimits.AutoSize = true; labelPowerLimits.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelPowerLimits.Location = new Point(23, 15); + labelPowerLimits.Location = new Point(24, 18); + labelPowerLimits.Margin = new Padding(4, 0, 4, 0); labelPowerLimits.Name = "labelPowerLimits"; labelPowerLimits.Size = new Size(229, 32); labelPowerLimits.TabIndex = 26; @@ -193,7 +195,7 @@ // checkApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; checkApplyPower.AutoSize = true; - checkApplyPower.Location = new Point(21, 982); + checkApplyPower.Location = new Point(32, 982); checkApplyPower.Margin = new Padding(4, 2, 4, 2); checkApplyPower.Name = "checkApplyPower"; checkApplyPower.Size = new Size(165, 36); @@ -204,10 +206,10 @@ // buttonApplyPower // buttonApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - buttonApplyPower.Location = new Point(17, 1025); + buttonApplyPower.Location = new Point(26, 1024); buttonApplyPower.Margin = new Padding(4, 2, 4, 2); buttonApplyPower.Name = "buttonApplyPower"; - buttonApplyPower.Size = new Size(321, 44); + buttonApplyPower.Size = new Size(300, 44); buttonApplyPower.TabIndex = 24; buttonApplyPower.Text = "Apply Power Limits"; buttonApplyPower.UseVisualStyleBackColor = true; @@ -217,7 +219,8 @@ panelCPU.Controls.Add(labelCPU); panelCPU.Controls.Add(label2); panelCPU.Controls.Add(trackCPU); - panelCPU.Location = new Point(184, 89); + panelCPU.Location = new Point(184, 90); + panelCPU.Margin = new Padding(4, 4, 4, 4); panelCPU.Name = "panelCPU"; panelCPU.Size = new Size(160, 510); panelCPU.TabIndex = 23; @@ -226,7 +229,7 @@ // labelCPU.AutoSize = true; labelCPU.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelCPU.Location = new Point(43, 41); + labelCPU.Location = new Point(44, 40); labelCPU.Margin = new Padding(4, 0, 4, 0); labelCPU.Name = "labelCPU"; labelCPU.Size = new Size(61, 32); @@ -237,7 +240,7 @@ // label2 // label2.AutoSize = true; - label2.Location = new Point(45, 7); + label2.Location = new Point(44, 8); label2.Margin = new Padding(4, 0, 4, 0); label2.Name = "label2"; label2.Size = new Size(58, 32); @@ -247,7 +250,7 @@ // // trackCPU // - trackCPU.Location = new Point(47, 89); + trackCPU.Location = new Point(48, 88); trackCPU.Margin = new Padding(4, 2, 4, 2); trackCPU.Maximum = 85; trackCPU.Minimum = 15; @@ -263,16 +266,17 @@ panelTotal.Controls.Add(labelTotal); panelTotal.Controls.Add(label1); panelTotal.Controls.Add(trackTotal); - panelTotal.Location = new Point(17, 89); + panelTotal.Location = new Point(16, 90); + panelTotal.Margin = new Padding(4, 4, 4, 4); panelTotal.Name = "panelTotal"; - panelTotal.Size = new Size(160, 511); + panelTotal.Size = new Size(160, 512); panelTotal.TabIndex = 22; // // labelTotal // labelTotal.AutoSize = true; labelTotal.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelTotal.Location = new Point(46, 41); + labelTotal.Location = new Point(46, 40); labelTotal.Margin = new Padding(4, 0, 4, 0); labelTotal.Name = "labelTotal"; labelTotal.Size = new Size(70, 32); @@ -283,7 +287,7 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(48, 7); + label1.Location = new Point(48, 8); label1.Margin = new Padding(4, 0, 4, 0); label1.Name = "label1"; label1.Size = new Size(65, 32); @@ -293,7 +297,7 @@ // // trackTotal // - trackTotal.Location = new Point(44, 89); + trackTotal.Location = new Point(44, 88); trackTotal.Margin = new Padding(4, 2, 4, 2); trackTotal.Maximum = 150; trackTotal.Minimum = 15; @@ -309,7 +313,7 @@ // labelApplied.AutoSize = true; labelApplied.ForeColor = Color.Tomato; - labelApplied.Location = new Point(23, 51); + labelApplied.Location = new Point(24, 54); labelApplied.Margin = new Padding(4, 0, 4, 0); labelApplied.Name = "labelApplied"; labelApplied.Size = new Size(143, 32); @@ -321,10 +325,10 @@ pictureFine.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; pictureFine.BackgroundImageLayout = ImageLayout.Zoom; pictureFine.Image = Properties.Resources.everything_is_fine_itsfine; - pictureFine.Location = new Point(17, 671); + pictureFine.Location = new Point(20, 666); pictureFine.Margin = new Padding(4, 2, 4, 2); pictureFine.Name = "pictureFine"; - pictureFine.Size = new Size(327, 254); + pictureFine.Size = new Size(324, 268); pictureFine.SizeMode = PictureBoxSizeMode.Zoom; pictureFine.TabIndex = 20; pictureFine.TabStop = false; @@ -332,10 +336,10 @@ // // labelInfo // - labelInfo.Location = new Point(17, 603); + labelInfo.Location = new Point(24, 604); labelInfo.Margin = new Padding(4, 0, 4, 0); labelInfo.Name = "labelInfo"; - labelInfo.Size = new Size(327, 330); + labelInfo.Size = new Size(320, 330); labelInfo.TabIndex = 19; labelInfo.Text = "label"; // @@ -344,15 +348,13 @@ AutoScaleDimensions = new SizeF(192F, 192F); AutoScaleMode = AutoScaleMode.Dpi; AutoSize = true; - AutoSizeMode = AutoSizeMode.GrowAndShrink; - ClientSize = new Size(1220, 1089); + ClientSize = new Size(1196, 1092); Controls.Add(panelFans); Controls.Add(panelPower); Margin = new Padding(4, 2, 4, 2); MaximizeBox = false; MdiChildrenMinimizedAnchorBottom = false; MinimizeBox = false; - MinimumSize = new Size(0, 1160); Name = "Fans"; ShowIcon = false; ShowInTaskbar = false; @@ -372,7 +374,6 @@ ((System.ComponentModel.ISupportInitialize)trackTotal).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureFine).EndInit(); ResumeLayout(false); - PerformLayout(); } #endregion diff --git a/GHelper.csproj b/GHelper.csproj index ef724cf1..2414a0d9 100644 --- a/GHelper.csproj +++ b/GHelper.csproj @@ -15,8 +15,8 @@ GHelper x64 False - 0.21 True + 0.23 diff --git a/Program.cs b/Program.cs index c4392455..76bc9f7f 100644 --- a/Program.cs +++ b/Program.cs @@ -143,10 +143,6 @@ namespace GHelper case PBT_APMRESUMEAUTOMATIC: settingsForm.BeginInvoke(delegate { - // Setting "other" mode to prevent bios bugging with PPTs after wake up from sleep - wmi.DeviceSet(ASUSWmi.PerformanceMode, config.getConfig("performance_mode")); - Thread.Sleep(1000); - SetAutoModes(); }); break; @@ -159,7 +155,8 @@ namespace GHelper static async void CheckForUpdates() { - settingsForm.SetVersionLabel("Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); + var assembly = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + settingsForm.SetVersionLabel("Version: " + assembly); try { @@ -170,12 +167,11 @@ namespace GHelper var config = JsonSerializer.Deserialize(json); var tag = config.GetProperty("tag_name").ToString().Replace("v", ""); var url = config.GetProperty("assets")[0].GetProperty("browser_download_url").ToString(); - var assembly = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - + var gitVersion = new Version(tag); - var appVersion = new Version(); + var appVersion = new Version(assembly); - var result = appVersion.CompareTo(gitVersion); + var result = gitVersion.CompareTo(appVersion); if (result > 0) { settingsForm.SetVersionLabel("Download Update: " + tag, url); diff --git a/Settings.cs b/Settings.cs index 7530fd03..466658f4 100644 --- a/Settings.cs +++ b/Settings.cs @@ -60,6 +60,7 @@ namespace GHelper buttonQuit.Click += ButtonQuit_Click; + checkGPU.CheckedChanged += CheckGPU_CheckedChanged; checkScreen.CheckedChanged += checkScreen_CheckedChanged; @@ -96,6 +97,13 @@ namespace GHelper } + private void CheckGPU_CheckedChanged(object? sender, EventArgs e) + { + if (sender is null) return; + CheckBox check = (CheckBox)sender; + Program.config.setConfig("gpu_auto", check.Checked ? 1 : 0); + } + public void SetVersionLabel(string label, string url = null) { labelVersion.Text = label; @@ -717,8 +725,15 @@ namespace GHelper if (Program.config.getConfigPerf("auto_apply_power") == 1) { - SetPower(); + var timer = new System.Timers.Timer(500); + timer.Elapsed += delegate + { + SetPower(); + timer.Stop(); + }; + timer.Start(); } + } public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false) @@ -822,13 +837,11 @@ namespace GHelper { if (eco == 1 && Plugged == PowerLineStatus.Online) // Eco going Standard on plugged { - Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0); - InitGPUMode(); + SetEcoGPU(0); } else if (eco == 0 && Plugged != PowerLineStatus.Online) // Standard going Eco on plugged { - Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1); - InitGPUMode(); + SetEcoGPU(1); } } @@ -862,6 +875,18 @@ namespace GHelper } + + public void SetEcoGPU(int eco) + { + new Thread(() => + { + Thread.CurrentThread.IsBackground = true; + Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco); + BeginInvoke(delegate { InitGPUMode(); }); + }).Start(); + + } + public void SetGPUMode(int GPUMode = ASUSWmi.GPUModeStandard) { @@ -897,13 +922,13 @@ namespace GHelper else if (GPUMode == ASUSWmi.GPUModeEco) { VisualiseGPUMode(GPUMode); - Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1); + SetEcoGPU(1); changed = true; } else if (GPUMode == ASUSWmi.GPUModeStandard) { VisualiseGPUMode(GPUMode); - Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0); + SetEcoGPU(0); changed = true; } @@ -1013,13 +1038,6 @@ namespace GHelper SetBatteryChargeLimit(bar.Value); } - private void checkGPU_CheckedChanged(object? sender, EventArgs e) - { - if (sender is null) return; - CheckBox check = (CheckBox)sender; - Program.config.setConfig("gpu_auto", check.Checked ? 1 : 0); - } - private void checkScreen_CheckedChanged(object? sender, EventArgs e) {