diff --git a/app/AppConfig.cs b/app/AppConfig.cs
index 53b03bd6..a1ed375d 100644
--- a/app/AppConfig.cs
+++ b/app/AppConfig.cs
@@ -1,4 +1,4 @@
-using GHelper;
+using GHelper.Mode;
using System.Diagnostics;
using System.Management;
using System.Text.Json;
diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs
index 07dc204a..a89c2948 100644
--- a/app/Extra.Designer.cs
+++ b/app/Extra.Designer.cs
@@ -1,5 +1,5 @@
-using CustomControls;
-using GHelper.Properties;
+using GHelper.Properties;
+using GHelper.UI;
namespace GHelper
{
diff --git a/app/Extra.cs b/app/Extra.cs
index 08909292..544ce007 100644
--- a/app/Extra.cs
+++ b/app/Extra.cs
@@ -1,5 +1,7 @@
-using CustomControls;
-using GHelper.Gpu;
+using GHelper.Gpu.AMD;
+using GHelper.Helpers;
+using GHelper.Input;
+using GHelper.UI;
using System.Diagnostics;
namespace GHelper
diff --git a/app/Fans.Designer.cs b/app/Fans.Designer.cs
index 107095d9..43fbbb9e 100644
--- a/app/Fans.Designer.cs
+++ b/app/Fans.Designer.cs
@@ -1,4 +1,4 @@
-using CustomControls;
+using GHelper.UI;
using System.Windows.Forms.DataVisualization.Charting;
namespace GHelper
diff --git a/app/Fans.cs b/app/Fans.cs
index 23703606..a0d91d2d 100644
--- a/app/Fans.cs
+++ b/app/Fans.cs
@@ -1,6 +1,6 @@
-using CustomControls;
-using GHelper.Gpu;
+using GHelper.Gpu.NVidia;
using GHelper.Mode;
+using GHelper.UI;
using Ryzen;
using System.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting;
diff --git a/app/Gpu/AmdAdl2.cs b/app/Gpu/AMD/AmdAdl2.cs
similarity index 90%
rename from app/Gpu/AmdAdl2.cs
rename to app/Gpu/AMD/AmdAdl2.cs
index 6123c891..d76504f8 100644
--- a/app/Gpu/AmdAdl2.cs
+++ b/app/Gpu/AMD/AmdAdl2.cs
@@ -1,8 +1,8 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
-using static AmdAdl2.Adl2.NativeMethods;
+using static GHelper.Gpu.AMD.Adl2.NativeMethods;
-namespace AmdAdl2;
+namespace GHelper.Gpu.AMD;
#region Export Struct
@@ -33,13 +33,15 @@ public struct ADLBdf
}
[StructLayout(LayoutKind.Sequential)]
-public struct ADLSingleSensorData {
+public struct ADLSingleSensorData
+{
public int Supported;
public int Value;
}
[StructLayout(LayoutKind.Sequential)]
-public struct ADLPMLogDataOutput {
+public struct ADLPMLogDataOutput
+{
int Size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_PMLOG_MAX_SENSORS)]
@@ -57,7 +59,8 @@ public struct ADLGcnInfo
}
[Flags]
-public enum ADLAsicFamilyType {
+public enum ADLAsicFamilyType
+{
Undefined = 0,
Discrete = 1 << 0,
Integrated = 1 << 1,
@@ -69,7 +72,8 @@ public enum ADLAsicFamilyType {
Embedded = 1 << 7,
}
-public enum ADLSensorType {
+public enum ADLSensorType
+{
SENSOR_MAXTYPES = 0,
PMLOG_CLK_GFXCLK = 1, // Current graphic clock value in MHz
PMLOG_CLK_MEMCLK = 2, // Current memory clock value in MHz
@@ -149,13 +153,15 @@ public enum ADLSensorType {
//Throttle Status
[Flags]
-public enum ADL_THROTTLE_NOTIFICATION {
+public enum ADL_THROTTLE_NOTIFICATION
+{
ADL_PMLOG_THROTTLE_POWER = 1 << 0,
ADL_PMLOG_THROTTLE_THERMAL = 1 << 1,
ADL_PMLOG_THROTTLE_CURRENT = 1 << 2,
};
-public enum ADL_PMLOG_SENSORS {
+public enum ADL_PMLOG_SENSORS
+{
ADL_SENSOR_MAXTYPES = 0,
ADL_PMLOG_CLK_GFXCLK = 1,
ADL_PMLOG_CLK_MEMCLK = 2,
@@ -237,7 +243,8 @@ public enum ADL_PMLOG_SENSORS {
/// ADLAdapterInfo Structure
[StructLayout(LayoutKind.Sequential)]
-public struct ADLAdapterInfo {
+public struct ADLAdapterInfo
+{
/// The size of the structure
int Size;
@@ -292,7 +299,8 @@ public struct ADLAdapterInfo {
/// ADLAdapterInfo Array
[StructLayout(LayoutKind.Sequential)]
-public struct ADLAdapterInfoArray {
+public struct ADLAdapterInfoArray
+{
/// ADLAdapterInfo Array
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_MAX_ADAPTERS)]
public ADLAdapterInfo[] ADLAdapterInfo;
@@ -304,7 +312,8 @@ public struct ADLAdapterInfoArray {
/// ADLDisplayID Structure
[StructLayout(LayoutKind.Sequential)]
-public struct ADLDisplayID {
+public struct ADLDisplayID
+{
/// Display Logical Index
public int DisplayLogicalIndex;
@@ -320,7 +329,8 @@ public struct ADLDisplayID {
/// ADLDisplayInfo Structure
[StructLayout(LayoutKind.Sequential)]
-public struct ADLDisplayInfo {
+public struct ADLDisplayInfo
+{
/// Display Index
public ADLDisplayID DisplayID;
@@ -355,7 +365,8 @@ public struct ADLDisplayInfo {
#endregion Export Struct
-public class Adl2 {
+public class Adl2
+{
public const string Atiadlxx_FileName = "atiadlxx.dll";
#region Internal Constant
@@ -398,24 +409,30 @@ public class Adl2 {
// ///// ADL Create Function to create ADL Data
/// If it is 1, then ADL will only return the physical exist adapters
///// retrun ADL Error Code
- public static int ADL2_Main_Control_Create(int enumConnectedAdapters, out IntPtr adlContextHandle) {
+ public static int ADL2_Main_Control_Create(int enumConnectedAdapters, out nint adlContextHandle)
+ {
return NativeMethods.ADL2_Main_Control_Create(ADL_Main_Memory_Alloc_Impl_Reference, enumConnectedAdapters, out adlContextHandle);
}
- public static void FreeMemory(IntPtr buffer) {
+ public static void FreeMemory(nint buffer)
+ {
Memory_Free_Impl(buffer);
}
private static bool? isDllLoaded;
- public static bool Load() {
+ public static bool Load()
+ {
if (isDllLoaded != null)
return isDllLoaded.Value;
- try {
+ try
+ {
Marshal.PrelinkAll(typeof(Adl2));
isDllLoaded = true;
- } catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException) {
+ }
+ catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException)
+ {
Debug.WriteLine(e);
isDllLoaded = false;
}
@@ -423,53 +440,57 @@ public class Adl2 {
return isDllLoaded.Value;
}
- private static NativeMethods.ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc_Impl_Reference = Memory_Alloc_Impl;
+ private static ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc_Impl_Reference = Memory_Alloc_Impl;
/// Build in memory allocation function
/// input size
/// return the memory buffer
- private static IntPtr Memory_Alloc_Impl(int size) {
+ private static nint Memory_Alloc_Impl(int size)
+ {
return Marshal.AllocCoTaskMem(size);
}
/// Build in memory free function
/// input buffer
- private static void Memory_Free_Impl(IntPtr buffer) {
- if (IntPtr.Zero != buffer) {
+ private static void Memory_Free_Impl(nint buffer)
+ {
+ if (nint.Zero != buffer)
+ {
Marshal.FreeCoTaskMem(buffer);
}
}
- public static class NativeMethods {
+ public static class NativeMethods
+ {
/// ADL Memory allocation function allows ADL to callback for memory allocation
/// input size
/// retrun ADL Error Code
- public delegate IntPtr ADL_Main_Memory_Alloc(int size);
+ public delegate nint ADL_Main_Memory_Alloc(int size);
// ///// ADL Create Function to create ADL Data
/// Call back functin pointer which is ised to allocate memeory
/// If it is 1, then ADL will only retuen the physical exist adapters
///// retrun ADL Error Code
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, out IntPtr adlContextHandle);
+ public static extern int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, out nint adlContextHandle);
/// ADL Destroy Function to free up ADL Data
/// retrun ADL Error Code
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Main_Control_Destroy(IntPtr adlContextHandle);
+ public static extern int ADL2_Main_Control_Destroy(nint adlContextHandle);
/// ADL Function to get the number of adapters
/// return number of adapters
/// retrun ADL Error Code
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Adapter_NumberOfAdapters_Get(IntPtr adlContextHandle, out int numAdapters);
+ public static extern int ADL2_Adapter_NumberOfAdapters_Get(nint adlContextHandle, out int numAdapters);
/// ADL Function to get the GPU adapter information
/// return GPU adapter information
/// the size of the GPU adapter struct
/// retrun ADL Error Code
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Adapter_AdapterInfo_Get(IntPtr adlContextHandle, IntPtr info, int inputSize);
+ public static extern int ADL2_Adapter_AdapterInfo_Get(nint adlContextHandle, nint info, int inputSize);
/// Function to determine if the adapter is active or not.
/// The function is used to check if the adapter associated with iAdapterIndex is active
@@ -477,7 +498,7 @@ public class Adl2 {
/// Status of the adapter. True: Active; False: Dsiabled
/// Non zero is successfull
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Adapter_Active_Get(IntPtr adlContextHandle, int adapterIndex, out int status);
+ public static extern int ADL2_Adapter_Active_Get(nint adlContextHandle, int adapterIndex, out int status);
/// Get display information based on adapter index
/// Adapter Index
@@ -487,16 +508,16 @@ public class Adl2 {
/// return ADL Error Code
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Display_DisplayInfo_Get(
- IntPtr adlContextHandle,
+ nint adlContextHandle,
int adapterIndex,
out int numDisplays,
- out IntPtr displayInfoArray,
+ out nint displayInfoArray,
int forceDetect
);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Overdrive_Caps(
- IntPtr adlContextHandle,
+ nint adlContextHandle,
int adapterIndex,
out int supported,
out int enabled,
@@ -504,21 +525,21 @@ public class Adl2 {
);
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_New_QueryPMLogData_Get(IntPtr adlContextHandle, int adapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput);
+ public static extern int ADL2_New_QueryPMLogData_Get(nint adlContextHandle, int adapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput);
[DllImport(Atiadlxx_FileName)]
- public static extern int ADL2_Adapter_ASICFamilyType_Get(IntPtr adlContextHandle, int adapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids);
+ public static extern int ADL2_Adapter_ASICFamilyType_Get(nint adlContextHandle, int adapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_SwitchableGraphics_Applications_Get(
- IntPtr context,
+ nint context,
int iListType,
out int lpNumApps,
- out IntPtr lppAppList);
+ out nint lppAppList);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_VariBright_Caps(
- IntPtr context,
+ nint context,
int iAdapterIndex,
out int iSupported,
out int iEnabled,
@@ -526,7 +547,7 @@ public class Adl2 {
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_VariBrightEnable_Set(
- IntPtr context,
+ nint context,
int iAdapterIndex,
int iEnabled);
@@ -553,25 +574,25 @@ public class Adl2 {
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_SystemClocks_Get(
- IntPtr context,
+ nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_SystemClocks_Set(
- IntPtr context,
+ nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_MemoryClocks_Get(
- IntPtr context,
+ nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_MemoryClocks_Set(
- IntPtr context,
+ nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
}
diff --git a/app/Gpu/AmdGpuControl.cs b/app/Gpu/AMD/AmdGpuControl.cs
similarity index 90%
rename from app/Gpu/AmdGpuControl.cs
rename to app/Gpu/AMD/AmdGpuControl.cs
index 72034745..2d0b1f38 100644
--- a/app/Gpu/AmdGpuControl.cs
+++ b/app/Gpu/AMD/AmdGpuControl.cs
@@ -1,14 +1,14 @@
-using AmdAdl2;
+using GHelper.Helpers;
using System.Runtime.InteropServices;
-using static AmdAdl2.Adl2.NativeMethods;
+using static GHelper.Gpu.AMD.Adl2.NativeMethods;
-namespace GHelper.Gpu;
+namespace GHelper.Gpu.AMD;
// Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs
public class AmdGpuControl : IGpuControl
{
private bool _isReady;
- private IntPtr _adlContextHandle;
+ private nint _adlContextHandle;
private readonly ADLAdapterInfo _internalDiscreteAdapter;
public bool IsNvidia => false;
@@ -23,7 +23,7 @@ public class AmdGpuControl : IGpuControl
ADLAdapterInfoArray osAdapterInfoData = new();
int osAdapterInfoDataSize = Marshal.SizeOf(osAdapterInfoData);
- IntPtr AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
+ nint AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
Marshal.StructureToPtr(osAdapterInfoData, AdapterBuffer, false);
if (ADL2_Adapter_AdapterInfo_Get(_adlContextHandle, AdapterBuffer, osAdapterInfoDataSize) != Adl2.ADL_SUCCESS)
return null;
@@ -76,7 +76,7 @@ public class AmdGpuControl : IGpuControl
}
- public bool IsValid => _isReady && _adlContextHandle != IntPtr.Zero;
+ public bool IsValid => _isReady && _adlContextHandle != nint.Zero;
public int? GetCurrentTemperature()
{
@@ -112,7 +112,7 @@ public class AmdGpuControl : IGpuControl
public bool SetVariBright(int enabled)
{
- if (_adlContextHandle == IntPtr.Zero) return false;
+ if (_adlContextHandle == nint.Zero) return false;
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
if (iGPU is null) return false;
@@ -125,7 +125,7 @@ public class AmdGpuControl : IGpuControl
{
supported = enabled = -1;
- if (_adlContextHandle == IntPtr.Zero) return false;
+ if (_adlContextHandle == nint.Zero) return false;
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
if (iGPU is null) return false;
@@ -154,7 +154,7 @@ public class AmdGpuControl : IGpuControl
if (!IsValid) return;
- IntPtr appInfoPtr = IntPtr.Zero;
+ nint appInfoPtr = nint.Zero;
int appCount = 0;
try
@@ -168,12 +168,12 @@ public class AmdGpuControl : IGpuControl
// Convert the application data pointers to an array of structs
var appInfoArray = new ADLSGApplicationInfo[appCount];
- IntPtr currentPtr = appInfoPtr;
+ nint currentPtr = appInfoPtr;
for (int i = 0; i < appCount; i++)
{
appInfoArray[i] = Marshal.PtrToStructure(currentPtr);
- currentPtr = IntPtr.Add(currentPtr, Marshal.SizeOf());
+ currentPtr = nint.Add(currentPtr, Marshal.SizeOf());
}
var appNames = new List();
@@ -189,7 +189,7 @@ public class AmdGpuControl : IGpuControl
List immune = new() { "svchost", "system", "ntoskrnl", "csrss", "winlogon", "wininit", "smss" };
- foreach (string kill in appNames)
+ foreach (string kill in appNames)
if (!immune.Contains(kill.ToLower()))
ProcessHelper.KillByName(kill);
@@ -202,7 +202,7 @@ public class AmdGpuControl : IGpuControl
finally
{
// Clean up resources
- if (appInfoPtr != IntPtr.Zero)
+ if (appInfoPtr != nint.Zero)
{
Marshal.FreeCoTaskMem(appInfoPtr);
}
@@ -213,10 +213,10 @@ public class AmdGpuControl : IGpuControl
private void ReleaseUnmanagedResources()
{
- if (_adlContextHandle != IntPtr.Zero)
+ if (_adlContextHandle != nint.Zero)
{
ADL2_Main_Control_Destroy(_adlContextHandle);
- _adlContextHandle = IntPtr.Zero;
+ _adlContextHandle = nint.Zero;
_isReady = false;
}
}
diff --git a/app/Gpu/GPUModeControl.cs b/app/Gpu/GPUModeControl.cs
new file mode 100644
index 00000000..c9e32ecf
--- /dev/null
+++ b/app/Gpu/GPUModeControl.cs
@@ -0,0 +1,316 @@
+using GHelper.Gpu.NVidia;
+using GHelper.Helpers;
+using GHelper.Mode;
+using System.Diagnostics;
+
+namespace GHelper.Gpu
+{
+ public class GPUModeControl
+ {
+ static SettingsForm settings = Program.settingsForm;
+ ModeControl modeControl = new ModeControl();
+
+ public void InitGPUMode()
+ {
+ int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
+ int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
+
+ Logger.WriteLine("Eco flag : " + eco);
+ Logger.WriteLine("Mux flag : " + mux);
+
+ int GpuMode;
+
+ if (mux == 0)
+ {
+ GpuMode = AsusACPI.GPUModeUltimate;
+ }
+ else
+ {
+ if (eco == 1)
+ GpuMode = AsusACPI.GPUModeEco;
+ else
+ GpuMode = AsusACPI.GPUModeStandard;
+
+ // Ultimate mode not suported
+ if (mux != 1) settings.HideUltimateMode();
+ if (eco < 0 && mux < 0) settings.HideGPUModes();
+ }
+
+ AppConfig.Set("gpu_mode", GpuMode);
+
+ InitXGM();
+ settings.VisualiseGPUMode(GpuMode);
+ }
+
+
+ public void SetGPUMode(int GPUMode)
+ {
+
+ int CurrentGPU = AppConfig.Get("gpu_mode");
+ AppConfig.Set("gpu_auto", 0);
+
+ if (CurrentGPU == GPUMode)
+ {
+ settings.VisualiseGPUMode();
+ return;
+ }
+
+ var restart = false;
+ var changed = false;
+
+ if (CurrentGPU == AsusACPI.GPUModeUltimate)
+ {
+ DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOff, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.Yes)
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUMux, 1, "GPUMux");
+ restart = true;
+ changed = true;
+ }
+ }
+ else if (GPUMode == AsusACPI.GPUModeUltimate)
+ {
+ DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOn, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.Yes)
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUMux, 0, "GPUMux");
+ restart = true;
+ changed = true;
+ }
+
+ }
+ else if (GPUMode == AsusACPI.GPUModeEco)
+ {
+ settings.VisualiseGPUMode(GPUMode);
+ SetGPUEco(1, true);
+ changed = true;
+ }
+ else if (GPUMode == AsusACPI.GPUModeStandard)
+ {
+ settings.VisualiseGPUMode(GPUMode);
+ SetGPUEco(0);
+ changed = true;
+ }
+
+ if (changed)
+ {
+ AppConfig.Set("gpu_mode", GPUMode);
+ }
+
+ if (restart)
+ {
+ settings.VisualiseGPUMode();
+ Process.Start("shutdown", "/r /t 1");
+ }
+
+ }
+
+
+
+ public void SetGPUEco(int eco, bool hardWay = false)
+ {
+
+ settings.LockGPUModes();
+
+ Task.Run(async () =>
+ {
+
+ int status = 1;
+
+ if (eco == 1)
+ {
+ if (NvidiaSmi.GetDisplayActiveStatus())
+ {
+ DialogResult dialogResult = MessageBox.Show(Properties.Strings.EnableOptimusText, Properties.Strings.EnableOptimusTitle, MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.No)
+ {
+ InitGPUMode();
+ return;
+ }
+ }
+
+ HardwareControl.KillGPUApps();
+ }
+
+ Logger.WriteLine($"Running eco command {eco}");
+
+ status = Program.acpi.SetGPUEco(eco);
+
+ if (status == 0 && eco == 1 && hardWay) RestartGPU();
+
+ await Task.Delay(TimeSpan.FromMilliseconds(100));
+
+ settings.Invoke(delegate
+ {
+ InitGPUMode();
+ settings.AutoScreen();
+ });
+
+ if (eco == 0)
+ {
+ await Task.Delay(TimeSpan.FromMilliseconds(3000));
+ HardwareControl.RecreateGpuControl();
+ modeControl.SetGPUClocks(false);
+ }
+
+ });
+
+
+ }
+
+ public static bool IsPlugged()
+ {
+ bool optimizedUSBC = AppConfig.Get("optimized_usbc") != 1;
+
+ return SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online &&
+ (optimizedUSBC || Program.acpi.DeviceGet(AsusACPI.ChargerMode) < AsusACPI.ChargerUSB);
+
+ }
+
+ public bool AutoGPUMode()
+ {
+
+ bool GpuAuto = AppConfig.Is("gpu_auto");
+ bool ForceGPU = AppConfig.ContainsModel("503");
+
+ int GpuMode = AppConfig.Get("gpu_mode");
+
+ if (!GpuAuto && !ForceGPU) return false;
+
+ int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
+ int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
+
+ if (mux == 0) // GPU in Ultimate, ignore
+ return false;
+ else
+ {
+
+ if (ReEnableGPU()) return true;
+
+ if (eco == 1)
+ if ((GpuAuto && IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeStandard))
+ {
+ SetGPUEco(0);
+ return true;
+ }
+ if (eco == 0)
+ if ((GpuAuto && !IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeEco))
+ {
+
+ if (HardwareControl.IsUsedGPU())
+ {
+ DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertDGPU, Properties.Strings.AlertDGPUTitle, MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.No) return false;
+ }
+
+ SetGPUEco(1);
+ return true;
+ }
+ }
+
+ return false;
+
+ }
+
+
+ public void RestartGPU(bool confirm = true)
+ {
+ if (HardwareControl.GpuControl is null) return;
+ if (!HardwareControl.GpuControl!.IsNvidia) return;
+
+ if (confirm)
+ {
+ DialogResult dialogResult = MessageBox.Show(Properties.Strings.RestartGPU, Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.No) return;
+ }
+
+ ProcessHelper.RunAsAdmin("gpurestart");
+
+ if (!ProcessHelper.IsUserAdministrator()) return;
+
+ Logger.WriteLine("Trying to restart dGPU");
+
+ Task.Run(async () =>
+ {
+ settings.LockGPUModes("Restarting GPU ...");
+
+ var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
+ bool status = nvControl.RestartGPU();
+
+ settings.Invoke(delegate
+ {
+ //labelTipGPU.Text = status ? "GPU Restarted, you can try Eco mode again" : "Failed to restart GPU"; TODO
+ InitGPUMode();
+ });
+ });
+
+ }
+
+
+ public bool ReEnableGPU()
+ {
+
+ if (AppConfig.Get("gpu_reenable") != 1) return false;
+ if (Screen.AllScreens.Length <= 1) return false;
+
+ Logger.WriteLine("Re-enabling gpu for 503 model");
+
+ Thread.Sleep(1000);
+ SetGPUEco(1);
+ Thread.Sleep(1000);
+ SetGPUEco(0);
+ return true;
+ }
+
+ public void InitXGM()
+ {
+ bool connected = Program.acpi.IsXGConnected();
+ int activated = Program.acpi.DeviceGet(AsusACPI.GPUXG);
+ settings.VisualizeXGM(connected, activated == 1);
+ }
+
+ public void ToggleXGM()
+ {
+
+ Task.Run(async () =>
+ {
+ settings.LockGPUModes();
+
+ if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
+ {
+ HardwareControl.KillGPUApps();
+ DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo);
+ if (dialogResult == DialogResult.Yes)
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUXG, 0, "GPU XGM");
+ await Task.Delay(TimeSpan.FromSeconds(15));
+ }
+ }
+ else
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM");
+ AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light"));
+
+ await Task.Delay(TimeSpan.FromSeconds(15));
+
+ if (AppConfig.IsMode("auto_apply"))
+ AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM));
+ }
+
+ settings.Invoke(delegate
+ {
+ InitGPUMode();
+ });
+ });
+ }
+
+ public void KillGPUApps()
+ {
+ if (HardwareControl.GpuControl is not null)
+ {
+ HardwareControl.GpuControl.KillGPUApps();
+ }
+ }
+
+ }
+}
diff --git a/app/Gpu/NvidiaGpuControl.cs b/app/Gpu/NVidia/NvidiaGpuControl.cs
similarity index 95%
rename from app/Gpu/NvidiaGpuControl.cs
rename to app/Gpu/NVidia/NvidiaGpuControl.cs
index 5706b799..a3bee55b 100644
--- a/app/Gpu/NvidiaGpuControl.cs
+++ b/app/Gpu/NVidia/NvidiaGpuControl.cs
@@ -1,4 +1,5 @@
-using NvAPIWrapper.GPU;
+using GHelper.Helpers;
+using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
@@ -6,7 +7,7 @@ using NvAPIWrapper.Native.Interfaces.GPU;
using System.Diagnostics;
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
-namespace GHelper.Gpu;
+namespace GHelper.Gpu.NVidia;
public class NvidiaGpuControl : IGpuControl
{
@@ -126,8 +127,8 @@ public class NvidiaGpuControl : IGpuControl
public int SetClocksFromConfig()
{
- int core = AppConfig.Get("gpu_core",0);
- int memory = AppConfig.Get("gpu_memory",0);
+ int core = AppConfig.Get("gpu_core", 0);
+ int memory = AppConfig.Get("gpu_memory", 0);
int status = SetClocks(core, memory);
return status;
}
@@ -145,7 +146,7 @@ public class NvidiaGpuControl : IGpuControl
var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage));
PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock };
- PerformanceStates20BaseVoltageEntryV1[] voltages = { };
+ PerformanceStates20BaseVoltageEntryV1[] voltages = { };
PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) };
diff --git a/app/Gpu/NvidiaSmi.cs b/app/Gpu/NVidia/NvidiaSmi.cs
similarity index 100%
rename from app/Gpu/NvidiaSmi.cs
rename to app/Gpu/NVidia/NvidiaSmi.cs
diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs
index ec76f837..7084ac9b 100644
--- a/app/HardwareControl.cs
+++ b/app/HardwareControl.cs
@@ -1,5 +1,9 @@
using GHelper;
using GHelper.Gpu;
+using GHelper.Gpu.NVidia;
+using GHelper.Gpu.AMD;
+
+using GHelper.Helpers;
using System.Diagnostics;
public static class HardwareControl
diff --git a/app/Logger.cs b/app/Helpers/Logger.cs
similarity index 100%
rename from app/Logger.cs
rename to app/Helpers/Logger.cs
diff --git a/app/OSDBase.cs b/app/Helpers/OSDBase.cs
similarity index 59%
rename from app/OSDBase.cs
rename to app/Helpers/OSDBase.cs
index 45f99142..92b6a5dd 100644
--- a/app/OSDBase.cs
+++ b/app/Helpers/OSDBase.cs
@@ -1,7 +1,7 @@
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
-namespace OSD
+namespace GHelper.Helpers
{
public class OSDNativeForm : NativeWindow, IDisposable
@@ -19,11 +19,11 @@ namespace OSD
protected internal void Invalidate()
{
- this.UpdateLayeredWindow();
+ UpdateLayeredWindow();
}
private void UpdateLayeredWindow()
{
- Bitmap bitmap1 = new Bitmap(this.Size.Width, this.Size.Height, PixelFormat.Format32bppArgb);
+ Bitmap bitmap1 = new Bitmap(Size.Width, Size.Height, PixelFormat.Format32bppArgb);
using (Graphics graphics1 = Graphics.FromImage(bitmap1))
{
Rectangle rectangle1;
@@ -31,27 +31,27 @@ namespace OSD
POINT point1;
POINT point2;
BLENDFUNCTION blendfunction1;
- rectangle1 = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
+ rectangle1 = new Rectangle(0, 0, Size.Width, Size.Height);
PerformPaint(new PaintEventArgs(graphics1, rectangle1));
- IntPtr ptr1 = User32.GetDC(IntPtr.Zero);
- IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1);
- IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
- IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3);
- size1.cx = this.Size.Width;
- size1.cy = this.Size.Height;
- point1.x = this.Location.X;
- point1.x = this.Location.X;
- point1.y = this.Location.Y;
+ nint ptr1 = User32.GetDC(nint.Zero);
+ nint ptr2 = Gdi32.CreateCompatibleDC(ptr1);
+ nint ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
+ nint ptr4 = Gdi32.SelectObject(ptr2, ptr3);
+ size1.cx = Size.Width;
+ size1.cy = Size.Height;
+ point1.x = Location.X;
+ point1.x = Location.X;
+ point1.y = Location.Y;
point2.x = 0;
point2.y = 0;
blendfunction1 = new BLENDFUNCTION();
blendfunction1.BlendOp = 0;
blendfunction1.BlendFlags = 0;
- blendfunction1.SourceConstantAlpha = this._alpha;
+ blendfunction1.SourceConstantAlpha = _alpha;
blendfunction1.AlphaFormat = 1;
- User32.UpdateLayeredWindow(base.Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA
+ User32.UpdateLayeredWindow(Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA
Gdi32.SelectObject(ptr2, ptr4);
- User32.ReleaseDC(IntPtr.Zero, ptr1);
+ User32.ReleaseDC(nint.Zero, ptr1);
Gdi32.DeleteObject(ptr3);
Gdi32.DeleteDC(ptr2);
}
@@ -59,25 +59,25 @@ namespace OSD
public virtual void Show()
{
- if (base.Handle == IntPtr.Zero) //if handle don't equal to zero - window was created and just hided
- this.CreateWindowOnly();
- User32.ShowWindow(base.Handle, User32.SW_SHOWNOACTIVATE);
+ if (Handle == nint.Zero) //if handle don't equal to zero - window was created and just hided
+ CreateWindowOnly();
+ User32.ShowWindow(Handle, User32.SW_SHOWNOACTIVATE);
}
public virtual void Hide()
{
- if (base.Handle == IntPtr.Zero)
+ if (Handle == nint.Zero)
return;
- User32.ShowWindow(base.Handle, User32.SW_HIDE);
- this.DestroyHandle();
+ User32.ShowWindow(Handle, User32.SW_HIDE);
+ DestroyHandle();
}
public virtual void Close()
{
- this.Hide();
- this.Dispose();
+ Hide();
+ Dispose();
}
private void CreateWindowOnly()
@@ -85,55 +85,55 @@ namespace OSD
CreateParams params1 = new CreateParams();
params1.Caption = "FloatingNativeWindow";
- int nX = this._location.X;
- int nY = this._location.Y;
- Screen screen1 = Screen.FromHandle(base.Handle);
- if ((nX + this._size.Width) > screen1.Bounds.Width)
+ int nX = _location.X;
+ int nY = _location.Y;
+ Screen screen1 = Screen.FromHandle(Handle);
+ if (nX + _size.Width > screen1.Bounds.Width)
{
- nX = screen1.Bounds.Width - this._size.Width;
+ nX = screen1.Bounds.Width - _size.Width;
}
- if ((nY + this._size.Height) > screen1.Bounds.Height)
+ if (nY + _size.Height > screen1.Bounds.Height)
{
- nY = screen1.Bounds.Height - this._size.Height;
+ nY = screen1.Bounds.Height - _size.Height;
}
- this._location = new Point(nX, nY);
- Size size1 = this._size;
- Point point1 = this._location;
+ _location = new Point(nX, nY);
+ Size size1 = _size;
+ Point point1 = _location;
params1.X = nX;
params1.Y = nY;
params1.Height = size1.Height;
params1.Width = size1.Width;
- params1.Parent = IntPtr.Zero;
+ params1.Parent = nint.Zero;
uint ui = User32.WS_POPUP;
params1.Style = (int)ui;
params1.ExStyle = User32.WS_EX_TOPMOST | User32.WS_EX_TOOLWINDOW | User32.WS_EX_LAYERED | User32.WS_EX_NOACTIVATE | User32.WS_EX_TRANSPARENT;
- this.CreateHandle(params1);
- this.UpdateLayeredWindow();
+ CreateHandle(params1);
+ UpdateLayeredWindow();
}
protected virtual void SetBoundsCore(int x, int y, int width, int height)
{
- if (((this.X != x) || (this.Y != y)) || ((this.Width != width) || (this.Height != height)))
+ if (X != x || Y != y || Width != width || Height != height)
{
- if (base.Handle != IntPtr.Zero)
+ if (Handle != nint.Zero)
{
int num1 = 20;
- if ((this.X == x) && (this.Y == y))
+ if (X == x && Y == y)
{
num1 |= 2;
}
- if ((this.Width == width) && (this.Height == height))
+ if (Width == width && Height == height)
{
num1 |= 1;
}
- User32.SetWindowPos(base.Handle, IntPtr.Zero, x, y, width, height, (uint)num1);
+ User32.SetWindowPos(Handle, nint.Zero, x, y, width, height, (uint)num1);
}
else
{
- this.Location = new Point(x, y);
- this.Size = new Size(width, height);
+ Location = new Point(x, y);
+ Size = new Size(width, height);
}
}
}
@@ -147,20 +147,20 @@ namespace OSD
///
public virtual Point Location
{
- get { return this._location; }
+ get { return _location; }
set
{
- if (base.Handle != IntPtr.Zero)
+ if (Handle != nint.Zero)
{
- this.SetBoundsCore(value.X, value.Y, this._size.Width, this._size.Height);
+ SetBoundsCore(value.X, value.Y, _size.Width, _size.Height);
RECT rect = new RECT();
- User32.GetWindowRect(base.Handle, ref rect);
- this._location = new Point(rect.left, rect.top);
- this.UpdateLayeredWindow();
+ User32.GetWindowRect(Handle, ref rect);
+ _location = new Point(rect.left, rect.top);
+ UpdateLayeredWindow();
}
else
{
- this._location = value;
+ _location = value;
}
}
}
@@ -169,20 +169,20 @@ namespace OSD
///
public virtual Size Size
{
- get { return this._size; }
+ get { return _size; }
set
{
- if (base.Handle != IntPtr.Zero)
+ if (Handle != nint.Zero)
{
- this.SetBoundsCore(this._location.X, this._location.Y, value.Width, value.Height);
+ SetBoundsCore(_location.X, _location.Y, value.Width, value.Height);
RECT rect = new RECT();
- User32.GetWindowRect(base.Handle, ref rect);
- this._size = new Size(rect.right - rect.left, rect.bottom - rect.top);
- this.UpdateLayeredWindow();
+ User32.GetWindowRect(Handle, ref rect);
+ _size = new Size(rect.right - rect.left, rect.bottom - rect.top);
+ UpdateLayeredWindow();
}
else
{
- this._size = value;
+ _size = value;
}
}
}
@@ -191,10 +191,10 @@ namespace OSD
///
public int Height
{
- get { return this._size.Height; }
+ get { return _size.Height; }
set
{
- this._size = new Size(this._size.Width, value);
+ _size = new Size(_size.Width, value);
}
}
///
@@ -202,10 +202,10 @@ namespace OSD
///
public int Width
{
- get { return this._size.Width; }
+ get { return _size.Width; }
set
{
- this._size = new Size(value, this._size.Height);
+ _size = new Size(value, _size.Height);
}
}
///
@@ -213,10 +213,10 @@ namespace OSD
///
public int X
{
- get { return this._location.X; }
+ get { return _location.X; }
set
{
- this.Location = new Point(value, this.Location.Y);
+ Location = new Point(value, Location.Y);
}
}
///
@@ -224,10 +224,10 @@ namespace OSD
///
public int Y
{
- get { return this._location.Y; }
+ get { return _location.Y; }
set
{
- this.Location = new Point(this.Location.X, value);
+ Location = new Point(Location.X, value);
}
}
///
@@ -237,7 +237,7 @@ namespace OSD
{
get
{
- return new Rectangle(new Point(0, 0), this._size);
+ return new Rectangle(new Point(0, 0), _size);
}
}
///
@@ -245,12 +245,12 @@ namespace OSD
///
public byte Alpha
{
- get { return this._alpha; }
+ get { return _alpha; }
set
{
- if (this._alpha == value) return;
- this._alpha = value;
- this.UpdateLayeredWindow();
+ if (_alpha == value) return;
+ _alpha = value;
+ UpdateLayeredWindow();
}
}
#endregion
@@ -258,15 +258,15 @@ namespace OSD
#region IDisposable Members
public void Dispose()
{
- this.Dispose(true);
+ Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
- if (!this._disposed)
+ if (!_disposed)
{
- this.DestroyHandle();
- this._disposed = true;
+ DestroyHandle();
+ _disposed = true;
}
}
#endregion
@@ -299,16 +299,16 @@ namespace OSD
{
public uint cbSize;
public uint dwFlags;
- public IntPtr hWnd;
+ public nint hWnd;
public uint dwHoverTime;
}
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
- public IntPtr hwnd;
+ public nint hwnd;
public int message;
- public IntPtr wParam;
- public IntPtr lParam;
+ public nint wParam;
+ public nint lParam;
public int time;
public int pt_x;
public int pt_y;
@@ -345,69 +345,69 @@ namespace OSD
{
}
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags);
+ internal static extern bool AnimateWindow(nint hWnd, uint dwTime, uint dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
+ internal static extern bool ClientToScreen(nint hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool DispatchMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool DrawFocusRect(IntPtr hWnd, ref RECT rect);
+ internal static extern bool DrawFocusRect(nint hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr GetDC(IntPtr hWnd);
+ internal static extern nint GetDC(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr GetFocus();
+ internal static extern nint GetFocus();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern ushort GetKeyState(int virtKey);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr GetParent(IntPtr hWnd);
+ internal static extern nint GetParent(nint hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
- public static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref RECT rect);
+ public static extern bool GetClientRect(nint hWnd, [In, Out] ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
+ internal static extern int GetWindowLong(nint hWnd, int nIndex);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr GetWindow(IntPtr hWnd, int cmd);
+ internal static extern nint GetWindow(nint hWnd, int cmd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
+ internal static extern bool GetWindowRect(nint hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool HideCaret(IntPtr hWnd);
+ internal static extern bool HideCaret(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool InvalidateRect(IntPtr hWnd, ref RECT rect, bool erase);
+ internal static extern bool InvalidateRect(nint hWnd, ref RECT rect, bool erase);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);
+ internal static extern nint LoadCursor(nint hInstance, uint cursor);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
- public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rect, int cPoints);
+ public static extern int MapWindowPoints(nint hWndFrom, nint hWndTo, [In, Out] ref RECT rect, int cPoints);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
+ internal static extern bool MoveWindow(nint hWnd, int x, int y, int width, int height, bool repaint);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
+ internal static extern bool PostMessage(nint hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ReleaseCapture();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
+ internal static extern int ReleaseDC(nint hWnd, nint hDC);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt);
+ internal static extern bool ScreenToClient(nint hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
+ internal static extern uint SendMessage(nint hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr SetCursor(IntPtr hCursor);
+ internal static extern nint SetCursor(nint hCursor);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr SetFocus(IntPtr hWnd);
+ internal static extern nint SetFocus(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newLong);
+ internal static extern int SetWindowLong(nint hWnd, int nIndex, int newLong);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int X, int Y, int Width, int Height, uint flags);
+ internal static extern int SetWindowPos(nint hWnd, nint hWndAfter, int X, int Y, int Width, int Height, uint flags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
+ internal static extern bool SetWindowRgn(nint hWnd, nint hRgn, bool redraw);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool ShowCaret(IntPtr hWnd);
+ internal static extern bool ShowCaret(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool SetCapture(IntPtr hWnd);
+ internal static extern bool SetCapture(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern int ShowWindow(IntPtr hWnd, short cmdShow);
+ internal static extern int ShowWindow(nint hWnd, short cmdShow);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
@@ -415,9 +415,9 @@ namespace OSD
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool TranslateMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
+ internal static extern bool UpdateLayeredWindow(nint hwnd, nint hdcDst, ref POINT pptDst, ref SIZE psize, nint hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
- internal static extern bool UpdateWindow(IntPtr hwnd);
+ internal static extern bool UpdateWindow(nint hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool WaitMessage();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
@@ -431,25 +431,25 @@ namespace OSD
{
}
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern int CombineRgn(IntPtr dest, IntPtr src1, IntPtr src2, int flags);
+ internal static extern int CombineRgn(nint dest, nint src1, nint src2, int flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr CreateBrushIndirect(ref LOGBRUSH brush);
+ internal static extern nint CreateBrushIndirect(ref LOGBRUSH brush);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr CreateCompatibleDC(IntPtr hDC);
+ internal static extern nint CreateCompatibleDC(nint hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr CreateRectRgnIndirect(ref RECT rect);
+ internal static extern nint CreateRectRgnIndirect(ref RECT rect);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern bool DeleteDC(IntPtr hDC);
+ internal static extern bool DeleteDC(nint hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr DeleteObject(IntPtr hObject);
+ internal static extern nint DeleteObject(nint hObject);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern int GetClipBox(IntPtr hDC, ref RECT rectBox);
+ internal static extern int GetClipBox(nint hDC, ref RECT rectBox);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern bool PatBlt(IntPtr hDC, int x, int y, int width, int height, uint flags);
+ internal static extern bool PatBlt(nint hDC, int x, int y, int width, int height, uint flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn);
+ internal static extern int SelectClipRgn(nint hDC, nint hRgn);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
- internal static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
+ internal static extern nint SelectObject(nint hDC, nint hObject);
}
[StructLayout(LayoutKind.Sequential)]
public struct LOGBRUSH
diff --git a/app/OptimizationService.cs b/app/Helpers/OptimizationService.cs
similarity index 94%
rename from app/OptimizationService.cs
rename to app/Helpers/OptimizationService.cs
index 3d5b1eec..e27cb1d6 100644
--- a/app/OptimizationService.cs
+++ b/app/Helpers/OptimizationService.cs
@@ -3,7 +3,7 @@ using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
-namespace GHelper
+namespace GHelper.Helpers
{
public static class OptimizationService
{
@@ -52,7 +52,7 @@ namespace GHelper
public static bool IsRunning()
{
- return (Process.GetProcessesByName("AsusOptimization").Count() > 0);
+ return Process.GetProcessesByName("AsusOptimization").Count() > 0;
}
public static int GetRunningCount()
@@ -66,7 +66,7 @@ namespace GHelper
}
- public static void SetBacklightOffDelay(int value = 60)
+ public static void SetBacklightOffDelay(int value = 60)
{
try
{
diff --git a/app/ProcessHelper.cs b/app/Helpers/ProcessHelper.cs
similarity index 98%
rename from app/ProcessHelper.cs
rename to app/Helpers/ProcessHelper.cs
index 2c762f97..0a5ed971 100644
--- a/app/ProcessHelper.cs
+++ b/app/Helpers/ProcessHelper.cs
@@ -6,7 +6,7 @@ using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
-namespace GHelper
+namespace GHelper.Helpers
{
public static class ProcessHelper
{
@@ -61,7 +61,8 @@ namespace GHelper
{
Process.Start(startInfo);
Application.Exit();
- } catch (Exception ex)
+ }
+ catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
diff --git a/app/ScreenBrightness.cs b/app/Helpers/ScreenBrightness.cs
similarity index 97%
rename from app/ScreenBrightness.cs
rename to app/Helpers/ScreenBrightness.cs
index 4b06c940..9ea50222 100644
--- a/app/ScreenBrightness.cs
+++ b/app/Helpers/ScreenBrightness.cs
@@ -1,4 +1,4 @@
-namespace GHelper
+namespace GHelper.Helpers
{
using System;
using System.Diagnostics;
diff --git a/app/Startup.cs b/app/Helpers/Startup.cs
similarity index 98%
rename from app/Startup.cs
rename to app/Helpers/Startup.cs
index f8da4539..ae6adc96 100644
--- a/app/Startup.cs
+++ b/app/Helpers/Startup.cs
@@ -1,4 +1,4 @@
-using GHelper;
+using GHelper.Helpers;
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Security.Principal;
diff --git a/app/ToastForm.cs b/app/Helpers/ToastForm.cs
similarity index 84%
rename from app/ToastForm.cs
rename to app/Helpers/ToastForm.cs
index 0b2c97ae..f22e22bd 100644
--- a/app/ToastForm.cs
+++ b/app/Helpers/ToastForm.cs
@@ -1,9 +1,8 @@
-using OSD;
-using System.Diagnostics;
+using System.Diagnostics;
using System.Drawing.Drawing2D;
-namespace GHelper
+namespace GHelper.Helpers
{
static class Drawing
@@ -74,7 +73,7 @@ namespace GHelper
protected override void PerformPaint(PaintEventArgs e)
{
Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black));
- Drawing.FillRoundedRectangle(e.Graphics, brush, this.Bound, 10);
+ e.Graphics.FillRoundedRectangle(brush, Bound, 10);
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
@@ -128,34 +127,37 @@ namespace GHelper
e.Graphics.DrawString(toastText,
new Font("Segoe UI", 36f, FontStyle.Bold, GraphicsUnit.Pixel),
new SolidBrush(Color.White),
- new PointF(this.Bound.Width / 2 + shiftX, this.Bound.Height / 2),
+ new PointF(Bound.Width / 2 + shiftX, Bound.Height / 2),
format);
}
public void RunToast(string text, ToastIcon? icon = null)
{
- //Hide();
- timer.Stop();
+ Program.settingsForm.Invoke(delegate
+ {
+ //Hide();
+ timer.Stop();
- toastText = text;
- toastIcon = icon;
+ toastText = text;
+ toastIcon = icon;
- Screen screen1 = Screen.FromHandle(base.Handle);
+ Screen screen1 = Screen.FromHandle(Handle);
- Width = Math.Max(300, 100 + toastText.Length * 22);
- Height = 100;
- X = (screen1.Bounds.Width - this.Width) / 2;
- Y = screen1.Bounds.Height - 300 - this.Height;
+ Width = Math.Max(300, 100 + toastText.Length * 22);
+ Height = 100;
+ X = (screen1.Bounds.Width - Width) / 2;
+ Y = screen1.Bounds.Height - 300 - Height;
+
+ Show();
+ timer.Start();
+ });
- Show();
- timer.Start();
}
private void timer_Tick(object? sender, EventArgs e)
{
- Debug.WriteLine("Toast end");
-
+ //Debug.WriteLine("Toast end");
Hide();
timer.Stop();
}
diff --git a/app/InputDispatcher.cs b/app/Input/InputDispatcher.cs
similarity index 89%
rename from app/InputDispatcher.cs
rename to app/Input/InputDispatcher.cs
index 7bf2a833..b6a75605 100644
--- a/app/InputDispatcher.cs
+++ b/app/Input/InputDispatcher.cs
@@ -1,11 +1,12 @@
-using GHelper.Mode;
+using GHelper.Helpers;
+using GHelper.Mode;
using HidLibrary;
using Microsoft.Win32;
using NAudio.CoreAudioApi;
using System.Diagnostics;
using System.Management;
-namespace GHelper
+namespace GHelper.Input
{
public class KeyboardListener
{
@@ -27,7 +28,7 @@ namespace GHelper
{
// Emergency break
- if (input == null || !input.IsConnected )
+ if (input == null || !input.IsConnected)
{
Logger.WriteLine("Listener terminated");
break;
@@ -69,6 +70,7 @@ namespace GHelper
public static Keys keyApp = Keys.F12;
static ModeControl modeControl = new ModeControl();
+ static ToastForm toast = new ToastForm();
KeyboardListener listener;
KeyboardHook hook = new KeyboardHook();
@@ -135,8 +137,8 @@ namespace GHelper
public void InitBacklightTimer()
{
- timer.Enabled = (AppConfig.Get("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online) ||
- (AppConfig.Get("keyboard_ac_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online);
+ timer.Enabled = AppConfig.Get("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online ||
+ AppConfig.Get("keyboard_ac_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
}
@@ -157,7 +159,7 @@ namespace GHelper
if (!AppConfig.ContainsModel("Z13"))
if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown);
- if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
+ if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
// FN-Lock group
@@ -253,12 +255,12 @@ namespace GHelper
break;
case Keys.F7:
if (AppConfig.ContainsModel("TUF"))
- Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
+ toast.RunToast(ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
HandleOptimizationEvent(16);
break;
case Keys.F8:
- if (AppConfig.ContainsModel("TUF"))
- Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
+ if (AppConfig.ContainsModel("TUF"))
+ toast.RunToast(ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
HandleOptimizationEvent(32);
break;
case Keys.F9:
@@ -334,7 +336,7 @@ namespace GHelper
Program.settingsForm.BeginInvoke(Program.settingsForm.CycleAuraMode);
break;
case "performance":
- Program.settingsForm.BeginInvoke(modeControl.CyclePerformanceMode);
+ modeControl.CyclePerformanceMode();
break;
case "ghelper":
Program.settingsForm.BeginInvoke(delegate
@@ -351,7 +353,7 @@ namespace GHelper
var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
bool muteStatus = !commDevice.AudioEndpointVolume.Mute;
commDevice.AudioEndpointVolume.Mute = muteStatus;
- Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, muteStatus ? "Muted" : "Unmuted", muteStatus ? ToastIcon.MicrophoneMute : ToastIcon.Microphone);
+ toast.RunToast(muteStatus ? "Muted" : "Unmuted", muteStatus ? ToastIcon.MicrophoneMute : ToastIcon.Microphone);
}
break;
case "brightness_up":
@@ -373,7 +375,7 @@ namespace GHelper
{
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PrecisionTouchPad\Status", false))
{
- return (key?.GetValue("Enabled")?.ToString() == "1");
+ return key?.GetValue("Enabled")?.ToString() == "1";
}
}
@@ -383,11 +385,11 @@ namespace GHelper
AppConfig.Set("fn_lock", fnLock);
if (AppConfig.ContainsModel("VivoBook"))
- Program.acpi.DeviceSet(AsusACPI.FnLock, (fnLock == 1) ? 0 : 1, "FnLock");
+ Program.acpi.DeviceSet(AsusACPI.FnLock, fnLock == 1 ? 0 : 1, "FnLock");
else
Program.settingsForm.BeginInvoke(Program.inputDispatcher.RegisterKeys);
- Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, "Fn-Lock "+(fnLock==1?"On":"Off"), ToastIcon.FnLock);
+ toast.RunToast("Fn-Lock " + (fnLock == 1 ? "On" : "Off"), ToastIcon.FnLock);
}
public static void TabletMode()
@@ -397,7 +399,7 @@ namespace GHelper
Logger.WriteLine("Tablet: " + tabletState + " Touchpad: " + touchpadState);
- if ((tabletState && touchpadState) || (!tabletState && !touchpadState)) AsusUSB.TouchpadToggle();
+ if (tabletState && touchpadState || !tabletState && !touchpadState) AsusUSB.TouchpadToggle();
}
@@ -412,7 +414,7 @@ namespace GHelper
KeyProcess("m4");
return;
case 174: // FN+F5
- Program.settingsForm.BeginInvoke(modeControl.CyclePerformanceMode);
+ modeControl.CyclePerformanceMode();
return;
case 179: // FN+F4
case 178: // FN+F4
@@ -441,8 +443,8 @@ namespace GHelper
return;
}
- if (!OptimizationService.IsRunning())
-
+ if (!OptimizationService.IsRunning())
+
HandleOptimizationEvent(EventID);
// Asus Optimization service Events
@@ -463,7 +465,7 @@ namespace GHelper
case 107: // FN+F10
bool touchpadState = GetTouchpadState();
AsusUSB.TouchpadToggle();
- Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, touchpadState ? "Off" : "On", ToastIcon.Touchpad);
+ toast.RunToast(touchpadState ? "Off" : "On", ToastIcon.Touchpad);
break;
case 108: // FN+F11
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.KB_Sleep, "Sleep");
@@ -503,8 +505,8 @@ namespace GHelper
int backlight = onBattery ? backlight_battery : backlight_power;
if (delta >= 4)
- backlight = (++backlight % 4);
- else
+ backlight = ++backlight % 4;
+ else
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
if (onBattery)
@@ -516,7 +518,7 @@ namespace GHelper
{
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);
+ toast.RunToast(backlightNames[backlight], delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
}
}
diff --git a/app/KeyboardHook.cs b/app/Input/KeyboardHook.cs
similarity index 100%
rename from app/KeyboardHook.cs
rename to app/Input/KeyboardHook.cs
diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs
index c78f8e34..62673b39 100644
--- a/app/Mode/ModeControl.cs
+++ b/app/Mode/ModeControl.cs
@@ -1,6 +1,6 @@
-using GHelper.Gpu;
+using GHelper.Gpu.NVidia;
+using GHelper.Helpers;
using Ryzen;
-using System.Diagnostics;
namespace GHelper.Mode
{
@@ -8,6 +8,7 @@ namespace GHelper.Mode
{
static SettingsForm settings = Program.settingsForm;
+ static ToastForm toast = new ToastForm();
private static bool customFans = false;
private static int customPower = 0;
@@ -32,30 +33,20 @@ namespace GHelper.Mode
if (!Modes.Exists(mode)) mode = 0;
+ customFans = false;
+ customPower = 0;
+
settings.ShowMode(mode);
+ SetModeLabel();
Modes.SetCurrent(mode);
- SetModeLabel();
-
- if (IsManualModeRequired())
- Program.acpi.DeviceSet(AsusACPI.PerformanceMode, AsusACPI.PerformanceManual, "Manual Mode");
- else
- Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetBase(mode), "Mode");
+ Program.acpi.DeviceSet(AsusACPI.PerformanceMode, IsManualModeRequired() ? AsusACPI.PerformanceManual : Modes.GetBase(mode), "Mode");
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM();
if (notify)
- {
- try
- {
- settings.toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
- }
- catch
- {
- Debug.WriteLine("Toast error");
- }
- }
+ toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
SetGPUClocks();
AutoFans();
@@ -74,15 +65,14 @@ namespace GHelper.Mode
NativeMethods.SetCPUBoost(AppConfig.GetMode("auto_boost"));
}
+ /*
if (NativeMethods.PowerGetEffectiveOverlayScheme(out Guid activeScheme) == 0)
{
Debug.WriteLine("Effective :" + activeScheme);
}
+ */
- if (settings.fans != null && settings.fans.Text != "")
- {
- settings.fans.InitAll();
- }
+ settings.FansInit();
}
@@ -108,7 +98,6 @@ namespace GHelper.Mode
int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
-
if (AppConfig.Is("mid_fan"))
Program.acpi.SetFanCurve(AsusFan.Mid, AppConfig.GetFanConfig(AsusFan.Mid));
@@ -140,7 +129,7 @@ namespace GHelper.Mode
}
- Program.settingsForm.BeginInvoke(SetModeLabel);
+ SetModeLabel();
}
@@ -263,7 +252,7 @@ namespace GHelper.Mode
}
- Program.settingsForm.BeginInvoke(SetModeLabel);
+ SetModeLabel();
}
@@ -311,14 +300,10 @@ namespace GHelper.Mode
if (gpu_temp < AsusACPI.MinGPUTemp || gpu_temp > AsusACPI.MaxGPUTemp) return;
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0)
- {
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0");
- }
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0)
- {
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2");
- }
}
diff --git a/app/Modes.cs b/app/Mode/Modes.cs
similarity index 98%
rename from app/Modes.cs
rename to app/Mode/Modes.cs
index 44266a82..9543c460 100644
--- a/app/Modes.cs
+++ b/app/Mode/Modes.cs
@@ -1,6 +1,4 @@
-using Microsoft.VisualBasic.Devices;
-
-namespace GHelper
+namespace GHelper.Mode
{
internal class Modes
{
diff --git a/app/Program.cs b/app/Program.cs
index a78940c5..21cd5598 100644
--- a/app/Program.cs
+++ b/app/Program.cs
@@ -1,3 +1,6 @@
+using GHelper.Gpu;
+using GHelper.Helpers;
+using GHelper.Input;
using GHelper.Mode;
using Microsoft.Win32;
using Ryzen;
@@ -22,13 +25,14 @@ namespace GHelper
public static SettingsForm settingsForm = new SettingsForm();
public static ModeControl modeControl = new ModeControl();
+ public static GPUModeControl gpuControl = new GPUModeControl();
public static IntPtr unRegPowerNotify;
private static long lastAuto;
private static long lastTheme;
- public static InputDispatcher inputDispatcher;
+ public static InputDispatcher? inputDispatcher;
private static PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
@@ -50,8 +54,6 @@ namespace GHelper
Thread.CurrentThread.CurrentUICulture = culture;
}
- Debug.WriteLine(CultureInfo.CurrentUICulture);
-
ProcessHelper.CheckAlreadyRunning();
try
@@ -78,15 +80,12 @@ namespace GHelper
HardwareControl.RecreateGpuControl();
RyzenControl.Init();
- var ds = settingsForm.Handle;
-
trayIcon.MouseClick += TrayIcon_MouseClick;
inputDispatcher = new InputDispatcher();
settingsForm.InitAura();
settingsForm.InitMatrix();
- settingsForm.SetStartupCheck(Startup.IsScheduled());
SetAutoModes();
@@ -97,7 +96,7 @@ namespace GHelper
// Subscribing for monitor power on events
PowerSettingGuid settingGuid = new NativeMethods.PowerSettingGuid();
- unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
+ unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(settingsForm.Handle, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0)
@@ -155,11 +154,11 @@ namespace GHelper
settingsForm.SetBatteryChargeLimit(AppConfig.Get("charge_limit"));
modeControl.AutoPerformance(powerChanged);
- bool switched = settingsForm.AutoGPUMode();
+ bool switched = gpuControl.AutoGPUMode();
if (!switched)
{
- settingsForm.InitGPUMode();
+ gpuControl.InitGPUMode();
settingsForm.AutoScreen();
}
@@ -204,7 +203,7 @@ namespace GHelper
settingsForm.FansToggle(1);
break;
case "gpurestart":
- settingsForm.RestartGPU(false);
+ gpuControl.RestartGPU(false);
break;
case "services":
settingsForm.keyb = new Extra();
@@ -214,7 +213,7 @@ namespace GHelper
case "uv":
Startup.ReScheduleAdmin();
settingsForm.FansToggle(2);
- //settingsForm.SetUV(); TODO
+ modeControl.SetUV();
break;
}
}
@@ -223,9 +222,7 @@ namespace GHelper
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
- {
SettingsToggle();
- }
}
diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs
index 10706172..37ae0ea8 100644
--- a/app/Settings.Designer.cs
+++ b/app/Settings.Designer.cs
@@ -1,4 +1,4 @@
-using CustomControls;
+using GHelper.UI;
namespace GHelper
{
@@ -41,7 +41,7 @@ namespace GHelper
labelMatrix = new Label();
checkMatrix = new CheckBox();
panelBattery = new Panel();
- sliderBattery = new WinFormsSliderBar.Slider();
+ sliderBattery = new Slider();
panelBatteryTitle = new Panel();
labelBattery = new Label();
pictureBattery = new PictureBox();
@@ -1169,7 +1169,6 @@ namespace GHelper
ShowIcon = false;
StartPosition = FormStartPosition.CenterScreen;
Text = "G-Helper";
- Load += Settings_Load;
panelMatrix.ResumeLayout(false);
panelMatrix.PerformLayout();
tableLayoutMatrix.ResumeLayout(false);
@@ -1254,7 +1253,7 @@ namespace GHelper
private RButton buttonKeyboard;
private RButton buttonKeyboardColor;
private RButton buttonFans;
- private WinFormsSliderBar.Slider sliderBattery;
+ private Slider sliderBattery;
private RButton buttonUpdates;
private Panel panelGPUTitle;
private PictureBox pictureGPU;
diff --git a/app/Settings.cs b/app/Settings.cs
index 14e3cc84..e4930cc1 100644
--- a/app/Settings.cs
+++ b/app/Settings.cs
@@ -1,7 +1,9 @@
-using CustomControls;
-using GHelper.AnimeMatrix;
+using GHelper.AnimeMatrix;
using GHelper.Gpu;
+using GHelper.Helpers;
+using GHelper.Input;
using GHelper.Mode;
+using GHelper.UI;
using System.Diagnostics;
using System.Net;
using System.Reflection;
@@ -17,17 +19,12 @@ namespace GHelper
ContextMenuStrip contextMenuStrip = new CustomContextMenu();
ToolStripMenuItem menuSilent, menuBalanced, menuTurbo, menuEco, menuStandard, menuUltimate, menuOptimized;
- ModeControl modeControl;
-
- public ToastForm toast = new ToastForm();
+ ModeControl modeControl = new ModeControl();
+ GPUModeControl gpuControl = new GPUModeControl();
public static System.Timers.Timer aTimer = default!;
- public static Point trayPoint;
-
public string versionUrl = "http://github.com/seerge/g-helper/releases";
- //public string modeName = "Balanced";
-
public AniMatrix matrix;
public Fans fans;
public Extra keyb;
@@ -44,8 +41,6 @@ namespace GHelper
InitializeComponent();
InitTheme(true);
- modeControl = new ModeControl();
-
buttonSilent.Text = Properties.Strings.Silent;
buttonBalanced.Text = Properties.Strings.Balanced;
buttonTurbo.Text = Properties.Strings.Turbo;
@@ -133,6 +128,7 @@ namespace GHelper
buttonMatrix.Click += ButtonMatrix_Click;
+ checkStartup.Checked = Startup.IsScheduled();
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
labelVersion.Click += LabelVersion_Click;
@@ -195,7 +191,7 @@ namespace GHelper
if (this.Visible)
{
InitScreen();
- InitXGM();
+ gpuControl.InitXGM();
// Run update once per 12 hours
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeSeconds() - lastUpdate) < 43200) return;
@@ -261,11 +257,6 @@ namespace GHelper
}
}
- public void RunToast(string text, ToastIcon? icon = null)
- {
- toast.RunToast(text, icon);
- }
-
public void SetContextMenu()
{
@@ -351,47 +342,7 @@ namespace GHelper
private void ButtonXGM_Click(object? sender, EventArgs e)
{
-
- Task.Run(async () =>
- {
- BeginInvoke(delegate
- {
- ButtonEnabled(buttonOptimized, false);
- ButtonEnabled(buttonEco, false);
- ButtonEnabled(buttonStandard, false);
- ButtonEnabled(buttonUltimate, false);
- ButtonEnabled(buttonXGM, false);
- });
-
- if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
- {
- HardwareControl.KillGPUApps();
- DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Program.acpi.DeviceSet(AsusACPI.GPUXG, 0, "GPU XGM");
- await Task.Delay(TimeSpan.FromSeconds(15));
- }
- }
- else
- {
- Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM");
- AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light"));
-
- await Task.Delay(TimeSpan.FromSeconds(15));
-
- if (AppConfig.IsMode("auto_apply"))
- AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM));
- }
-
- BeginInvoke(delegate
- {
- InitGPUMode();
- });
-
-
- });
-
+ gpuControl.ToggleXGM();
}
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
@@ -451,8 +402,7 @@ namespace GHelper
}
catch (Exception ex)
{
- //Logger.WriteLine("Failed to check for updates:" + ex.Message);
-
+ Debug.WriteLine("Failed to check for updates:" + ex.Message);
}
}
@@ -581,7 +531,7 @@ namespace GHelper
{
AppConfig.Set("gpu_auto", (AppConfig.Get("gpu_auto") == 1) ? 0 : 1);
VisualiseGPUMode();
- AutoGPUMode();
+ gpuControl.AutoGPUMode();
}
private void ButtonScreenAuto_Click(object? sender, EventArgs e)
@@ -598,13 +548,9 @@ namespace GHelper
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
- {
Startup.Schedule();
- }
else
- {
Startup.UnSchedule();
- }
}
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
@@ -703,6 +649,14 @@ namespace GHelper
}
}
+ public void FansInit()
+ {
+ Invoke(delegate
+ {
+ if (fans != null && fans.Text != "") fans.InitAll();
+ });
+ }
+
public void FansToggle(int index = 0)
{
if (fans == null || fans.Text == "")
@@ -783,13 +737,10 @@ namespace GHelper
return;
}
- int brightness = AppConfig.Get("matrix_brightness");
- int running = AppConfig.Get("matrix_running");
+ comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1);
+ comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1);
- comboMatrix.SelectedIndex = (brightness != -1) ? Math.Min(brightness, comboMatrix.Items.Count - 1) : 0;
- comboMatrixRunning.SelectedIndex = (running != -1) ? Math.Min(running, comboMatrixRunning.Items.Count - 1) : 0;
-
- checkMatrix.Checked = (AppConfig.Get("matrix_auto") == 1);
+ checkMatrix.Checked = AppConfig.Is("matrix_auto");
checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged;
}
@@ -890,7 +841,7 @@ namespace GHelper
int frequency = NativeMethods.GetRefreshRate();
int maxFrequency = NativeMethods.GetRefreshRate(true);
- bool screenAuto = (AppConfig.Get("screen_auto") == 1);
+ bool screenAuto = AppConfig.Is("screen_auto");
bool overdriveSetting = (AppConfig.Get("no_overdrive") != 1);
int overdrive = Program.acpi.DeviceGet(AsusACPI.ScreenOverdrive);
@@ -978,26 +929,23 @@ namespace GHelper
private void ButtonUltimate_Click(object? sender, EventArgs e)
{
- SetGPUMode(AsusACPI.GPUModeUltimate);
+ gpuControl.SetGPUMode(AsusACPI.GPUModeUltimate);
}
private void ButtonStandard_Click(object? sender, EventArgs e)
{
- SetGPUMode(AsusACPI.GPUModeStandard);
+ gpuControl.SetGPUMode(AsusACPI.GPUModeStandard);
}
private void ButtonEco_Click(object? sender, EventArgs e)
{
- SetGPUMode(AsusACPI.GPUModeEco);
+ gpuControl.SetGPUMode(AsusACPI.GPUModeEco);
}
private void ButtonStopGPU_Click(object? sender, EventArgs e)
{
- if (HardwareControl.GpuControl is not null)
- {
- HardwareControl.GpuControl.KillGPUApps();
- }
+ gpuControl.KillGPUApps();
}
public async void RefreshSensors(bool force = false)
@@ -1050,54 +998,51 @@ namespace GHelper
public void ShowMode(int mode)
{
-
- buttonSilent.Activated = false;
- buttonBalanced.Activated = false;
- buttonTurbo.Activated = false;
- buttonFans.Activated = false;
-
- menuSilent.Checked = false;
- menuBalanced.Checked = false;
- menuTurbo.Checked = false;
-
- switch (mode)
+ Invoke(delegate
{
- case AsusACPI.PerformanceSilent:
- buttonSilent.Activated = true;
- menuSilent.Checked = true;
- break;
- case AsusACPI.PerformanceTurbo:
- buttonTurbo.Activated = true;
- menuTurbo.Checked = true;
- break;
- case AsusACPI.PerformanceBalanced:
- buttonBalanced.Activated = true;
- menuBalanced.Checked = true;
- break;
- default:
- buttonFans.Activated = true;
- switch (Modes.GetBase(mode))
- {
- case AsusACPI.PerformanceSilent:
- buttonFans.BorderColor = colorEco;
- break;
- case AsusACPI.PerformanceTurbo:
- buttonFans.BorderColor = colorTurbo;
- break;
- default:
- buttonFans.BorderColor = colorStandard;
- break;
- }
- break;
- }
+ buttonSilent.Activated = false;
+ buttonBalanced.Activated = false;
+ buttonTurbo.Activated = false;
+ buttonFans.Activated = false;
+ menuSilent.Checked = false;
+ menuBalanced.Checked = false;
+ menuTurbo.Checked = false;
+ switch (mode)
+ {
+ case AsusACPI.PerformanceSilent:
+ buttonSilent.Activated = true;
+ menuSilent.Checked = true;
+ break;
+ case AsusACPI.PerformanceTurbo:
+ buttonTurbo.Activated = true;
+ menuTurbo.Checked = true;
+ break;
+ case AsusACPI.PerformanceBalanced:
+ buttonBalanced.Activated = true;
+ menuBalanced.Checked = true;
+ break;
+ default:
+ buttonFans.Activated = true;
+ buttonFans.BorderColor = Modes.GetBase(mode) switch
+ {
+ AsusACPI.PerformanceSilent => colorEco,
+ AsusACPI.PerformanceTurbo => colorTurbo,
+ _ => colorStandard,
+ };
+ break;
+ }
+ });
}
public void SetModeLabel(string modeText)
{
- labelPerf.Text = modeText;
+ Invoke(delegate
+ {
+ labelPerf.Text = modeText;
+ });
}
@@ -1131,88 +1076,15 @@ namespace GHelper
}
- public static bool IsPlugged()
- {
- bool optimizedUSBC = AppConfig.Get("optimized_usbc") != 1;
-
- return SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online &&
- (optimizedUSBC || Program.acpi.DeviceGet(AsusACPI.ChargerMode) < AsusACPI.ChargerUSB);
-
- }
-
- public bool AutoGPUMode()
+ public void VisualizeXGM(bool connected, bool activated)
{
- bool GpuAuto = AppConfig.Is("gpu_auto");
- bool ForceGPU = AppConfig.ContainsModel("503");
-
- int GpuMode = AppConfig.Get("gpu_mode");
-
- if (!GpuAuto && !ForceGPU) return false;
-
- int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
- int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
-
- if (mux == 0) // GPU in Ultimate, ignore
- return false;
- else
- {
-
- if (ReEnableGPU()) return true;
-
- if (eco == 1)
- if ((GpuAuto && IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeStandard))
- {
- SetGPUEco(0);
- return true;
- }
- if (eco == 0)
- if ((GpuAuto && !IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeEco))
- {
-
- if (HardwareControl.IsUsedGPU())
- {
- DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertDGPU, Properties.Strings.AlertDGPUTitle, MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.No) return false;
- }
-
- SetGPUEco(1);
- return true;
- }
- }
-
- return false;
-
- }
-
- public bool ReEnableGPU()
- {
-
- if (AppConfig.Get("gpu_reenable") != 1) return false;
- if (Screen.AllScreens.Length <= 1) return false;
-
- Logger.WriteLine("Re-enabling gpu for 503 model");
-
- Thread.Sleep(1000);
- SetGPUEco(1);
- Thread.Sleep(1000);
- SetGPUEco(0);
- return true;
- }
-
- public void InitXGM()
- {
- bool connected = Program.acpi.IsXGConnected();
buttonXGM.Enabled = buttonXGM.Visible = connected;
-
if (!connected) return;
- int activated = Program.acpi.DeviceGet(AsusACPI.GPUXG);
- if (activated < 0) return;
+ buttonXGM.Activated = activated;
- buttonXGM.Activated = (activated == 1);
-
- if (buttonXGM.Activated)
+ if (activated)
{
ButtonEnabled(buttonOptimized, false);
ButtonEnabled(buttonEco, false);
@@ -1229,231 +1101,52 @@ namespace GHelper
}
-
- public int InitGPUMode()
+ public void HideUltimateMode()
{
+ tableGPU.Controls.Remove(buttonUltimate);
+ tablePerf.ColumnCount = 0;
+ tableGPU.ColumnCount = 0;
+ tableScreen.ColumnCount = 0;
+ menuUltimate.Visible = false;
+ }
- int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
- int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
+ public void HideGPUModes()
+ {
+ isGpuSection = false;
+ buttonEco.Visible = false;
+ buttonStandard.Visible = false;
+ buttonUltimate.Visible = false;
+ buttonOptimized.Visible = false;
+ buttonStopGPU.Visible = true;
- Logger.WriteLine("Eco flag : " + eco);
- Logger.WriteLine("Mux flag : " + mux);
-
- int GpuMode;
-
- if (mux == 0)
- GpuMode = AsusACPI.GPUModeUltimate;
- else
- {
- if (eco == 1)
- GpuMode = AsusACPI.GPUModeEco;
- else
- GpuMode = AsusACPI.GPUModeStandard;
-
- // Ultimate mode not suported
- if (mux != 1)
- {
- tableGPU.Controls.Remove(buttonUltimate);
- tablePerf.ColumnCount = 0;
- tableGPU.ColumnCount = 0;
- tableScreen.ColumnCount = 0;
- menuUltimate.Visible = false;
- }
-
- if (eco < 0 && mux < 0)
- {
- isGpuSection = false;
-
- buttonEco.Visible = false;
- buttonStandard.Visible = false;
- buttonUltimate.Visible = false;
- buttonOptimized.Visible = false;
- buttonStopGPU.Visible = true;
-
- SetContextMenu();
-
- if (HardwareControl.FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan)) is null) panelGPU.Visible = false;
- }
-
- }
-
- AppConfig.Set("gpu_mode", GpuMode);
-
- ButtonEnabled(buttonOptimized, true);
- ButtonEnabled(buttonEco, true);
- ButtonEnabled(buttonStandard, true);
- ButtonEnabled(buttonUltimate, true);
-
- InitXGM();
-
- VisualiseGPUMode(GpuMode);
-
- return GpuMode;
+ SetContextMenu();
+ if (HardwareControl.FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan)) is null) panelGPU.Visible = false;
}
- public void RestartGPU(bool confirm = true)
+ public void LockGPUModes(string text = null)
{
- if (HardwareControl.GpuControl is null) return;
- if (!HardwareControl.GpuControl!.IsNvidia) return;
-
- if (confirm)
+ Invoke(delegate
{
- DialogResult dialogResult = MessageBox.Show(Properties.Strings.RestartGPU, Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.No) return;
- }
+ if (text is null) text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";
- ProcessHelper.RunAsAdmin("gpurestart");
+ ButtonEnabled(buttonOptimized, false);
+ ButtonEnabled(buttonEco, false);
+ ButtonEnabled(buttonStandard, false);
+ ButtonEnabled(buttonUltimate, false);
+ ButtonEnabled(buttonXGM, false);
- if (!ProcessHelper.IsUserAdministrator()) return;
-
- Logger.WriteLine("Trying to restart dGPU");
-
- Task.Run(async () =>
- {
- Program.settingsForm.BeginInvoke(delegate
- {
- labelTipGPU.Text = "Restarting GPU ...";
- ButtonEnabled(buttonOptimized, false);
- ButtonEnabled(buttonEco, false);
- ButtonEnabled(buttonStandard, false);
- ButtonEnabled(buttonUltimate, false);
- });
-
- var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
- bool status = nvControl.RestartGPU();
-
- Program.settingsForm.BeginInvoke(delegate
- {
- labelTipGPU.Text = status ? "GPU Restarted, you can try Eco mode again" : "Failed to restart GPU";
- InitGPUMode();
- });
+ labelGPU.Text = text;
});
-
- }
-
-
- public void SetGPUEco(int eco, bool hardWay = false)
- {
-
- ButtonEnabled(buttonOptimized, false);
- ButtonEnabled(buttonEco, false);
- ButtonEnabled(buttonStandard, false);
- ButtonEnabled(buttonUltimate, false);
- ButtonEnabled(buttonXGM, false);
-
- labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";
-
- Task.Run(async () =>
- {
-
- int status = 1;
-
- if (eco == 1)
- {
- if (NvidiaSmi.GetDisplayActiveStatus())
- {
- DialogResult dialogResult = MessageBox.Show(Properties.Strings.EnableOptimusText, Properties.Strings.EnableOptimusTitle, MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.No)
- {
- InitGPUMode();
- return;
- }
- }
-
- HardwareControl.KillGPUApps();
- }
-
- Logger.WriteLine($"Running eco command {eco}");
-
- status = Program.acpi.SetGPUEco(eco);
-
- if (status == 0 && eco == 1 && hardWay) RestartGPU();
-
- await Task.Delay(TimeSpan.FromMilliseconds(100));
- Program.settingsForm.BeginInvoke(delegate
- {
- InitGPUMode();
- AutoScreen();
- });
-
- if (eco == 0)
- {
- await Task.Delay(TimeSpan.FromMilliseconds(3000));
- HardwareControl.RecreateGpuControl();
- modeControl.SetGPUClocks(false);
- }
-
- });
-
-
- }
-
- public void SetGPUMode(int GPUMode)
- {
-
- int CurrentGPU = AppConfig.Get("gpu_mode");
- AppConfig.Set("gpu_auto", 0);
-
- if (CurrentGPU == GPUMode)
- {
- VisualiseGPUMode();
- return;
- }
-
- var restart = false;
- var changed = false;
-
- if (CurrentGPU == AsusACPI.GPUModeUltimate)
- {
- DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOff, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Program.acpi.DeviceSet(AsusACPI.GPUMux, 1, "GPUMux");
- restart = true;
- changed = true;
- }
- }
- else if (GPUMode == AsusACPI.GPUModeUltimate)
- {
- DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOn, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Program.acpi.DeviceSet(AsusACPI.GPUMux, 0, "GPUMux");
- restart = true;
- changed = true;
- }
-
- }
- else if (GPUMode == AsusACPI.GPUModeEco)
- {
- VisualiseGPUMode(GPUMode);
- SetGPUEco(1, true);
- changed = true;
- }
- else if (GPUMode == AsusACPI.GPUModeStandard)
- {
- VisualiseGPUMode(GPUMode);
- SetGPUEco(0);
- changed = true;
- }
-
- if (changed)
- {
- AppConfig.Set("gpu_mode", GPUMode);
- }
-
- if (restart)
- {
- VisualiseGPUMode();
- Process.Start("shutdown", "/r /t 1");
- }
-
}
public void VisualiseGPUMode(int GPUMode = -1)
{
+ ButtonEnabled(buttonOptimized, true);
+ ButtonEnabled(buttonEco, true);
+ ButtonEnabled(buttonStandard, true);
+ ButtonEnabled(buttonUltimate, true);
if (GPUMode == -1)
GPUMode = AppConfig.Get("gpu_mode");
@@ -1516,10 +1209,6 @@ namespace GHelper
modeControl.SetPerformanceMode(AsusACPI.PerformanceTurbo);
}
- private void Settings_Load(object sender, EventArgs e)
- {
-
- }
public void ButtonEnabled(RButton but, bool enabled)
{
@@ -1527,12 +1216,6 @@ namespace GHelper
but.BackColor = but.Enabled ? Color.FromArgb(255, but.BackColor) : Color.FromArgb(100, but.BackColor);
}
- public void SetStartupCheck(bool status)
- {
- checkStartup.CheckedChanged -= CheckStartup_CheckedChanged;
- checkStartup.Checked = status;
- checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
- }
public void SetBatteryChargeLimit(int limit)
{
diff --git a/app/ControlHelper.cs b/app/UI/ControlHelper.cs
similarity index 99%
rename from app/ControlHelper.cs
rename to app/UI/ControlHelper.cs
index 637fa56f..8addc332 100644
--- a/app/ControlHelper.cs
+++ b/app/UI/ControlHelper.cs
@@ -1,7 +1,6 @@
-using CustomControls;
+using GHelper.UI;
using System.Drawing.Drawing2D;
using System.Windows.Forms.DataVisualization.Charting;
-using WinFormsSliderBar;
public static class ControlHelper
{
diff --git a/app/CustomContextMenu.cs b/app/UI/CustomContextMenu.cs
similarity index 92%
rename from app/CustomContextMenu.cs
rename to app/UI/CustomContextMenu.cs
index c45dd4d7..194fffd9 100644
--- a/app/CustomContextMenu.cs
+++ b/app/UI/CustomContextMenu.cs
@@ -1,11 +1,11 @@
using System.Runtime.InteropServices;
-namespace GHelper
+namespace GHelper.UI
{
class CustomContextMenu : ContextMenuStrip
{
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- private static extern long DwmSetWindowAttribute(IntPtr hwnd,
+ private static extern long DwmSetWindowAttribute(nint hwnd,
DWMWINDOWATTRIBUTE attribute,
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
uint cbAttribute);
diff --git a/app/CustomControls.cs b/app/UI/CustomControls.cs
similarity index 91%
rename from app/CustomControls.cs
rename to app/UI/CustomControls.cs
index 6c237dee..cd1da12c 100644
--- a/app/CustomControls.cs
+++ b/app/UI/CustomControls.cs
@@ -3,7 +3,7 @@ using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
-namespace CustomControls
+namespace GHelper.UI
{
public class RForm : Form
@@ -28,7 +28,7 @@ namespace CustomControls
public static extern bool CheckSystemDarkModeStatus();
[DllImport("DwmApi")] //System.Runtime.InteropServices
- private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
+ private static extern int DwmSetWindowAttribute(nint hwnd, int attr, int[] attrValue, int attrSize);
public bool darkTheme = false;
@@ -72,7 +72,7 @@ namespace CustomControls
public bool InitTheme(bool setDPI = false)
{
bool newDarkTheme = CheckSystemDarkModeStatus();
- bool changed = (darkTheme != newDarkTheme);
+ bool changed = darkTheme != newDarkTheme;
darkTheme = newDarkTheme;
InitColors(darkTheme);
@@ -82,7 +82,7 @@ namespace CustomControls
if (changed)
{
- DwmSetWindowAttribute(this.Handle, 20, new[] { darkTheme ? 1 : 0 }, 4);
+ DwmSetWindowAttribute(Handle, 20, new[] { darkTheme ? 1 : 0 }, 4);
ControlHelper.Adjust(this, changed);
}
@@ -182,8 +182,8 @@ namespace CustomControls
};
var ps = new PAINTSTRUCT();
bool shoulEndPaint = false;
- IntPtr dc;
- if (m.WParam == IntPtr.Zero)
+ nint dc;
+ if (m.WParam == nint.Zero)
{
dc = BeginPaint(Handle, ref ps);
m.WParam = dc;
@@ -196,7 +196,7 @@ namespace CustomControls
var rgn = CreateRectRgn(innerInnerBorder.Left, innerInnerBorder.Top,
innerInnerBorder.Right, innerInnerBorder.Bottom);
-
+
SelectClipRgn(dc, rgn);
DefWndProc(ref m);
DeleteObject(rgn);
@@ -240,7 +240,7 @@ namespace CustomControls
[StructLayout(LayoutKind.Sequential)]
public struct PAINTSTRUCT
{
- public IntPtr hdc;
+ public nint hdc;
public bool fErase;
public int rcPaint_left;
public int rcPaint_top;
@@ -258,17 +258,17 @@ namespace CustomControls
public int reserved8;
}
[DllImport("user32.dll")]
- private static extern IntPtr BeginPaint(IntPtr hWnd,
+ private static extern nint BeginPaint(nint hWnd,
[In, Out] ref PAINTSTRUCT lpPaint);
[DllImport("user32.dll")]
- private static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint);
+ private static extern bool EndPaint(nint hWnd, ref PAINTSTRUCT lpPaint);
[DllImport("gdi32.dll")]
- public static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn);
+ public static extern int SelectClipRgn(nint hDC, nint hRgn);
[DllImport("user32.dll")]
- public static extern int GetUpdateRgn(IntPtr hwnd, IntPtr hrgn, bool fErase);
+ public static extern int GetUpdateRgn(nint hwnd, nint hrgn, bool fErase);
public enum RegionFlags
{
ERROR = 0,
@@ -277,10 +277,10 @@ namespace CustomControls
COMPLEXREGION = 3,
}
[DllImport("gdi32.dll")]
- internal static extern bool DeleteObject(IntPtr hObject);
+ internal static extern bool DeleteObject(nint hObject);
[DllImport("gdi32.dll")]
- private static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
+ private static extern nint CreateRectRgn(int x1, int y1, int x2, int y2);
}
public class RButton : Button
@@ -316,7 +316,7 @@ namespace CustomControls
set
{
if (activated != value)
- this.Invalidate();
+ Invalidate();
activated = value;
}
@@ -362,19 +362,19 @@ namespace CustomControls
float ratio = pevent.Graphics.DpiX / 192.0f;
int border = (int)(ratio * borderSize);
- Rectangle rectSurface = this.ClientRectangle;
+ Rectangle rectSurface = ClientRectangle;
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -border, -border);
Color borderDrawColor = activated ? borderColor : Color.Transparent;
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius + border))
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius))
- using (Pen penSurface = new Pen(this.Parent.BackColor, border))
+ using (Pen penSurface = new Pen(Parent.BackColor, border))
using (Pen penBorder = new Pen(borderDrawColor, border))
{
penBorder.Alignment = PenAlignment.Outset;
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- this.Region = new Region(pathSurface);
+ Region = new Region(pathSurface);
pevent.Graphics.DrawPath(penSurface, pathSurface);
pevent.Graphics.DrawPath(penBorder, pathBorder);
}
@@ -388,7 +388,7 @@ namespace CustomControls
rect.Height -= Image.Height;
}
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
- TextRenderer.DrawText(pevent.Graphics, this.Text, this.Font, rect, Color.Gray, flags);
+ TextRenderer.DrawText(pevent.Graphics, Text, Font, rect, Color.Gray, flags);
}
diff --git a/app/CustomControls.resx b/app/UI/CustomControls.resx
similarity index 100%
rename from app/CustomControls.resx
rename to app/UI/CustomControls.resx
diff --git a/app/Slider.cs b/app/UI/Slider.cs
similarity index 99%
rename from app/Slider.cs
rename to app/UI/Slider.cs
index 203a615f..b179fd3c 100644
--- a/app/Slider.cs
+++ b/app/UI/Slider.cs
@@ -1,6 +1,6 @@
using System.Drawing.Drawing2D;
-namespace WinFormsSliderBar
+namespace GHelper.UI
{
public static class GraphicsExtensions
{
diff --git a/app/Updates.Designer.cs b/app/Updates.Designer.cs
index b065f8d0..444f997a 100644
--- a/app/Updates.Designer.cs
+++ b/app/Updates.Designer.cs
@@ -1,4 +1,6 @@
-namespace GHelper
+using GHelper.UI;
+
+namespace GHelper
{
partial class Updates
{
@@ -34,7 +36,7 @@
pictureBios = new PictureBox();
panelBiosTitle = new Panel();
labelUpdates = new Label();
- buttonRefresh = new CustomControls.RButton();
+ buttonRefresh = new RButton();
panelBios = new Panel();
panelDrivers = new Panel();
tableDrivers = new TableLayoutPanel();
@@ -242,7 +244,7 @@
private Panel panelDriversTitle;
private Label labelDrivers;
private PictureBox pictureDrivers;
- private CustomControls.RButton buttonRefresh;
+ private RButton buttonRefresh;
private Label labelUpdates;
}
}
\ No newline at end of file
diff --git a/app/Updates.cs b/app/Updates.cs
index 5e4b96c0..0c4499a7 100644
--- a/app/Updates.cs
+++ b/app/Updates.cs
@@ -1,4 +1,4 @@
-using CustomControls;
+using GHelper.UI;
using System.Diagnostics;
using System.Management;
using System.Net;