Compare commits

..

10 Commits
new ... v0.8

8 changed files with 462 additions and 55 deletions

View File

@@ -31,7 +31,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup>

View File

@@ -1,10 +1,12 @@
using Microsoft.Win32.TaskScheduler;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Diagnostics;
using System.Management;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
public class ASUSWmi
{
private ManagementObject mo;
@@ -19,6 +21,7 @@ public class ASUSWmi
public const int GPUMux = 0x00090016;
public const int BatteryLimit = 0x00120057;
public const int ScreenOverdrive = 0x00050019;
public const int PerformanceBalanced = 0;
public const int PerformanceTurbo = 1;
@@ -49,8 +52,29 @@ public class ASUSWmi
ManagementBaseObject outParams = this.mo.InvokeMethod(MethodName, inParams, null);
foreach (PropertyData property in outParams.Properties)
{
if (property.Name == "device_status") return int.Parse(property.Value.ToString()) - 65536;
if (property.Name == "result") return int.Parse(property.Value.ToString());
if (property.Name == "device_status")
{
int status;
try
{
status = int.Parse(property.Value.ToString());
status -= 65536;
return status;
} catch
{
return -1;
}
}
if (property.Name == "result")
{
try
{
return int.Parse(property.Value.ToString());
} catch
{
return -1;
}
}
}
return -1;
@@ -147,9 +171,14 @@ public class AppConfig
if (File.Exists(configFile))
{
string text = File.ReadAllText(configFile);
config = JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
if (config is null)
try
{
config = JsonSerializer.Deserialize<Dictionary<string, object>>(text);
}
catch
{
initConfig();
}
}
else
{
@@ -162,7 +191,7 @@ public class AppConfig
{
config = new Dictionary<string, object>();
config["performance_mode"] = 0;
string jsonString = JsonConvert.SerializeObject(config);
string jsonString = JsonSerializer.Serialize(config);
File.WriteAllText(configFile, jsonString);
}
@@ -176,12 +205,151 @@ public class AppConfig
public void setConfig(string name, int value)
{
config[name] = value;
string jsonString = JsonConvert.SerializeObject(config);
string jsonString = JsonSerializer.Serialize(config);
File.WriteAllText(configFile, jsonString);
}
}
public class NativeMethods
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
[Flags()]
public enum DisplaySettingsFlags : int
{
CDS_UPDATEREGISTRY = 1,
CDS_TEST = 2,
CDS_FULLSCREEN = 4,
CDS_GLOBAL = 8,
CDS_SET_PRIMARY = 0x10,
CDS_RESET = 0x40000000,
CDS_NORESET = 0x10000000
}
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int EnumDisplaySettingsEx(
string lpszDeviceName,
int iModeNum,
ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettingsEx(
string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
DisplaySettingsFlags dwflags, IntPtr lParam);
public const int ENUM_CURRENT_SETTINGS = -1;
public const string laptopScreenName = "\\\\.\\DISPLAY1";
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
public static Screen FindLaptopScreen()
{
var screens = Screen.AllScreens;
Screen laptopScreen = null;
foreach (var screen in screens)
{
if (screen.DeviceName == laptopScreenName)
{
laptopScreen = screen;
}
}
if (laptopScreen is null) return null;
else return laptopScreen;
}
public static int GetRefreshRate()
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
int frequency = -1;
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
return frequency;
}
public static int SetRefreshRate(int frequency = 120)
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmDisplayFrequency = frequency;
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen.DeviceName, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
return iRet;
}
return 0;
}
}
namespace GHelper
@@ -223,6 +391,8 @@ namespace GHelper
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
settingsForm.VisualiseGPUAuto(config.getConfig("gpu_auto"));
settingsForm.VisualiseScreenAuto(config.getConfig("screen_auto"));
settingsForm.SetStartupCheck(scheduler.IsScheduled());
Application.Run();
@@ -233,6 +403,9 @@ namespace GHelper
static void WatcherEventArrived(object sender, EventArrivedEventArgs e)
{
var collection = (ManagementEventWatcher)sender;
if (e.NewEvent is null) return;
int EventID = int.Parse(e.NewEvent["EventID"].ToString());
Debug.WriteLine(EventID);
@@ -250,6 +423,7 @@ namespace GHelper
settingsForm.BeginInvoke(delegate
{
settingsForm.AutoGPUMode(0);
settingsForm.AutoScreen(0);
});
return;
case 88: // Plugged
@@ -257,6 +431,7 @@ namespace GHelper
settingsForm.BeginInvoke(delegate
{
settingsForm.AutoGPUMode(1);
settingsForm.AutoScreen(1);
});
return;

View File

@@ -80,6 +80,16 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_laptop_48 {
get {
object obj = ResourceManager.GetObject("icons8-laptop-48", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -118,22 +118,25 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="icons8-charging-battery-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-charging-battery-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="eco" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\eco.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="standard" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\standard.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ultimate" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ultimate.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-video-card-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-video-card-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="standard" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\standard.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-speed-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-speed-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-video-card-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-video-card-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-charging-battery-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-charging-battery-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-laptop-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-laptop-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@@ -1,8 +1,10 @@
# G14-Helper
A tiny system tray utility that allows you set performance and GPU profiles for your laptop. Same as ASUS Armory Crate does but without it completely!.
Designed for Asus Zephyrus G14 2022 (with AMD Radeon iGPU and dGPU). But could and should potentially work for G14 of 2021 and 2020, G15, X FLOW, and other ROG models.
A tiny system tray utility that allows you set performance and GPU profiles for your laptop. Same as ASUS Armory Crate does but without it completely!.
![Screenshot](https://github.com/seerge/g14-helper/blob/main/screenshot.png)
## Performance Profile switching
@@ -23,8 +25,9 @@ Profiles are **same** as in Armory Crate, including default fan curves
1. **Maximum battery charge rate** limit (60% / 80% / 100%) to preserve your battery
2. CPU and GPU relative fan speed monitoring
3. Automatic switching of Standard/Eco GPU modes when laptop is plugged / unplugged!
4. Start with windows (optional)
4. FN+F5 an M4 (Rog) keys cycle through Performance modes
5. Screen resolution and display overdrive switching
6. Run on startup (optional)
## How to install
@@ -39,9 +42,7 @@ I don`t have Microsoft certificate to sign app yet, so if you set a warning from
Alternatively you can comile and run project by yourself :)
![Screenshot](https://github.com/seerge/g14-helper/blob/main/screenshot.png)
Settings are located in APPDATA\ROAMING
Settings file is storer at %AppData%\GHelper
P.S.: It's not recommended to use app in combination with Armory Crate, cause they adjust same settings.
Please keep in mind, that if you also run MyASUS app periodically it will also try to adjust same battery charge settings

154
Settings.Designer.cs generated
View File

@@ -49,19 +49,27 @@
this.labelPerf = new System.Windows.Forms.Label();
this.checkGPU = new System.Windows.Forms.CheckBox();
this.buttonQuit = new System.Windows.Forms.Button();
this.pictureScreen = new System.Windows.Forms.PictureBox();
this.labelSreen = new System.Windows.Forms.Label();
this.tableScreen = new System.Windows.Forms.TableLayoutPanel();
this.button120Hz = new System.Windows.Forms.Button();
this.button60Hz = new System.Windows.Forms.Button();
this.checkScreen = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.trackBattery)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBattery)).BeginInit();
this.tableGPU.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureGPU)).BeginInit();
this.tablePerf.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picturePerf)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureScreen)).BeginInit();
this.tableScreen.SuspendLayout();
this.SuspendLayout();
//
// checkStartup
//
this.checkStartup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkStartup.AutoSize = true;
this.checkStartup.Location = new System.Drawing.Point(34, 640);
this.checkStartup.Location = new System.Drawing.Point(34, 836);
this.checkStartup.Name = "checkStartup";
this.checkStartup.Size = new System.Drawing.Size(206, 36);
this.checkStartup.TabIndex = 2;
@@ -74,11 +82,11 @@
this.trackBattery.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.trackBattery.LargeChange = 20;
this.trackBattery.Location = new System.Drawing.Point(23, 532);
this.trackBattery.Location = new System.Drawing.Point(23, 744);
this.trackBattery.Maximum = 100;
this.trackBattery.Minimum = 50;
this.trackBattery.Name = "trackBattery";
this.trackBattery.Size = new System.Drawing.Size(702, 90);
this.trackBattery.Size = new System.Drawing.Size(651, 90);
this.trackBattery.SmallChange = 10;
this.trackBattery.TabIndex = 3;
this.trackBattery.TickFrequency = 10;
@@ -89,7 +97,7 @@
//
this.labelBattery.AutoSize = true;
this.labelBattery.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.labelBattery.Location = new System.Drawing.Point(83, 486);
this.labelBattery.Location = new System.Drawing.Point(83, 701);
this.labelBattery.Name = "labelBattery";
this.labelBattery.Size = new System.Drawing.Size(248, 32);
this.labelBattery.TabIndex = 4;
@@ -99,7 +107,7 @@
//
this.labelBatteryLimit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelBatteryLimit.AutoSize = true;
this.labelBatteryLimit.Location = new System.Drawing.Point(647, 484);
this.labelBatteryLimit.Location = new System.Drawing.Point(596, 699);
this.labelBatteryLimit.Name = "labelBatteryLimit";
this.labelBatteryLimit.Size = new System.Drawing.Size(73, 32);
this.labelBatteryLimit.TabIndex = 5;
@@ -108,7 +116,7 @@
// pictureBattery
//
this.pictureBattery.Image = global::GHelper.Properties.Resources.icons8_charging_battery_48;
this.pictureBattery.Location = new System.Drawing.Point(32, 478);
this.pictureBattery.Location = new System.Drawing.Point(32, 693);
this.pictureBattery.Name = "pictureBattery";
this.pictureBattery.Size = new System.Drawing.Size(48, 48);
this.pictureBattery.TabIndex = 6;
@@ -118,7 +126,7 @@
//
this.labelGPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelGPUFan.AutoSize = true;
this.labelGPUFan.Location = new System.Drawing.Point(566, 242);
this.labelGPUFan.Location = new System.Drawing.Point(515, 234);
this.labelGPUFan.Name = "labelGPUFan";
this.labelGPUFan.Size = new System.Drawing.Size(155, 32);
this.labelGPUFan.TabIndex = 8;
@@ -135,11 +143,11 @@
this.tableGPU.Controls.Add(this.buttonUltimate, 2, 0);
this.tableGPU.Controls.Add(this.buttonStandard, 1, 0);
this.tableGPU.Controls.Add(this.buttonEco, 0, 0);
this.tableGPU.Location = new System.Drawing.Point(23, 289);
this.tableGPU.Location = new System.Drawing.Point(23, 276);
this.tableGPU.Name = "tableGPU";
this.tableGPU.RowCount = 1;
this.tableGPU.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F));
this.tableGPU.Size = new System.Drawing.Size(702, 106);
this.tableGPU.Size = new System.Drawing.Size(651, 106);
this.tableGPU.TabIndex = 7;
//
// buttonUltimate
@@ -148,10 +156,10 @@
this.buttonUltimate.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonUltimate.FlatAppearance.BorderSize = 0;
this.buttonUltimate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonUltimate.Location = new System.Drawing.Point(478, 10);
this.buttonUltimate.Location = new System.Drawing.Point(444, 10);
this.buttonUltimate.Margin = new System.Windows.Forms.Padding(10);
this.buttonUltimate.Name = "buttonUltimate";
this.buttonUltimate.Size = new System.Drawing.Size(214, 86);
this.buttonUltimate.Size = new System.Drawing.Size(197, 86);
this.buttonUltimate.TabIndex = 2;
this.buttonUltimate.Text = "Ultimate";
this.buttonUltimate.UseVisualStyleBackColor = false;
@@ -162,10 +170,10 @@
this.buttonStandard.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonStandard.FlatAppearance.BorderSize = 0;
this.buttonStandard.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonStandard.Location = new System.Drawing.Point(244, 10);
this.buttonStandard.Location = new System.Drawing.Point(227, 10);
this.buttonStandard.Margin = new System.Windows.Forms.Padding(10);
this.buttonStandard.Name = "buttonStandard";
this.buttonStandard.Size = new System.Drawing.Size(214, 86);
this.buttonStandard.Size = new System.Drawing.Size(197, 86);
this.buttonStandard.TabIndex = 1;
this.buttonStandard.Text = "Standard";
this.buttonStandard.UseVisualStyleBackColor = false;
@@ -180,7 +188,7 @@
this.buttonEco.Location = new System.Drawing.Point(10, 10);
this.buttonEco.Margin = new System.Windows.Forms.Padding(10);
this.buttonEco.Name = "buttonEco";
this.buttonEco.Size = new System.Drawing.Size(214, 86);
this.buttonEco.Size = new System.Drawing.Size(197, 86);
this.buttonEco.TabIndex = 0;
this.buttonEco.Text = "Eco";
this.buttonEco.UseVisualStyleBackColor = false;
@@ -189,7 +197,7 @@
//
this.labelGPU.AutoSize = true;
this.labelGPU.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.labelGPU.Location = new System.Drawing.Point(82, 242);
this.labelGPU.Location = new System.Drawing.Point(82, 234);
this.labelGPU.Name = "labelGPU";
this.labelGPU.Size = new System.Drawing.Size(136, 32);
this.labelGPU.TabIndex = 9;
@@ -198,7 +206,7 @@
// pictureGPU
//
this.pictureGPU.Image = global::GHelper.Properties.Resources.icons8_video_card_48;
this.pictureGPU.Location = new System.Drawing.Point(29, 234);
this.pictureGPU.Location = new System.Drawing.Point(32, 226);
this.pictureGPU.Name = "pictureGPU";
this.pictureGPU.Size = new System.Drawing.Size(48, 48);
this.pictureGPU.TabIndex = 10;
@@ -208,7 +216,7 @@
//
this.labelCPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelCPUFan.AutoSize = true;
this.labelCPUFan.Location = new System.Drawing.Point(568, 39);
this.labelCPUFan.Location = new System.Drawing.Point(517, 39);
this.labelCPUFan.Name = "labelCPUFan";
this.labelCPUFan.Size = new System.Drawing.Size(154, 32);
this.labelCPUFan.TabIndex = 12;
@@ -225,11 +233,11 @@
this.tablePerf.Controls.Add(this.buttonTurbo, 2, 0);
this.tablePerf.Controls.Add(this.buttonBalanced, 1, 0);
this.tablePerf.Controls.Add(this.buttonSilent, 0, 0);
this.tablePerf.Location = new System.Drawing.Point(23, 90);
this.tablePerf.Location = new System.Drawing.Point(23, 79);
this.tablePerf.Name = "tablePerf";
this.tablePerf.RowCount = 1;
this.tablePerf.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F));
this.tablePerf.Size = new System.Drawing.Size(702, 106);
this.tablePerf.Size = new System.Drawing.Size(651, 106);
this.tablePerf.TabIndex = 11;
//
// buttonTurbo
@@ -239,10 +247,10 @@
this.buttonTurbo.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.buttonTurbo.FlatAppearance.BorderSize = 0;
this.buttonTurbo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonTurbo.Location = new System.Drawing.Point(478, 10);
this.buttonTurbo.Location = new System.Drawing.Point(444, 10);
this.buttonTurbo.Margin = new System.Windows.Forms.Padding(10);
this.buttonTurbo.Name = "buttonTurbo";
this.buttonTurbo.Size = new System.Drawing.Size(214, 86);
this.buttonTurbo.Size = new System.Drawing.Size(197, 86);
this.buttonTurbo.TabIndex = 2;
this.buttonTurbo.Text = "Turbo";
this.buttonTurbo.UseVisualStyleBackColor = false;
@@ -254,10 +262,10 @@
this.buttonBalanced.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.buttonBalanced.FlatAppearance.BorderSize = 0;
this.buttonBalanced.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonBalanced.Location = new System.Drawing.Point(244, 10);
this.buttonBalanced.Location = new System.Drawing.Point(227, 10);
this.buttonBalanced.Margin = new System.Windows.Forms.Padding(10);
this.buttonBalanced.Name = "buttonBalanced";
this.buttonBalanced.Size = new System.Drawing.Size(214, 86);
this.buttonBalanced.Size = new System.Drawing.Size(197, 86);
this.buttonBalanced.TabIndex = 1;
this.buttonBalanced.Text = "Balanced";
this.buttonBalanced.UseVisualStyleBackColor = false;
@@ -273,7 +281,7 @@
this.buttonSilent.Location = new System.Drawing.Point(10, 10);
this.buttonSilent.Margin = new System.Windows.Forms.Padding(10);
this.buttonSilent.Name = "buttonSilent";
this.buttonSilent.Size = new System.Drawing.Size(214, 86);
this.buttonSilent.Size = new System.Drawing.Size(197, 86);
this.buttonSilent.TabIndex = 0;
this.buttonSilent.Text = "Silent";
this.buttonSilent.UseVisualStyleBackColor = false;
@@ -281,7 +289,7 @@
// picturePerf
//
this.picturePerf.Image = global::GHelper.Properties.Resources.icons8_speed_48;
this.picturePerf.Location = new System.Drawing.Point(30, 29);
this.picturePerf.Location = new System.Drawing.Point(32, 29);
this.picturePerf.Name = "picturePerf";
this.picturePerf.Size = new System.Drawing.Size(48, 48);
this.picturePerf.TabIndex = 14;
@@ -300,7 +308,7 @@
// checkGPU
//
this.checkGPU.AutoSize = true;
this.checkGPU.Location = new System.Drawing.Point(34, 400);
this.checkGPU.Location = new System.Drawing.Point(34, 385);
this.checkGPU.Name = "checkGPU";
this.checkGPU.Size = new System.Drawing.Size(614, 36);
this.checkGPU.TabIndex = 15;
@@ -312,18 +320,100 @@
//
this.buttonQuit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonQuit.BackColor = System.Drawing.SystemColors.ButtonFace;
this.buttonQuit.Location = new System.Drawing.Point(602, 634);
this.buttonQuit.Location = new System.Drawing.Point(551, 830);
this.buttonQuit.Name = "buttonQuit";
this.buttonQuit.Size = new System.Drawing.Size(120, 46);
this.buttonQuit.TabIndex = 16;
this.buttonQuit.Text = "Quit";
this.buttonQuit.UseVisualStyleBackColor = false;
//
// pictureScreen
//
this.pictureScreen.Image = global::GHelper.Properties.Resources.icons8_laptop_48;
this.pictureScreen.Location = new System.Drawing.Point(32, 463);
this.pictureScreen.Name = "pictureScreen";
this.pictureScreen.Size = new System.Drawing.Size(48, 48);
this.pictureScreen.TabIndex = 18;
this.pictureScreen.TabStop = false;
//
// labelSreen
//
this.labelSreen.AutoSize = true;
this.labelSreen.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.labelSreen.Location = new System.Drawing.Point(82, 471);
this.labelSreen.Name = "labelSreen";
this.labelSreen.Size = new System.Drawing.Size(176, 32);
this.labelSreen.TabIndex = 17;
this.labelSreen.Text = "Laptop Screen";
//
// tableScreen
//
this.tableScreen.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableScreen.ColumnCount = 3;
this.tableScreen.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableScreen.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableScreen.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableScreen.Controls.Add(this.button120Hz, 1, 0);
this.tableScreen.Controls.Add(this.button60Hz, 0, 0);
this.tableScreen.Location = new System.Drawing.Point(23, 513);
this.tableScreen.Name = "tableScreen";
this.tableScreen.RowCount = 1;
this.tableScreen.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F));
this.tableScreen.Size = new System.Drawing.Size(651, 103);
this.tableScreen.TabIndex = 19;
//
// button120Hz
//
this.button120Hz.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.button120Hz.Dock = System.Windows.Forms.DockStyle.Fill;
this.button120Hz.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveBorder;
this.button120Hz.FlatAppearance.BorderSize = 0;
this.button120Hz.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button120Hz.Location = new System.Drawing.Point(227, 10);
this.button120Hz.Margin = new System.Windows.Forms.Padding(10);
this.button120Hz.Name = "button120Hz";
this.button120Hz.Size = new System.Drawing.Size(197, 86);
this.button120Hz.TabIndex = 1;
this.button120Hz.Text = "120Hz + OD";
this.button120Hz.UseVisualStyleBackColor = false;
//
// button60Hz
//
this.button60Hz.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.button60Hz.CausesValidation = false;
this.button60Hz.Dock = System.Windows.Forms.DockStyle.Fill;
this.button60Hz.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveBorder;
this.button60Hz.FlatAppearance.BorderSize = 0;
this.button60Hz.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button60Hz.ForeColor = System.Drawing.SystemColors.ControlText;
this.button60Hz.Location = new System.Drawing.Point(10, 10);
this.button60Hz.Margin = new System.Windows.Forms.Padding(10);
this.button60Hz.Name = "button60Hz";
this.button60Hz.Size = new System.Drawing.Size(197, 86);
this.button60Hz.TabIndex = 0;
this.button60Hz.Text = "60Hz";
this.button60Hz.UseVisualStyleBackColor = false;
//
// checkScreen
//
this.checkScreen.AutoSize = true;
this.checkScreen.Location = new System.Drawing.Point(34, 622);
this.checkScreen.Name = "checkScreen";
this.checkScreen.Size = new System.Drawing.Size(562, 36);
this.checkScreen.TabIndex = 20;
this.checkScreen.Text = "Switch 60Hz on battery, and back when plugged";
this.checkScreen.UseVisualStyleBackColor = true;
//
// SettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(756, 704);
this.ClientSize = new System.Drawing.Size(705, 900);
this.Controls.Add(this.checkScreen);
this.Controls.Add(this.tableScreen);
this.Controls.Add(this.pictureScreen);
this.Controls.Add(this.labelSreen);
this.Controls.Add(this.buttonQuit);
this.Controls.Add(this.checkGPU);
this.Controls.Add(this.picturePerf);
@@ -356,6 +446,8 @@
((System.ComponentModel.ISupportInitialize)(this.pictureGPU)).EndInit();
this.tablePerf.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picturePerf)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureScreen)).EndInit();
this.tableScreen.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -383,5 +475,11 @@
private Label labelPerf;
private CheckBox checkGPU;
private Button buttonQuit;
private PictureBox pictureScreen;
private Label labelSreen;
private TableLayoutPanel tableScreen;
private Button button120Hz;
private Button button60Hz;
private CheckBox checkScreen;
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
using System.Timers;
namespace GHelper
@@ -43,13 +44,101 @@ namespace GHelper
trackBattery.Scroll += trackBatteryChange;
button60Hz.Click += Button60Hz_Click;
button120Hz.Click += Button120Hz_Click;
buttonQuit.Click += ButtonQuit_Click;
checkScreen.CheckedChanged += checkScreen_CheckedChanged;
SetTimer();
}
private void Button120Hz_Click(object? sender, EventArgs e)
{
SetScreen(1000, 1);
}
private void Button60Hz_Click(object? sender, EventArgs e)
{
SetScreen(60, 0);
}
public void SetScreen(int frequency = -1, int overdrive = -1)
{
int currentFrequency = NativeMethods.GetRefreshRate();
if (currentFrequency < 0) // Laptop screen not detected or has unknown refresh rate
return;
if (frequency >= 1000)
{
frequency = Program.config.getConfig("max_frequency");
if (frequency <= 60)
frequency = 120;
}
if (frequency > 0)
NativeMethods.SetRefreshRate(frequency);
if (overdrive > 0)
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive);
InitScreen();
}
public void InitScreen()
{
int frequency = NativeMethods.GetRefreshRate();
int maxFrequency = Program.config.getConfig("max_frequency");
if (frequency < 0) {
button60Hz.Enabled= false;
button120Hz.Enabled = false;
labelSreen.Text = "Latop Screen: Turned off";
button60Hz.BackColor = SystemColors.ControlLight;
button120Hz.BackColor = SystemColors.ControlLight;
}
else
{
button60Hz.Enabled = true;
button120Hz.Enabled = true;
button60Hz.BackColor = SystemColors.ControlLightLight;
button120Hz.BackColor = SystemColors.ControlLightLight;
labelSreen.Text = "Latop Screen";
}
int overdrive = Program.wmi.DeviceGet(ASUSWmi.ScreenOverdrive);
button60Hz.FlatAppearance.BorderSize = buttonInactive;
button120Hz.FlatAppearance.BorderSize = buttonInactive;
if (frequency == 60)
{
button60Hz.FlatAppearance.BorderSize = buttonActive;
} else
{
if (maxFrequency > 60)
maxFrequency = frequency;
Program.config.setConfig("max_frequency", maxFrequency);
button120Hz.FlatAppearance.BorderSize = buttonActive;
}
if (maxFrequency > 60)
{
button120Hz.Text = maxFrequency.ToString() + "Hz + OD";
}
Program.config.setConfig("frequency", frequency);
Program.config.setConfig("overdrive", overdrive);
}
private void ButtonQuit_Click(object? sender, EventArgs e)
{
Close();
@@ -105,6 +194,8 @@ namespace GHelper
{
if (this.Visible)
{
InitScreen();
this.Left = Screen.FromControl(this).Bounds.Width - 10 - this.Width;
this.Top = Screen.FromControl(this).Bounds.Height - 100 - this.Height;
this.Activate();
@@ -152,6 +243,18 @@ namespace GHelper
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1);
}
public void AutoScreen (int Plugged = 1)
{
int ScreenAuto = Program.config.getConfig("screen_auto");
if (ScreenAuto != 1) return;
if (Plugged == 1)
SetScreen(1000, 1);
else
SetScreen(60, 0);
}
public void AutoGPUMode(int Plugged = 1)
{
@@ -169,25 +272,24 @@ namespace GHelper
{
if (eco == 1 && Plugged == 1) // Eco going Standard on plugged
{
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0);
GPUMode = ASUSWmi.GPUModeStandard;
VisualiseGPUMode(GPUMode);
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0);
Program.config.setConfig("gpu_mode", GPUMode);
}
else if (eco == 0 && Plugged == 0) // Standard going Eco on plugged
{
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1);
GPUMode = ASUSWmi.GPUModeEco;
VisualiseGPUMode(GPUMode);
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1);
Program.config.setConfig("gpu_mode", GPUMode);
}
}
}
public int InitGPUMode()
{
@@ -278,6 +380,11 @@ namespace GHelper
checkGPU.Checked = (GPUAuto == 1);
}
public void VisualiseScreenAuto(int ScreenAuto)
{
checkScreen.Checked = (ScreenAuto == 1);
}
public void VisualiseGPUMode(int GPUMode)
{
@@ -331,6 +438,7 @@ namespace GHelper
public void Disable_Ultimate()
{
buttonUltimate.Enabled = false;
buttonUltimate.BackColor = SystemColors.ControlLight;
}
public void SetStartupCheck(bool status)
@@ -382,6 +490,19 @@ namespace GHelper
}
private void checkScreen_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
{
Program.config.setConfig("screen_auto", 1);
}
else
{
Program.config.setConfig("screen_auto", 0);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 KiB

After

Width:  |  Height:  |  Size: 813 KiB