mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
More cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using GHelper;
|
using GHelper.Mode;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|||||||
4
app/Extra.Designer.cs
generated
4
app/Extra.Designer.cs
generated
@@ -1,5 +1,5 @@
|
|||||||
using CustomControls;
|
using GHelper.Properties;
|
||||||
using GHelper.Properties;
|
using GHelper.UI;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using CustomControls;
|
using GHelper.Gpu.AMD;
|
||||||
using GHelper.Gpu;
|
using GHelper.Helpers;
|
||||||
|
using GHelper.Input;
|
||||||
|
using GHelper.UI;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
|
|||||||
2
app/Fans.Designer.cs
generated
2
app/Fans.Designer.cs
generated
@@ -1,4 +1,4 @@
|
|||||||
using CustomControls;
|
using GHelper.UI;
|
||||||
using System.Windows.Forms.DataVisualization.Charting;
|
using System.Windows.Forms.DataVisualization.Charting;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using CustomControls;
|
using GHelper.Gpu.NVidia;
|
||||||
using GHelper.Gpu;
|
|
||||||
using GHelper.Mode;
|
using GHelper.Mode;
|
||||||
|
using GHelper.UI;
|
||||||
using Ryzen;
|
using Ryzen;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows.Forms.DataVisualization.Charting;
|
using System.Windows.Forms.DataVisualization.Charting;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
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
|
#region Export Struct
|
||||||
|
|
||||||
@@ -33,13 +33,15 @@ public struct ADLBdf
|
|||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLSingleSensorData {
|
public struct ADLSingleSensorData
|
||||||
|
{
|
||||||
public int Supported;
|
public int Supported;
|
||||||
public int Value;
|
public int Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLPMLogDataOutput {
|
public struct ADLPMLogDataOutput
|
||||||
|
{
|
||||||
int Size;
|
int Size;
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_PMLOG_MAX_SENSORS)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_PMLOG_MAX_SENSORS)]
|
||||||
@@ -57,7 +59,8 @@ public struct ADLGcnInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum ADLAsicFamilyType {
|
public enum ADLAsicFamilyType
|
||||||
|
{
|
||||||
Undefined = 0,
|
Undefined = 0,
|
||||||
Discrete = 1 << 0,
|
Discrete = 1 << 0,
|
||||||
Integrated = 1 << 1,
|
Integrated = 1 << 1,
|
||||||
@@ -69,7 +72,8 @@ public enum ADLAsicFamilyType {
|
|||||||
Embedded = 1 << 7,
|
Embedded = 1 << 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ADLSensorType {
|
public enum ADLSensorType
|
||||||
|
{
|
||||||
SENSOR_MAXTYPES = 0,
|
SENSOR_MAXTYPES = 0,
|
||||||
PMLOG_CLK_GFXCLK = 1, // Current graphic clock value in MHz
|
PMLOG_CLK_GFXCLK = 1, // Current graphic clock value in MHz
|
||||||
PMLOG_CLK_MEMCLK = 2, // Current memory clock value in MHz
|
PMLOG_CLK_MEMCLK = 2, // Current memory clock value in MHz
|
||||||
@@ -149,13 +153,15 @@ public enum ADLSensorType {
|
|||||||
|
|
||||||
//Throttle Status
|
//Throttle Status
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum ADL_THROTTLE_NOTIFICATION {
|
public enum ADL_THROTTLE_NOTIFICATION
|
||||||
|
{
|
||||||
ADL_PMLOG_THROTTLE_POWER = 1 << 0,
|
ADL_PMLOG_THROTTLE_POWER = 1 << 0,
|
||||||
ADL_PMLOG_THROTTLE_THERMAL = 1 << 1,
|
ADL_PMLOG_THROTTLE_THERMAL = 1 << 1,
|
||||||
ADL_PMLOG_THROTTLE_CURRENT = 1 << 2,
|
ADL_PMLOG_THROTTLE_CURRENT = 1 << 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
public enum ADL_PMLOG_SENSORS {
|
public enum ADL_PMLOG_SENSORS
|
||||||
|
{
|
||||||
ADL_SENSOR_MAXTYPES = 0,
|
ADL_SENSOR_MAXTYPES = 0,
|
||||||
ADL_PMLOG_CLK_GFXCLK = 1,
|
ADL_PMLOG_CLK_GFXCLK = 1,
|
||||||
ADL_PMLOG_CLK_MEMCLK = 2,
|
ADL_PMLOG_CLK_MEMCLK = 2,
|
||||||
@@ -237,7 +243,8 @@ public enum ADL_PMLOG_SENSORS {
|
|||||||
|
|
||||||
/// <summary> ADLAdapterInfo Structure</summary>
|
/// <summary> ADLAdapterInfo Structure</summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLAdapterInfo {
|
public struct ADLAdapterInfo
|
||||||
|
{
|
||||||
/// <summary>The size of the structure</summary>
|
/// <summary>The size of the structure</summary>
|
||||||
int Size;
|
int Size;
|
||||||
|
|
||||||
@@ -292,7 +299,8 @@ public struct ADLAdapterInfo {
|
|||||||
|
|
||||||
/// <summary> ADLAdapterInfo Array</summary>
|
/// <summary> ADLAdapterInfo Array</summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLAdapterInfoArray {
|
public struct ADLAdapterInfoArray
|
||||||
|
{
|
||||||
/// <summary> ADLAdapterInfo Array </summary>
|
/// <summary> ADLAdapterInfo Array </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_MAX_ADAPTERS)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_MAX_ADAPTERS)]
|
||||||
public ADLAdapterInfo[] ADLAdapterInfo;
|
public ADLAdapterInfo[] ADLAdapterInfo;
|
||||||
@@ -304,7 +312,8 @@ public struct ADLAdapterInfoArray {
|
|||||||
|
|
||||||
/// <summary> ADLDisplayID Structure</summary>
|
/// <summary> ADLDisplayID Structure</summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLDisplayID {
|
public struct ADLDisplayID
|
||||||
|
{
|
||||||
/// <summary> Display Logical Index </summary>
|
/// <summary> Display Logical Index </summary>
|
||||||
public int DisplayLogicalIndex;
|
public int DisplayLogicalIndex;
|
||||||
|
|
||||||
@@ -320,7 +329,8 @@ public struct ADLDisplayID {
|
|||||||
|
|
||||||
/// <summary> ADLDisplayInfo Structure</summary>
|
/// <summary> ADLDisplayInfo Structure</summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct ADLDisplayInfo {
|
public struct ADLDisplayInfo
|
||||||
|
{
|
||||||
/// <summary> Display Index </summary>
|
/// <summary> Display Index </summary>
|
||||||
public ADLDisplayID DisplayID;
|
public ADLDisplayID DisplayID;
|
||||||
|
|
||||||
@@ -355,7 +365,8 @@ public struct ADLDisplayInfo {
|
|||||||
|
|
||||||
#endregion Export Struct
|
#endregion Export Struct
|
||||||
|
|
||||||
public class Adl2 {
|
public class Adl2
|
||||||
|
{
|
||||||
public const string Atiadlxx_FileName = "atiadlxx.dll";
|
public const string Atiadlxx_FileName = "atiadlxx.dll";
|
||||||
|
|
||||||
#region Internal Constant
|
#region Internal Constant
|
||||||
@@ -398,24 +409,30 @@ public class Adl2 {
|
|||||||
// ///// <summary> ADL Create Function to create ADL Data</summary>
|
// ///// <summary> ADL Create Function to create ADL Data</summary>
|
||||||
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only return the physical exist adapters </param>
|
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only return the physical exist adapters </param>
|
||||||
///// <returns> retrun ADL Error Code</returns>
|
///// <returns> retrun ADL Error Code</returns>
|
||||||
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);
|
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);
|
Memory_Free_Impl(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool? isDllLoaded;
|
private static bool? isDllLoaded;
|
||||||
|
|
||||||
public static bool Load() {
|
public static bool Load()
|
||||||
|
{
|
||||||
if (isDllLoaded != null)
|
if (isDllLoaded != null)
|
||||||
return isDllLoaded.Value;
|
return isDllLoaded.Value;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
Marshal.PrelinkAll(typeof(Adl2));
|
Marshal.PrelinkAll(typeof(Adl2));
|
||||||
isDllLoaded = true;
|
isDllLoaded = true;
|
||||||
} catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException) {
|
}
|
||||||
|
catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException)
|
||||||
|
{
|
||||||
Debug.WriteLine(e);
|
Debug.WriteLine(e);
|
||||||
isDllLoaded = false;
|
isDllLoaded = false;
|
||||||
}
|
}
|
||||||
@@ -423,53 +440,57 @@ public class Adl2 {
|
|||||||
return isDllLoaded.Value;
|
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;
|
||||||
|
|
||||||
/// <summary> Build in memory allocation function</summary>
|
/// <summary> Build in memory allocation function</summary>
|
||||||
/// <param name="size">input size</param>
|
/// <param name="size">input size</param>
|
||||||
/// <returns>return the memory buffer</returns>
|
/// <returns>return the memory buffer</returns>
|
||||||
private static IntPtr Memory_Alloc_Impl(int size) {
|
private static nint Memory_Alloc_Impl(int size)
|
||||||
|
{
|
||||||
return Marshal.AllocCoTaskMem(size);
|
return Marshal.AllocCoTaskMem(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Build in memory free function</summary>
|
/// <summary> Build in memory free function</summary>
|
||||||
/// <param name="buffer">input buffer</param>
|
/// <param name="buffer">input buffer</param>
|
||||||
private static void Memory_Free_Impl(IntPtr buffer) {
|
private static void Memory_Free_Impl(nint buffer)
|
||||||
if (IntPtr.Zero != buffer) {
|
{
|
||||||
|
if (nint.Zero != buffer)
|
||||||
|
{
|
||||||
Marshal.FreeCoTaskMem(buffer);
|
Marshal.FreeCoTaskMem(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NativeMethods {
|
public static class NativeMethods
|
||||||
|
{
|
||||||
/// <summary> ADL Memory allocation function allows ADL to callback for memory allocation</summary>
|
/// <summary> ADL Memory allocation function allows ADL to callback for memory allocation</summary>
|
||||||
/// <param name="size">input size</param>
|
/// <param name="size">input size</param>
|
||||||
/// <returns> retrun ADL Error Code</returns>
|
/// <returns> retrun ADL Error Code</returns>
|
||||||
public delegate IntPtr ADL_Main_Memory_Alloc(int size);
|
public delegate nint ADL_Main_Memory_Alloc(int size);
|
||||||
|
|
||||||
// ///// <summary> ADL Create Function to create ADL Data</summary>
|
// ///// <summary> ADL Create Function to create ADL Data</summary>
|
||||||
/// <param name="callback">Call back functin pointer which is ised to allocate memeory </param>
|
/// <param name="callback">Call back functin pointer which is ised to allocate memeory </param>
|
||||||
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only retuen the physical exist adapters </param>
|
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only retuen the physical exist adapters </param>
|
||||||
///// <returns> retrun ADL Error Code</returns>
|
///// <returns> retrun ADL Error Code</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[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);
|
||||||
|
|
||||||
/// <summary> ADL Destroy Function to free up ADL Data</summary>
|
/// <summary> ADL Destroy Function to free up ADL Data</summary>
|
||||||
/// <returns> retrun ADL Error Code</returns>
|
/// <returns> retrun ADL Error Code</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_Main_Control_Destroy(IntPtr adlContextHandle);
|
public static extern int ADL2_Main_Control_Destroy(nint adlContextHandle);
|
||||||
|
|
||||||
/// <summary> ADL Function to get the number of adapters</summary>
|
/// <summary> ADL Function to get the number of adapters</summary>
|
||||||
/// <param name="numAdapters">return number of adapters</param>
|
/// <param name="numAdapters">return number of adapters</param>
|
||||||
/// <returns> retrun ADL Error Code</returns>
|
/// <returns> retrun ADL Error Code</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[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);
|
||||||
|
|
||||||
/// <summary> ADL Function to get the GPU adapter information</summary>
|
/// <summary> ADL Function to get the GPU adapter information</summary>
|
||||||
/// <param name="info">return GPU adapter information</param>
|
/// <param name="info">return GPU adapter information</param>
|
||||||
/// <param name="inputSize">the size of the GPU adapter struct</param>
|
/// <param name="inputSize">the size of the GPU adapter struct</param>
|
||||||
/// <returns> retrun ADL Error Code</returns>
|
/// <returns> retrun ADL Error Code</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[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);
|
||||||
|
|
||||||
/// <summary> Function to determine if the adapter is active or not.</summary>
|
/// <summary> Function to determine if the adapter is active or not.</summary>
|
||||||
/// <remarks>The function is used to check if the adapter associated with iAdapterIndex is active</remarks>
|
/// <remarks>The function is used to check if the adapter associated with iAdapterIndex is active</remarks>
|
||||||
@@ -477,7 +498,7 @@ public class Adl2 {
|
|||||||
/// <param name="status"> Status of the adapter. True: Active; False: Dsiabled</param>
|
/// <param name="status"> Status of the adapter. True: Active; False: Dsiabled</param>
|
||||||
/// <returns>Non zero is successfull</returns>
|
/// <returns>Non zero is successfull</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[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);
|
||||||
|
|
||||||
/// <summary>Get display information based on adapter index</summary>
|
/// <summary>Get display information based on adapter index</summary>
|
||||||
/// <param name="adapterIndex">Adapter Index</param>
|
/// <param name="adapterIndex">Adapter Index</param>
|
||||||
@@ -487,16 +508,16 @@ public class Adl2 {
|
|||||||
/// <returns>return ADL Error Code</returns>
|
/// <returns>return ADL Error Code</returns>
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_Display_DisplayInfo_Get(
|
public static extern int ADL2_Display_DisplayInfo_Get(
|
||||||
IntPtr adlContextHandle,
|
nint adlContextHandle,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
out int numDisplays,
|
out int numDisplays,
|
||||||
out IntPtr displayInfoArray,
|
out nint displayInfoArray,
|
||||||
int forceDetect
|
int forceDetect
|
||||||
);
|
);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_Overdrive_Caps(
|
public static extern int ADL2_Overdrive_Caps(
|
||||||
IntPtr adlContextHandle,
|
nint adlContextHandle,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
out int supported,
|
out int supported,
|
||||||
out int enabled,
|
out int enabled,
|
||||||
@@ -504,21 +525,21 @@ public class Adl2 {
|
|||||||
);
|
);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[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)]
|
[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)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_SwitchableGraphics_Applications_Get(
|
public static extern int ADL2_SwitchableGraphics_Applications_Get(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int iListType,
|
int iListType,
|
||||||
out int lpNumApps,
|
out int lpNumApps,
|
||||||
out IntPtr lppAppList);
|
out nint lppAppList);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_Adapter_VariBright_Caps(
|
public static extern int ADL2_Adapter_VariBright_Caps(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int iAdapterIndex,
|
int iAdapterIndex,
|
||||||
out int iSupported,
|
out int iSupported,
|
||||||
out int iEnabled,
|
out int iEnabled,
|
||||||
@@ -526,7 +547,7 @@ public class Adl2 {
|
|||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_Adapter_VariBrightEnable_Set(
|
public static extern int ADL2_Adapter_VariBrightEnable_Set(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int iAdapterIndex,
|
int iAdapterIndex,
|
||||||
int iEnabled);
|
int iEnabled);
|
||||||
|
|
||||||
@@ -553,25 +574,25 @@ public class Adl2 {
|
|||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_OverdriveN_SystemClocks_Get(
|
public static extern int ADL2_OverdriveN_SystemClocks_Get(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
ref ADLODNPerformanceLevels performanceLevels);
|
ref ADLODNPerformanceLevels performanceLevels);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_OverdriveN_SystemClocks_Set(
|
public static extern int ADL2_OverdriveN_SystemClocks_Set(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
ref ADLODNPerformanceLevels performanceLevels);
|
ref ADLODNPerformanceLevels performanceLevels);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_OverdriveN_MemoryClocks_Get(
|
public static extern int ADL2_OverdriveN_MemoryClocks_Get(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
ref ADLODNPerformanceLevels performanceLevels);
|
ref ADLODNPerformanceLevels performanceLevels);
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
public static extern int ADL2_OverdriveN_MemoryClocks_Set(
|
public static extern int ADL2_OverdriveN_MemoryClocks_Set(
|
||||||
IntPtr context,
|
nint context,
|
||||||
int adapterIndex,
|
int adapterIndex,
|
||||||
ref ADLODNPerformanceLevels performanceLevels);
|
ref ADLODNPerformanceLevels performanceLevels);
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
using AmdAdl2;
|
using GHelper.Helpers;
|
||||||
using System.Runtime.InteropServices;
|
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
|
// Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs
|
||||||
public class AmdGpuControl : IGpuControl
|
public class AmdGpuControl : IGpuControl
|
||||||
{
|
{
|
||||||
private bool _isReady;
|
private bool _isReady;
|
||||||
private IntPtr _adlContextHandle;
|
private nint _adlContextHandle;
|
||||||
private readonly ADLAdapterInfo _internalDiscreteAdapter;
|
private readonly ADLAdapterInfo _internalDiscreteAdapter;
|
||||||
|
|
||||||
public bool IsNvidia => false;
|
public bool IsNvidia => false;
|
||||||
@@ -23,7 +23,7 @@ public class AmdGpuControl : IGpuControl
|
|||||||
|
|
||||||
ADLAdapterInfoArray osAdapterInfoData = new();
|
ADLAdapterInfoArray osAdapterInfoData = new();
|
||||||
int osAdapterInfoDataSize = Marshal.SizeOf(osAdapterInfoData);
|
int osAdapterInfoDataSize = Marshal.SizeOf(osAdapterInfoData);
|
||||||
IntPtr AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
|
nint AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
|
||||||
Marshal.StructureToPtr(osAdapterInfoData, AdapterBuffer, false);
|
Marshal.StructureToPtr(osAdapterInfoData, AdapterBuffer, false);
|
||||||
if (ADL2_Adapter_AdapterInfo_Get(_adlContextHandle, AdapterBuffer, osAdapterInfoDataSize) != Adl2.ADL_SUCCESS)
|
if (ADL2_Adapter_AdapterInfo_Get(_adlContextHandle, AdapterBuffer, osAdapterInfoDataSize) != Adl2.ADL_SUCCESS)
|
||||||
return null;
|
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()
|
public int? GetCurrentTemperature()
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ public class AmdGpuControl : IGpuControl
|
|||||||
|
|
||||||
public bool SetVariBright(int enabled)
|
public bool SetVariBright(int enabled)
|
||||||
{
|
{
|
||||||
if (_adlContextHandle == IntPtr.Zero) return false;
|
if (_adlContextHandle == nint.Zero) return false;
|
||||||
|
|
||||||
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
|
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
|
||||||
if (iGPU is null) return false;
|
if (iGPU is null) return false;
|
||||||
@@ -125,7 +125,7 @@ public class AmdGpuControl : IGpuControl
|
|||||||
{
|
{
|
||||||
supported = enabled = -1;
|
supported = enabled = -1;
|
||||||
|
|
||||||
if (_adlContextHandle == IntPtr.Zero) return false;
|
if (_adlContextHandle == nint.Zero) return false;
|
||||||
|
|
||||||
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
|
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
|
||||||
if (iGPU is null) return false;
|
if (iGPU is null) return false;
|
||||||
@@ -154,7 +154,7 @@ public class AmdGpuControl : IGpuControl
|
|||||||
|
|
||||||
if (!IsValid) return;
|
if (!IsValid) return;
|
||||||
|
|
||||||
IntPtr appInfoPtr = IntPtr.Zero;
|
nint appInfoPtr = nint.Zero;
|
||||||
int appCount = 0;
|
int appCount = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -168,12 +168,12 @@ public class AmdGpuControl : IGpuControl
|
|||||||
|
|
||||||
// Convert the application data pointers to an array of structs
|
// Convert the application data pointers to an array of structs
|
||||||
var appInfoArray = new ADLSGApplicationInfo[appCount];
|
var appInfoArray = new ADLSGApplicationInfo[appCount];
|
||||||
IntPtr currentPtr = appInfoPtr;
|
nint currentPtr = appInfoPtr;
|
||||||
|
|
||||||
for (int i = 0; i < appCount; i++)
|
for (int i = 0; i < appCount; i++)
|
||||||
{
|
{
|
||||||
appInfoArray[i] = Marshal.PtrToStructure<ADLSGApplicationInfo>(currentPtr);
|
appInfoArray[i] = Marshal.PtrToStructure<ADLSGApplicationInfo>(currentPtr);
|
||||||
currentPtr = IntPtr.Add(currentPtr, Marshal.SizeOf<ADLSGApplicationInfo>());
|
currentPtr = nint.Add(currentPtr, Marshal.SizeOf<ADLSGApplicationInfo>());
|
||||||
}
|
}
|
||||||
|
|
||||||
var appNames = new List<string>();
|
var appNames = new List<string>();
|
||||||
@@ -202,7 +202,7 @@ public class AmdGpuControl : IGpuControl
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// Clean up resources
|
// Clean up resources
|
||||||
if (appInfoPtr != IntPtr.Zero)
|
if (appInfoPtr != nint.Zero)
|
||||||
{
|
{
|
||||||
Marshal.FreeCoTaskMem(appInfoPtr);
|
Marshal.FreeCoTaskMem(appInfoPtr);
|
||||||
}
|
}
|
||||||
@@ -213,10 +213,10 @@ public class AmdGpuControl : IGpuControl
|
|||||||
|
|
||||||
private void ReleaseUnmanagedResources()
|
private void ReleaseUnmanagedResources()
|
||||||
{
|
{
|
||||||
if (_adlContextHandle != IntPtr.Zero)
|
if (_adlContextHandle != nint.Zero)
|
||||||
{
|
{
|
||||||
ADL2_Main_Control_Destroy(_adlContextHandle);
|
ADL2_Main_Control_Destroy(_adlContextHandle);
|
||||||
_adlContextHandle = IntPtr.Zero;
|
_adlContextHandle = nint.Zero;
|
||||||
_isReady = false;
|
_isReady = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
316
app/Gpu/GPUModeControl.cs
Normal file
316
app/Gpu/GPUModeControl.cs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using NvAPIWrapper.GPU;
|
using GHelper.Helpers;
|
||||||
|
using NvAPIWrapper.GPU;
|
||||||
using NvAPIWrapper.Native;
|
using NvAPIWrapper.Native;
|
||||||
using NvAPIWrapper.Native.GPU;
|
using NvAPIWrapper.Native.GPU;
|
||||||
using NvAPIWrapper.Native.GPU.Structures;
|
using NvAPIWrapper.Native.GPU.Structures;
|
||||||
@@ -6,7 +7,7 @@ using NvAPIWrapper.Native.Interfaces.GPU;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
|
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
|
||||||
|
|
||||||
namespace GHelper.Gpu;
|
namespace GHelper.Gpu.NVidia;
|
||||||
|
|
||||||
public class NvidiaGpuControl : IGpuControl
|
public class NvidiaGpuControl : IGpuControl
|
||||||
{
|
{
|
||||||
@@ -126,8 +127,8 @@ public class NvidiaGpuControl : IGpuControl
|
|||||||
|
|
||||||
public int SetClocksFromConfig()
|
public int SetClocksFromConfig()
|
||||||
{
|
{
|
||||||
int core = AppConfig.Get("gpu_core",0);
|
int core = AppConfig.Get("gpu_core", 0);
|
||||||
int memory = AppConfig.Get("gpu_memory",0);
|
int memory = AppConfig.Get("gpu_memory", 0);
|
||||||
int status = SetClocks(core, memory);
|
int status = SetClocks(core, memory);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -145,7 +146,7 @@ public class NvidiaGpuControl : IGpuControl
|
|||||||
var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage));
|
var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage));
|
||||||
|
|
||||||
PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock };
|
PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock };
|
||||||
PerformanceStates20BaseVoltageEntryV1[] voltages = { };
|
PerformanceStates20BaseVoltageEntryV1[] voltages = { };
|
||||||
|
|
||||||
PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) };
|
PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) };
|
||||||
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
using GHelper;
|
using GHelper;
|
||||||
using GHelper.Gpu;
|
using GHelper.Gpu;
|
||||||
|
using GHelper.Gpu.NVidia;
|
||||||
|
using GHelper.Gpu.AMD;
|
||||||
|
|
||||||
|
using GHelper.Helpers;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
public static class HardwareControl
|
public static class HardwareControl
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OSD
|
namespace GHelper.Helpers
|
||||||
{
|
{
|
||||||
|
|
||||||
public class OSDNativeForm : NativeWindow, IDisposable
|
public class OSDNativeForm : NativeWindow, IDisposable
|
||||||
@@ -19,11 +19,11 @@ namespace OSD
|
|||||||
|
|
||||||
protected internal void Invalidate()
|
protected internal void Invalidate()
|
||||||
{
|
{
|
||||||
this.UpdateLayeredWindow();
|
UpdateLayeredWindow();
|
||||||
}
|
}
|
||||||
private void 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))
|
using (Graphics graphics1 = Graphics.FromImage(bitmap1))
|
||||||
{
|
{
|
||||||
Rectangle rectangle1;
|
Rectangle rectangle1;
|
||||||
@@ -31,27 +31,27 @@ namespace OSD
|
|||||||
POINT point1;
|
POINT point1;
|
||||||
POINT point2;
|
POINT point2;
|
||||||
BLENDFUNCTION blendfunction1;
|
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));
|
PerformPaint(new PaintEventArgs(graphics1, rectangle1));
|
||||||
IntPtr ptr1 = User32.GetDC(IntPtr.Zero);
|
nint ptr1 = User32.GetDC(nint.Zero);
|
||||||
IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1);
|
nint ptr2 = Gdi32.CreateCompatibleDC(ptr1);
|
||||||
IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
|
nint ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
|
||||||
IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3);
|
nint ptr4 = Gdi32.SelectObject(ptr2, ptr3);
|
||||||
size1.cx = this.Size.Width;
|
size1.cx = Size.Width;
|
||||||
size1.cy = this.Size.Height;
|
size1.cy = Size.Height;
|
||||||
point1.x = this.Location.X;
|
point1.x = Location.X;
|
||||||
point1.x = this.Location.X;
|
point1.x = Location.X;
|
||||||
point1.y = this.Location.Y;
|
point1.y = Location.Y;
|
||||||
point2.x = 0;
|
point2.x = 0;
|
||||||
point2.y = 0;
|
point2.y = 0;
|
||||||
blendfunction1 = new BLENDFUNCTION();
|
blendfunction1 = new BLENDFUNCTION();
|
||||||
blendfunction1.BlendOp = 0;
|
blendfunction1.BlendOp = 0;
|
||||||
blendfunction1.BlendFlags = 0;
|
blendfunction1.BlendFlags = 0;
|
||||||
blendfunction1.SourceConstantAlpha = this._alpha;
|
blendfunction1.SourceConstantAlpha = _alpha;
|
||||||
blendfunction1.AlphaFormat = 1;
|
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);
|
Gdi32.SelectObject(ptr2, ptr4);
|
||||||
User32.ReleaseDC(IntPtr.Zero, ptr1);
|
User32.ReleaseDC(nint.Zero, ptr1);
|
||||||
Gdi32.DeleteObject(ptr3);
|
Gdi32.DeleteObject(ptr3);
|
||||||
Gdi32.DeleteDC(ptr2);
|
Gdi32.DeleteDC(ptr2);
|
||||||
}
|
}
|
||||||
@@ -59,25 +59,25 @@ namespace OSD
|
|||||||
|
|
||||||
public virtual void Show()
|
public virtual void Show()
|
||||||
{
|
{
|
||||||
if (base.Handle == IntPtr.Zero) //if handle don't equal to zero - window was created and just hided
|
if (Handle == nint.Zero) //if handle don't equal to zero - window was created and just hided
|
||||||
this.CreateWindowOnly();
|
CreateWindowOnly();
|
||||||
User32.ShowWindow(base.Handle, User32.SW_SHOWNOACTIVATE);
|
User32.ShowWindow(Handle, User32.SW_SHOWNOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void Hide()
|
public virtual void Hide()
|
||||||
{
|
{
|
||||||
if (base.Handle == IntPtr.Zero)
|
if (Handle == nint.Zero)
|
||||||
return;
|
return;
|
||||||
User32.ShowWindow(base.Handle, User32.SW_HIDE);
|
User32.ShowWindow(Handle, User32.SW_HIDE);
|
||||||
this.DestroyHandle();
|
DestroyHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void Close()
|
public virtual void Close()
|
||||||
{
|
{
|
||||||
this.Hide();
|
Hide();
|
||||||
this.Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWindowOnly()
|
private void CreateWindowOnly()
|
||||||
@@ -85,55 +85,55 @@ namespace OSD
|
|||||||
|
|
||||||
CreateParams params1 = new CreateParams();
|
CreateParams params1 = new CreateParams();
|
||||||
params1.Caption = "FloatingNativeWindow";
|
params1.Caption = "FloatingNativeWindow";
|
||||||
int nX = this._location.X;
|
int nX = _location.X;
|
||||||
int nY = this._location.Y;
|
int nY = _location.Y;
|
||||||
Screen screen1 = Screen.FromHandle(base.Handle);
|
Screen screen1 = Screen.FromHandle(Handle);
|
||||||
if ((nX + this._size.Width) > screen1.Bounds.Width)
|
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);
|
_location = new Point(nX, nY);
|
||||||
Size size1 = this._size;
|
Size size1 = _size;
|
||||||
Point point1 = this._location;
|
Point point1 = _location;
|
||||||
params1.X = nX;
|
params1.X = nX;
|
||||||
params1.Y = nY;
|
params1.Y = nY;
|
||||||
params1.Height = size1.Height;
|
params1.Height = size1.Height;
|
||||||
params1.Width = size1.Width;
|
params1.Width = size1.Width;
|
||||||
params1.Parent = IntPtr.Zero;
|
params1.Parent = nint.Zero;
|
||||||
uint ui = User32.WS_POPUP;
|
uint ui = User32.WS_POPUP;
|
||||||
params1.Style = (int)ui;
|
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;
|
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);
|
CreateHandle(params1);
|
||||||
this.UpdateLayeredWindow();
|
UpdateLayeredWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected virtual void SetBoundsCore(int x, int y, int width, int height)
|
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;
|
int num1 = 20;
|
||||||
if ((this.X == x) && (this.Y == y))
|
if (X == x && Y == y)
|
||||||
{
|
{
|
||||||
num1 |= 2;
|
num1 |= 2;
|
||||||
}
|
}
|
||||||
if ((this.Width == width) && (this.Height == height))
|
if (Width == width && Height == height)
|
||||||
{
|
{
|
||||||
num1 |= 1;
|
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
|
else
|
||||||
{
|
{
|
||||||
this.Location = new Point(x, y);
|
Location = new Point(x, y);
|
||||||
this.Size = new Size(width, height);
|
Size = new Size(width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,20 +147,20 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Point Location
|
public virtual Point Location
|
||||||
{
|
{
|
||||||
get { return this._location; }
|
get { return _location; }
|
||||||
set
|
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();
|
RECT rect = new RECT();
|
||||||
User32.GetWindowRect(base.Handle, ref rect);
|
User32.GetWindowRect(Handle, ref rect);
|
||||||
this._location = new Point(rect.left, rect.top);
|
_location = new Point(rect.left, rect.top);
|
||||||
this.UpdateLayeredWindow();
|
UpdateLayeredWindow();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._location = value;
|
_location = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,20 +169,20 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Size Size
|
public virtual Size Size
|
||||||
{
|
{
|
||||||
get { return this._size; }
|
get { return _size; }
|
||||||
set
|
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();
|
RECT rect = new RECT();
|
||||||
User32.GetWindowRect(base.Handle, ref rect);
|
User32.GetWindowRect(Handle, ref rect);
|
||||||
this._size = new Size(rect.right - rect.left, rect.bottom - rect.top);
|
_size = new Size(rect.right - rect.left, rect.bottom - rect.top);
|
||||||
this.UpdateLayeredWindow();
|
UpdateLayeredWindow();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._size = value;
|
_size = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,10 +191,10 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Height
|
public int Height
|
||||||
{
|
{
|
||||||
get { return this._size.Height; }
|
get { return _size.Height; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this._size = new Size(this._size.Width, value);
|
_size = new Size(_size.Width, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -202,10 +202,10 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Width
|
public int Width
|
||||||
{
|
{
|
||||||
get { return this._size.Width; }
|
get { return _size.Width; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this._size = new Size(value, this._size.Height);
|
_size = new Size(value, _size.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -213,10 +213,10 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
get { return this._location.X; }
|
get { return _location.X; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.Location = new Point(value, this.Location.Y);
|
Location = new Point(value, Location.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -224,10 +224,10 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Y
|
public int Y
|
||||||
{
|
{
|
||||||
get { return this._location.Y; }
|
get { return _location.Y; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.Location = new Point(this.Location.X, value);
|
Location = new Point(Location.X, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -237,7 +237,7 @@ namespace OSD
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Rectangle(new Point(0, 0), this._size);
|
return new Rectangle(new Point(0, 0), _size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -245,12 +245,12 @@ namespace OSD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public byte Alpha
|
public byte Alpha
|
||||||
{
|
{
|
||||||
get { return this._alpha; }
|
get { return _alpha; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (this._alpha == value) return;
|
if (_alpha == value) return;
|
||||||
this._alpha = value;
|
_alpha = value;
|
||||||
this.UpdateLayeredWindow();
|
UpdateLayeredWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -258,15 +258,15 @@ namespace OSD
|
|||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
this.Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!this._disposed)
|
if (!_disposed)
|
||||||
{
|
{
|
||||||
this.DestroyHandle();
|
DestroyHandle();
|
||||||
this._disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -299,16 +299,16 @@ namespace OSD
|
|||||||
{
|
{
|
||||||
public uint cbSize;
|
public uint cbSize;
|
||||||
public uint dwFlags;
|
public uint dwFlags;
|
||||||
public IntPtr hWnd;
|
public nint hWnd;
|
||||||
public uint dwHoverTime;
|
public uint dwHoverTime;
|
||||||
}
|
}
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal struct MSG
|
internal struct MSG
|
||||||
{
|
{
|
||||||
public IntPtr hwnd;
|
public nint hwnd;
|
||||||
public int message;
|
public int message;
|
||||||
public IntPtr wParam;
|
public nint wParam;
|
||||||
public IntPtr lParam;
|
public nint lParam;
|
||||||
public int time;
|
public int time;
|
||||||
public int pt_x;
|
public int pt_x;
|
||||||
public int pt_y;
|
public int pt_y;
|
||||||
@@ -345,69 +345,69 @@ namespace OSD
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool DispatchMessage(ref MSG msg);
|
internal static extern bool DispatchMessage(ref MSG msg);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern IntPtr GetFocus();
|
internal static extern nint GetFocus();
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern ushort GetKeyState(int virtKey);
|
internal static extern ushort GetKeyState(int virtKey);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
|
internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
|
internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool ReleaseCapture();
|
internal static extern bool ReleaseCapture();
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
|
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
@@ -415,9 +415,9 @@ namespace OSD
|
|||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool TranslateMessage(ref MSG msg);
|
internal static extern bool TranslateMessage(ref MSG msg);
|
||||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||||
internal static extern bool WaitMessage();
|
internal static extern bool WaitMessage();
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||||
@@ -431,25 +431,25 @@ namespace OSD
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct LOGBRUSH
|
public struct LOGBRUSH
|
||||||
@@ -3,7 +3,7 @@ using System.Diagnostics;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper.Helpers
|
||||||
{
|
{
|
||||||
public static class OptimizationService
|
public static class OptimizationService
|
||||||
{
|
{
|
||||||
@@ -52,7 +52,7 @@ namespace GHelper
|
|||||||
|
|
||||||
public static bool IsRunning()
|
public static bool IsRunning()
|
||||||
{
|
{
|
||||||
return (Process.GetProcessesByName("AsusOptimization").Count() > 0);
|
return Process.GetProcessesByName("AsusOptimization").Count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetRunningCount()
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@ using System.Security.Principal;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper.Helpers
|
||||||
{
|
{
|
||||||
public static class ProcessHelper
|
public static class ProcessHelper
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,8 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
Process.Start(startInfo);
|
Process.Start(startInfo);
|
||||||
Application.Exit();
|
Application.Exit();
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WriteLine(ex.Message);
|
Logger.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace GHelper
|
namespace GHelper.Helpers
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using GHelper;
|
using GHelper.Helpers;
|
||||||
using Microsoft.Win32.TaskScheduler;
|
using Microsoft.Win32.TaskScheduler;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using OSD;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper.Helpers
|
||||||
{
|
{
|
||||||
|
|
||||||
static class Drawing
|
static class Drawing
|
||||||
@@ -74,7 +73,7 @@ namespace GHelper
|
|||||||
protected override void PerformPaint(PaintEventArgs e)
|
protected override void PerformPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black));
|
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();
|
StringFormat format = new StringFormat();
|
||||||
format.LineAlignment = StringAlignment.Center;
|
format.LineAlignment = StringAlignment.Center;
|
||||||
@@ -128,34 +127,37 @@ namespace GHelper
|
|||||||
e.Graphics.DrawString(toastText,
|
e.Graphics.DrawString(toastText,
|
||||||
new Font("Segoe UI", 36f, FontStyle.Bold, GraphicsUnit.Pixel),
|
new Font("Segoe UI", 36f, FontStyle.Bold, GraphicsUnit.Pixel),
|
||||||
new SolidBrush(Color.White),
|
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);
|
format);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RunToast(string text, ToastIcon? icon = null)
|
public void RunToast(string text, ToastIcon? icon = null)
|
||||||
{
|
{
|
||||||
//Hide();
|
Program.settingsForm.Invoke(delegate
|
||||||
timer.Stop();
|
{
|
||||||
|
//Hide();
|
||||||
|
timer.Stop();
|
||||||
|
|
||||||
toastText = text;
|
toastText = text;
|
||||||
toastIcon = icon;
|
toastIcon = icon;
|
||||||
|
|
||||||
Screen screen1 = Screen.FromHandle(base.Handle);
|
Screen screen1 = Screen.FromHandle(Handle);
|
||||||
|
|
||||||
Width = Math.Max(300, 100 + toastText.Length * 22);
|
Width = Math.Max(300, 100 + toastText.Length * 22);
|
||||||
Height = 100;
|
Height = 100;
|
||||||
X = (screen1.Bounds.Width - this.Width) / 2;
|
X = (screen1.Bounds.Width - Width) / 2;
|
||||||
Y = screen1.Bounds.Height - 300 - this.Height;
|
Y = screen1.Bounds.Height - 300 - Height;
|
||||||
|
|
||||||
|
Show();
|
||||||
|
timer.Start();
|
||||||
|
});
|
||||||
|
|
||||||
Show();
|
|
||||||
timer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timer_Tick(object? sender, EventArgs e)
|
private void timer_Tick(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Toast end");
|
//Debug.WriteLine("Toast end");
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
using GHelper.Mode;
|
using GHelper.Helpers;
|
||||||
|
using GHelper.Mode;
|
||||||
using HidLibrary;
|
using HidLibrary;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using NAudio.CoreAudioApi;
|
using NAudio.CoreAudioApi;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper.Input
|
||||||
{
|
{
|
||||||
public class KeyboardListener
|
public class KeyboardListener
|
||||||
{
|
{
|
||||||
@@ -27,7 +28,7 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Emergency break
|
// Emergency break
|
||||||
if (input == null || !input.IsConnected )
|
if (input == null || !input.IsConnected)
|
||||||
{
|
{
|
||||||
Logger.WriteLine("Listener terminated");
|
Logger.WriteLine("Listener terminated");
|
||||||
break;
|
break;
|
||||||
@@ -69,6 +70,7 @@ namespace GHelper
|
|||||||
public static Keys keyApp = Keys.F12;
|
public static Keys keyApp = Keys.F12;
|
||||||
|
|
||||||
static ModeControl modeControl = new ModeControl();
|
static ModeControl modeControl = new ModeControl();
|
||||||
|
static ToastForm toast = new ToastForm();
|
||||||
|
|
||||||
KeyboardListener listener;
|
KeyboardListener listener;
|
||||||
KeyboardHook hook = new KeyboardHook();
|
KeyboardHook hook = new KeyboardHook();
|
||||||
@@ -135,8 +137,8 @@ namespace GHelper
|
|||||||
|
|
||||||
public void InitBacklightTimer()
|
public void InitBacklightTimer()
|
||||||
{
|
{
|
||||||
timer.Enabled = (AppConfig.Get("keyboard_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);
|
AppConfig.Get("keyboard_ac_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +159,7 @@ namespace GHelper
|
|||||||
|
|
||||||
if (!AppConfig.ContainsModel("Z13"))
|
if (!AppConfig.ContainsModel("Z13"))
|
||||||
if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown);
|
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
|
// FN-Lock group
|
||||||
|
|
||||||
@@ -253,12 +255,12 @@ namespace GHelper
|
|||||||
break;
|
break;
|
||||||
case Keys.F7:
|
case Keys.F7:
|
||||||
if (AppConfig.ContainsModel("TUF"))
|
if (AppConfig.ContainsModel("TUF"))
|
||||||
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
|
toast.RunToast(ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
|
||||||
HandleOptimizationEvent(16);
|
HandleOptimizationEvent(16);
|
||||||
break;
|
break;
|
||||||
case Keys.F8:
|
case Keys.F8:
|
||||||
if (AppConfig.ContainsModel("TUF"))
|
if (AppConfig.ContainsModel("TUF"))
|
||||||
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
|
toast.RunToast(ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
|
||||||
HandleOptimizationEvent(32);
|
HandleOptimizationEvent(32);
|
||||||
break;
|
break;
|
||||||
case Keys.F9:
|
case Keys.F9:
|
||||||
@@ -334,7 +336,7 @@ namespace GHelper
|
|||||||
Program.settingsForm.BeginInvoke(Program.settingsForm.CycleAuraMode);
|
Program.settingsForm.BeginInvoke(Program.settingsForm.CycleAuraMode);
|
||||||
break;
|
break;
|
||||||
case "performance":
|
case "performance":
|
||||||
Program.settingsForm.BeginInvoke(modeControl.CyclePerformanceMode);
|
modeControl.CyclePerformanceMode();
|
||||||
break;
|
break;
|
||||||
case "ghelper":
|
case "ghelper":
|
||||||
Program.settingsForm.BeginInvoke(delegate
|
Program.settingsForm.BeginInvoke(delegate
|
||||||
@@ -351,7 +353,7 @@ namespace GHelper
|
|||||||
var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
|
var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
|
||||||
bool muteStatus = !commDevice.AudioEndpointVolume.Mute;
|
bool muteStatus = !commDevice.AudioEndpointVolume.Mute;
|
||||||
commDevice.AudioEndpointVolume.Mute = muteStatus;
|
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;
|
break;
|
||||||
case "brightness_up":
|
case "brightness_up":
|
||||||
@@ -373,7 +375,7 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PrecisionTouchPad\Status", false))
|
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);
|
AppConfig.Set("fn_lock", fnLock);
|
||||||
|
|
||||||
if (AppConfig.ContainsModel("VivoBook"))
|
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
|
else
|
||||||
Program.settingsForm.BeginInvoke(Program.inputDispatcher.RegisterKeys);
|
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()
|
public static void TabletMode()
|
||||||
@@ -397,7 +399,7 @@ namespace GHelper
|
|||||||
|
|
||||||
Logger.WriteLine("Tablet: " + tabletState + " Touchpad: " + touchpadState);
|
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");
|
KeyProcess("m4");
|
||||||
return;
|
return;
|
||||||
case 174: // FN+F5
|
case 174: // FN+F5
|
||||||
Program.settingsForm.BeginInvoke(modeControl.CyclePerformanceMode);
|
modeControl.CyclePerformanceMode();
|
||||||
return;
|
return;
|
||||||
case 179: // FN+F4
|
case 179: // FN+F4
|
||||||
case 178: // FN+F4
|
case 178: // FN+F4
|
||||||
@@ -463,7 +465,7 @@ namespace GHelper
|
|||||||
case 107: // FN+F10
|
case 107: // FN+F10
|
||||||
bool touchpadState = GetTouchpadState();
|
bool touchpadState = GetTouchpadState();
|
||||||
AsusUSB.TouchpadToggle();
|
AsusUSB.TouchpadToggle();
|
||||||
Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, touchpadState ? "Off" : "On", ToastIcon.Touchpad);
|
toast.RunToast(touchpadState ? "Off" : "On", ToastIcon.Touchpad);
|
||||||
break;
|
break;
|
||||||
case 108: // FN+F11
|
case 108: // FN+F11
|
||||||
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.KB_Sleep, "Sleep");
|
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.KB_Sleep, "Sleep");
|
||||||
@@ -503,7 +505,7 @@ namespace GHelper
|
|||||||
int backlight = onBattery ? backlight_battery : backlight_power;
|
int backlight = onBattery ? backlight_battery : backlight_power;
|
||||||
|
|
||||||
if (delta >= 4)
|
if (delta >= 4)
|
||||||
backlight = (++backlight % 4);
|
backlight = ++backlight % 4;
|
||||||
else
|
else
|
||||||
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
|
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
|
||||||
|
|
||||||
@@ -516,7 +518,7 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
AsusUSB.ApplyBrightness(backlight, "HotKey");
|
AsusUSB.ApplyBrightness(backlight, "HotKey");
|
||||||
string[] backlightNames = new string[] { "Off", "Low", "Mid", "Max" };
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using GHelper.Gpu;
|
using GHelper.Gpu.NVidia;
|
||||||
|
using GHelper.Helpers;
|
||||||
using Ryzen;
|
using Ryzen;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace GHelper.Mode
|
namespace GHelper.Mode
|
||||||
{
|
{
|
||||||
@@ -8,6 +8,7 @@ namespace GHelper.Mode
|
|||||||
{
|
{
|
||||||
|
|
||||||
static SettingsForm settings = Program.settingsForm;
|
static SettingsForm settings = Program.settingsForm;
|
||||||
|
static ToastForm toast = new ToastForm();
|
||||||
|
|
||||||
private static bool customFans = false;
|
private static bool customFans = false;
|
||||||
private static int customPower = 0;
|
private static int customPower = 0;
|
||||||
@@ -32,30 +33,20 @@ namespace GHelper.Mode
|
|||||||
|
|
||||||
if (!Modes.Exists(mode)) mode = 0;
|
if (!Modes.Exists(mode)) mode = 0;
|
||||||
|
|
||||||
|
customFans = false;
|
||||||
|
customPower = 0;
|
||||||
|
|
||||||
settings.ShowMode(mode);
|
settings.ShowMode(mode);
|
||||||
|
SetModeLabel();
|
||||||
|
|
||||||
Modes.SetCurrent(mode);
|
Modes.SetCurrent(mode);
|
||||||
|
|
||||||
SetModeLabel();
|
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, IsManualModeRequired() ? AsusACPI.PerformanceManual : Modes.GetBase(mode), "Mode");
|
||||||
|
|
||||||
if (IsManualModeRequired())
|
|
||||||
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, AsusACPI.PerformanceManual, "Manual Mode");
|
|
||||||
else
|
|
||||||
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetBase(mode), "Mode");
|
|
||||||
|
|
||||||
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM();
|
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM();
|
||||||
|
|
||||||
if (notify)
|
if (notify)
|
||||||
{
|
toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
|
||||||
try
|
|
||||||
{
|
|
||||||
settings.toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Debug.WriteLine("Toast error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SetGPUClocks();
|
SetGPUClocks();
|
||||||
AutoFans();
|
AutoFans();
|
||||||
@@ -74,15 +65,14 @@ namespace GHelper.Mode
|
|||||||
NativeMethods.SetCPUBoost(AppConfig.GetMode("auto_boost"));
|
NativeMethods.SetCPUBoost(AppConfig.GetMode("auto_boost"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (NativeMethods.PowerGetEffectiveOverlayScheme(out Guid activeScheme) == 0)
|
if (NativeMethods.PowerGetEffectiveOverlayScheme(out Guid activeScheme) == 0)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Effective :" + activeScheme);
|
Debug.WriteLine("Effective :" + activeScheme);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (settings.fans != null && settings.fans.Text != "")
|
settings.FansInit();
|
||||||
{
|
|
||||||
settings.fans.InitAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +98,6 @@ namespace GHelper.Mode
|
|||||||
int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
|
int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
|
||||||
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
|
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
|
||||||
|
|
||||||
|
|
||||||
if (AppConfig.Is("mid_fan"))
|
if (AppConfig.Is("mid_fan"))
|
||||||
Program.acpi.SetFanCurve(AsusFan.Mid, AppConfig.GetFanConfig(AsusFan.Mid));
|
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 (gpu_temp < AsusACPI.MinGPUTemp || gpu_temp > AsusACPI.MaxGPUTemp) return;
|
||||||
|
|
||||||
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0)
|
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0)
|
||||||
{
|
|
||||||
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0");
|
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0");
|
||||||
}
|
|
||||||
|
|
||||||
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0)
|
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0)
|
||||||
{
|
|
||||||
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2");
|
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2");
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Microsoft.VisualBasic.Devices;
|
namespace GHelper.Mode
|
||||||
|
|
||||||
namespace GHelper
|
|
||||||
{
|
{
|
||||||
internal class Modes
|
internal class Modes
|
||||||
{
|
{
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using GHelper.Gpu;
|
||||||
|
using GHelper.Helpers;
|
||||||
|
using GHelper.Input;
|
||||||
using GHelper.Mode;
|
using GHelper.Mode;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using Ryzen;
|
using Ryzen;
|
||||||
@@ -22,13 +25,14 @@ namespace GHelper
|
|||||||
|
|
||||||
public static SettingsForm settingsForm = new SettingsForm();
|
public static SettingsForm settingsForm = new SettingsForm();
|
||||||
public static ModeControl modeControl = new ModeControl();
|
public static ModeControl modeControl = new ModeControl();
|
||||||
|
public static GPUModeControl gpuControl = new GPUModeControl();
|
||||||
|
|
||||||
public static IntPtr unRegPowerNotify;
|
public static IntPtr unRegPowerNotify;
|
||||||
|
|
||||||
private static long lastAuto;
|
private static long lastAuto;
|
||||||
private static long lastTheme;
|
private static long lastTheme;
|
||||||
|
|
||||||
public static InputDispatcher inputDispatcher;
|
public static InputDispatcher? inputDispatcher;
|
||||||
|
|
||||||
private static PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
private static PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
||||||
|
|
||||||
@@ -50,8 +54,6 @@ namespace GHelper
|
|||||||
Thread.CurrentThread.CurrentUICulture = culture;
|
Thread.CurrentThread.CurrentUICulture = culture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
|
||||||
|
|
||||||
ProcessHelper.CheckAlreadyRunning();
|
ProcessHelper.CheckAlreadyRunning();
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -78,15 +80,12 @@ namespace GHelper
|
|||||||
HardwareControl.RecreateGpuControl();
|
HardwareControl.RecreateGpuControl();
|
||||||
RyzenControl.Init();
|
RyzenControl.Init();
|
||||||
|
|
||||||
var ds = settingsForm.Handle;
|
|
||||||
|
|
||||||
trayIcon.MouseClick += TrayIcon_MouseClick;
|
trayIcon.MouseClick += TrayIcon_MouseClick;
|
||||||
|
|
||||||
inputDispatcher = new InputDispatcher();
|
inputDispatcher = new InputDispatcher();
|
||||||
|
|
||||||
settingsForm.InitAura();
|
settingsForm.InitAura();
|
||||||
settingsForm.InitMatrix();
|
settingsForm.InitMatrix();
|
||||||
settingsForm.SetStartupCheck(Startup.IsScheduled());
|
|
||||||
|
|
||||||
|
|
||||||
SetAutoModes();
|
SetAutoModes();
|
||||||
@@ -97,7 +96,7 @@ namespace GHelper
|
|||||||
|
|
||||||
// Subscribing for monitor power on events
|
// Subscribing for monitor power on events
|
||||||
PowerSettingGuid settingGuid = new NativeMethods.PowerSettingGuid();
|
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)
|
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0)
|
||||||
@@ -155,11 +154,11 @@ namespace GHelper
|
|||||||
settingsForm.SetBatteryChargeLimit(AppConfig.Get("charge_limit"));
|
settingsForm.SetBatteryChargeLimit(AppConfig.Get("charge_limit"));
|
||||||
modeControl.AutoPerformance(powerChanged);
|
modeControl.AutoPerformance(powerChanged);
|
||||||
|
|
||||||
bool switched = settingsForm.AutoGPUMode();
|
bool switched = gpuControl.AutoGPUMode();
|
||||||
|
|
||||||
if (!switched)
|
if (!switched)
|
||||||
{
|
{
|
||||||
settingsForm.InitGPUMode();
|
gpuControl.InitGPUMode();
|
||||||
settingsForm.AutoScreen();
|
settingsForm.AutoScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ namespace GHelper
|
|||||||
settingsForm.FansToggle(1);
|
settingsForm.FansToggle(1);
|
||||||
break;
|
break;
|
||||||
case "gpurestart":
|
case "gpurestart":
|
||||||
settingsForm.RestartGPU(false);
|
gpuControl.RestartGPU(false);
|
||||||
break;
|
break;
|
||||||
case "services":
|
case "services":
|
||||||
settingsForm.keyb = new Extra();
|
settingsForm.keyb = new Extra();
|
||||||
@@ -214,7 +213,7 @@ namespace GHelper
|
|||||||
case "uv":
|
case "uv":
|
||||||
Startup.ReScheduleAdmin();
|
Startup.ReScheduleAdmin();
|
||||||
settingsForm.FansToggle(2);
|
settingsForm.FansToggle(2);
|
||||||
//settingsForm.SetUV(); TODO
|
modeControl.SetUV();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,9 +222,7 @@ namespace GHelper
|
|||||||
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
|
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButtons.Left)
|
if (e.Button == MouseButtons.Left)
|
||||||
{
|
|
||||||
SettingsToggle();
|
SettingsToggle();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
app/Settings.Designer.cs
generated
7
app/Settings.Designer.cs
generated
@@ -1,4 +1,4 @@
|
|||||||
using CustomControls;
|
using GHelper.UI;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
@@ -41,7 +41,7 @@ namespace GHelper
|
|||||||
labelMatrix = new Label();
|
labelMatrix = new Label();
|
||||||
checkMatrix = new CheckBox();
|
checkMatrix = new CheckBox();
|
||||||
panelBattery = new Panel();
|
panelBattery = new Panel();
|
||||||
sliderBattery = new WinFormsSliderBar.Slider();
|
sliderBattery = new Slider();
|
||||||
panelBatteryTitle = new Panel();
|
panelBatteryTitle = new Panel();
|
||||||
labelBattery = new Label();
|
labelBattery = new Label();
|
||||||
pictureBattery = new PictureBox();
|
pictureBattery = new PictureBox();
|
||||||
@@ -1169,7 +1169,6 @@ namespace GHelper
|
|||||||
ShowIcon = false;
|
ShowIcon = false;
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "G-Helper";
|
Text = "G-Helper";
|
||||||
Load += Settings_Load;
|
|
||||||
panelMatrix.ResumeLayout(false);
|
panelMatrix.ResumeLayout(false);
|
||||||
panelMatrix.PerformLayout();
|
panelMatrix.PerformLayout();
|
||||||
tableLayoutMatrix.ResumeLayout(false);
|
tableLayoutMatrix.ResumeLayout(false);
|
||||||
@@ -1254,7 +1253,7 @@ namespace GHelper
|
|||||||
private RButton buttonKeyboard;
|
private RButton buttonKeyboard;
|
||||||
private RButton buttonKeyboardColor;
|
private RButton buttonKeyboardColor;
|
||||||
private RButton buttonFans;
|
private RButton buttonFans;
|
||||||
private WinFormsSliderBar.Slider sliderBattery;
|
private Slider sliderBattery;
|
||||||
private RButton buttonUpdates;
|
private RButton buttonUpdates;
|
||||||
private Panel panelGPUTitle;
|
private Panel panelGPUTitle;
|
||||||
private PictureBox pictureGPU;
|
private PictureBox pictureGPU;
|
||||||
|
|||||||
511
app/Settings.cs
511
app/Settings.cs
@@ -1,7 +1,9 @@
|
|||||||
using CustomControls;
|
using GHelper.AnimeMatrix;
|
||||||
using GHelper.AnimeMatrix;
|
|
||||||
using GHelper.Gpu;
|
using GHelper.Gpu;
|
||||||
|
using GHelper.Helpers;
|
||||||
|
using GHelper.Input;
|
||||||
using GHelper.Mode;
|
using GHelper.Mode;
|
||||||
|
using GHelper.UI;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -17,17 +19,12 @@ namespace GHelper
|
|||||||
ContextMenuStrip contextMenuStrip = new CustomContextMenu();
|
ContextMenuStrip contextMenuStrip = new CustomContextMenu();
|
||||||
ToolStripMenuItem menuSilent, menuBalanced, menuTurbo, menuEco, menuStandard, menuUltimate, menuOptimized;
|
ToolStripMenuItem menuSilent, menuBalanced, menuTurbo, menuEco, menuStandard, menuUltimate, menuOptimized;
|
||||||
|
|
||||||
ModeControl modeControl;
|
ModeControl modeControl = new ModeControl();
|
||||||
|
GPUModeControl gpuControl = new GPUModeControl();
|
||||||
public ToastForm toast = new ToastForm();
|
|
||||||
|
|
||||||
public static System.Timers.Timer aTimer = default!;
|
public static System.Timers.Timer aTimer = default!;
|
||||||
public static Point trayPoint;
|
|
||||||
|
|
||||||
public string versionUrl = "http://github.com/seerge/g-helper/releases";
|
public string versionUrl = "http://github.com/seerge/g-helper/releases";
|
||||||
|
|
||||||
//public string modeName = "Balanced";
|
|
||||||
|
|
||||||
public AniMatrix matrix;
|
public AniMatrix matrix;
|
||||||
public Fans fans;
|
public Fans fans;
|
||||||
public Extra keyb;
|
public Extra keyb;
|
||||||
@@ -44,8 +41,6 @@ namespace GHelper
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
InitTheme(true);
|
InitTheme(true);
|
||||||
|
|
||||||
modeControl = new ModeControl();
|
|
||||||
|
|
||||||
buttonSilent.Text = Properties.Strings.Silent;
|
buttonSilent.Text = Properties.Strings.Silent;
|
||||||
buttonBalanced.Text = Properties.Strings.Balanced;
|
buttonBalanced.Text = Properties.Strings.Balanced;
|
||||||
buttonTurbo.Text = Properties.Strings.Turbo;
|
buttonTurbo.Text = Properties.Strings.Turbo;
|
||||||
@@ -133,6 +128,7 @@ namespace GHelper
|
|||||||
|
|
||||||
buttonMatrix.Click += ButtonMatrix_Click;
|
buttonMatrix.Click += ButtonMatrix_Click;
|
||||||
|
|
||||||
|
checkStartup.Checked = Startup.IsScheduled();
|
||||||
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
|
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
|
||||||
|
|
||||||
labelVersion.Click += LabelVersion_Click;
|
labelVersion.Click += LabelVersion_Click;
|
||||||
@@ -195,7 +191,7 @@ namespace GHelper
|
|||||||
if (this.Visible)
|
if (this.Visible)
|
||||||
{
|
{
|
||||||
InitScreen();
|
InitScreen();
|
||||||
InitXGM();
|
gpuControl.InitXGM();
|
||||||
|
|
||||||
// Run update once per 12 hours
|
// Run update once per 12 hours
|
||||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeSeconds() - lastUpdate) < 43200) return;
|
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()
|
public void SetContextMenu()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -351,47 +342,7 @@ namespace GHelper
|
|||||||
|
|
||||||
private void ButtonXGM_Click(object? sender, EventArgs e)
|
private void ButtonXGM_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
gpuControl.ToggleXGM();
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
|
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
|
||||||
@@ -451,8 +402,7 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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);
|
AppConfig.Set("gpu_auto", (AppConfig.Get("gpu_auto") == 1) ? 0 : 1);
|
||||||
VisualiseGPUMode();
|
VisualiseGPUMode();
|
||||||
AutoGPUMode();
|
gpuControl.AutoGPUMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonScreenAuto_Click(object? sender, EventArgs e)
|
private void ButtonScreenAuto_Click(object? sender, EventArgs e)
|
||||||
@@ -598,13 +548,9 @@ namespace GHelper
|
|||||||
CheckBox chk = (CheckBox)sender;
|
CheckBox chk = (CheckBox)sender;
|
||||||
|
|
||||||
if (chk.Checked)
|
if (chk.Checked)
|
||||||
{
|
|
||||||
Startup.Schedule();
|
Startup.Schedule();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
Startup.UnSchedule();
|
Startup.UnSchedule();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
|
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)
|
public void FansToggle(int index = 0)
|
||||||
{
|
{
|
||||||
if (fans == null || fans.Text == "")
|
if (fans == null || fans.Text == "")
|
||||||
@@ -783,13 +737,10 @@ namespace GHelper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int brightness = AppConfig.Get("matrix_brightness");
|
comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1);
|
||||||
int running = AppConfig.Get("matrix_running");
|
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;
|
checkMatrix.Checked = AppConfig.Is("matrix_auto");
|
||||||
comboMatrixRunning.SelectedIndex = (running != -1) ? Math.Min(running, comboMatrixRunning.Items.Count - 1) : 0;
|
|
||||||
|
|
||||||
checkMatrix.Checked = (AppConfig.Get("matrix_auto") == 1);
|
|
||||||
checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged;
|
checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -890,7 +841,7 @@ namespace GHelper
|
|||||||
int frequency = NativeMethods.GetRefreshRate();
|
int frequency = NativeMethods.GetRefreshRate();
|
||||||
int maxFrequency = NativeMethods.GetRefreshRate(true);
|
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);
|
bool overdriveSetting = (AppConfig.Get("no_overdrive") != 1);
|
||||||
|
|
||||||
int overdrive = Program.acpi.DeviceGet(AsusACPI.ScreenOverdrive);
|
int overdrive = Program.acpi.DeviceGet(AsusACPI.ScreenOverdrive);
|
||||||
@@ -978,26 +929,23 @@ namespace GHelper
|
|||||||
|
|
||||||
private void ButtonUltimate_Click(object? sender, EventArgs e)
|
private void ButtonUltimate_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SetGPUMode(AsusACPI.GPUModeUltimate);
|
gpuControl.SetGPUMode(AsusACPI.GPUModeUltimate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonStandard_Click(object? sender, EventArgs e)
|
private void ButtonStandard_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SetGPUMode(AsusACPI.GPUModeStandard);
|
gpuControl.SetGPUMode(AsusACPI.GPUModeStandard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonEco_Click(object? sender, EventArgs e)
|
private void ButtonEco_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SetGPUMode(AsusACPI.GPUModeEco);
|
gpuControl.SetGPUMode(AsusACPI.GPUModeEco);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonStopGPU_Click(object? sender, EventArgs e)
|
private void ButtonStopGPU_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (HardwareControl.GpuControl is not null)
|
gpuControl.KillGPUApps();
|
||||||
{
|
|
||||||
HardwareControl.GpuControl.KillGPUApps();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void RefreshSensors(bool force = false)
|
public async void RefreshSensors(bool force = false)
|
||||||
@@ -1050,54 +998,51 @@ namespace GHelper
|
|||||||
|
|
||||||
public void ShowMode(int mode)
|
public void ShowMode(int mode)
|
||||||
{
|
{
|
||||||
|
Invoke(delegate
|
||||||
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 = false;
|
||||||
buttonSilent.Activated = true;
|
buttonBalanced.Activated = false;
|
||||||
menuSilent.Checked = true;
|
buttonTurbo.Activated = false;
|
||||||
break;
|
buttonFans.Activated = false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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)
|
public void SetModeLabel(string modeText)
|
||||||
{
|
{
|
||||||
labelPerf.Text = modeText;
|
Invoke(delegate
|
||||||
|
{
|
||||||
|
labelPerf.Text = modeText;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1131,88 +1076,15 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPlugged()
|
public void VisualizeXGM(bool connected, bool activated)
|
||||||
{
|
|
||||||
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 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;
|
buttonXGM.Enabled = buttonXGM.Visible = connected;
|
||||||
|
|
||||||
if (!connected) return;
|
if (!connected) return;
|
||||||
|
|
||||||
int activated = Program.acpi.DeviceGet(AsusACPI.GPUXG);
|
buttonXGM.Activated = activated;
|
||||||
if (activated < 0) return;
|
|
||||||
|
|
||||||
buttonXGM.Activated = (activated == 1);
|
if (activated)
|
||||||
|
|
||||||
if (buttonXGM.Activated)
|
|
||||||
{
|
{
|
||||||
ButtonEnabled(buttonOptimized, false);
|
ButtonEnabled(buttonOptimized, false);
|
||||||
ButtonEnabled(buttonEco, false);
|
ButtonEnabled(buttonEco, false);
|
||||||
@@ -1229,231 +1101,52 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HideUltimateMode()
|
||||||
public int InitGPUMode()
|
|
||||||
{
|
{
|
||||||
|
tableGPU.Controls.Remove(buttonUltimate);
|
||||||
|
tablePerf.ColumnCount = 0;
|
||||||
|
tableGPU.ColumnCount = 0;
|
||||||
|
tableScreen.ColumnCount = 0;
|
||||||
|
menuUltimate.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
|
public void HideGPUModes()
|
||||||
int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
|
{
|
||||||
|
isGpuSection = false;
|
||||||
|
buttonEco.Visible = false;
|
||||||
|
buttonStandard.Visible = false;
|
||||||
|
buttonUltimate.Visible = false;
|
||||||
|
buttonOptimized.Visible = false;
|
||||||
|
buttonStopGPU.Visible = true;
|
||||||
|
|
||||||
Logger.WriteLine("Eco flag : " + eco);
|
SetContextMenu();
|
||||||
Logger.WriteLine("Mux flag : " + mux);
|
if (HardwareControl.FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan)) is null) panelGPU.Visible = false;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestartGPU(bool confirm = true)
|
public void LockGPUModes(string text = null)
|
||||||
{
|
{
|
||||||
if (HardwareControl.GpuControl is null) return;
|
Invoke(delegate
|
||||||
if (!HardwareControl.GpuControl!.IsNvidia) return;
|
|
||||||
|
|
||||||
if (confirm)
|
|
||||||
{
|
{
|
||||||
DialogResult dialogResult = MessageBox.Show(Properties.Strings.RestartGPU, Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
|
if (text is null) text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";
|
||||||
if (dialogResult == DialogResult.No) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessHelper.RunAsAdmin("gpurestart");
|
ButtonEnabled(buttonOptimized, false);
|
||||||
|
ButtonEnabled(buttonEco, false);
|
||||||
|
ButtonEnabled(buttonStandard, false);
|
||||||
|
ButtonEnabled(buttonUltimate, false);
|
||||||
|
ButtonEnabled(buttonXGM, false);
|
||||||
|
|
||||||
if (!ProcessHelper.IsUserAdministrator()) return;
|
labelGPU.Text = text;
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
public void VisualiseGPUMode(int GPUMode = -1)
|
||||||
{
|
{
|
||||||
|
ButtonEnabled(buttonOptimized, true);
|
||||||
|
ButtonEnabled(buttonEco, true);
|
||||||
|
ButtonEnabled(buttonStandard, true);
|
||||||
|
ButtonEnabled(buttonUltimate, true);
|
||||||
|
|
||||||
if (GPUMode == -1)
|
if (GPUMode == -1)
|
||||||
GPUMode = AppConfig.Get("gpu_mode");
|
GPUMode = AppConfig.Get("gpu_mode");
|
||||||
@@ -1516,10 +1209,6 @@ namespace GHelper
|
|||||||
modeControl.SetPerformanceMode(AsusACPI.PerformanceTurbo);
|
modeControl.SetPerformanceMode(AsusACPI.PerformanceTurbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Settings_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ButtonEnabled(RButton but, bool enabled)
|
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);
|
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)
|
public void SetBatteryChargeLimit(int limit)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using CustomControls;
|
using GHelper.UI;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Windows.Forms.DataVisualization.Charting;
|
using System.Windows.Forms.DataVisualization.Charting;
|
||||||
using WinFormsSliderBar;
|
|
||||||
|
|
||||||
public static class ControlHelper
|
public static class ControlHelper
|
||||||
{
|
{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper.UI
|
||||||
{
|
{
|
||||||
class CustomContextMenu : ContextMenuStrip
|
class CustomContextMenu : ContextMenuStrip
|
||||||
{
|
{
|
||||||
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
private static extern long DwmSetWindowAttribute(IntPtr hwnd,
|
private static extern long DwmSetWindowAttribute(nint hwnd,
|
||||||
DWMWINDOWATTRIBUTE attribute,
|
DWMWINDOWATTRIBUTE attribute,
|
||||||
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
||||||
uint cbAttribute);
|
uint cbAttribute);
|
||||||
@@ -3,7 +3,7 @@ using System.ComponentModel;
|
|||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace CustomControls
|
namespace GHelper.UI
|
||||||
{
|
{
|
||||||
|
|
||||||
public class RForm : Form
|
public class RForm : Form
|
||||||
@@ -28,7 +28,7 @@ namespace CustomControls
|
|||||||
public static extern bool CheckSystemDarkModeStatus();
|
public static extern bool CheckSystemDarkModeStatus();
|
||||||
|
|
||||||
[DllImport("DwmApi")] //System.Runtime.InteropServices
|
[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;
|
public bool darkTheme = false;
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ namespace CustomControls
|
|||||||
public bool InitTheme(bool setDPI = false)
|
public bool InitTheme(bool setDPI = false)
|
||||||
{
|
{
|
||||||
bool newDarkTheme = CheckSystemDarkModeStatus();
|
bool newDarkTheme = CheckSystemDarkModeStatus();
|
||||||
bool changed = (darkTheme != newDarkTheme);
|
bool changed = darkTheme != newDarkTheme;
|
||||||
darkTheme = newDarkTheme;
|
darkTheme = newDarkTheme;
|
||||||
|
|
||||||
InitColors(darkTheme);
|
InitColors(darkTheme);
|
||||||
@@ -82,7 +82,7 @@ namespace CustomControls
|
|||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
DwmSetWindowAttribute(this.Handle, 20, new[] { darkTheme ? 1 : 0 }, 4);
|
DwmSetWindowAttribute(Handle, 20, new[] { darkTheme ? 1 : 0 }, 4);
|
||||||
ControlHelper.Adjust(this, changed);
|
ControlHelper.Adjust(this, changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,8 +182,8 @@ namespace CustomControls
|
|||||||
};
|
};
|
||||||
var ps = new PAINTSTRUCT();
|
var ps = new PAINTSTRUCT();
|
||||||
bool shoulEndPaint = false;
|
bool shoulEndPaint = false;
|
||||||
IntPtr dc;
|
nint dc;
|
||||||
if (m.WParam == IntPtr.Zero)
|
if (m.WParam == nint.Zero)
|
||||||
{
|
{
|
||||||
dc = BeginPaint(Handle, ref ps);
|
dc = BeginPaint(Handle, ref ps);
|
||||||
m.WParam = dc;
|
m.WParam = dc;
|
||||||
@@ -240,7 +240,7 @@ namespace CustomControls
|
|||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct PAINTSTRUCT
|
public struct PAINTSTRUCT
|
||||||
{
|
{
|
||||||
public IntPtr hdc;
|
public nint hdc;
|
||||||
public bool fErase;
|
public bool fErase;
|
||||||
public int rcPaint_left;
|
public int rcPaint_left;
|
||||||
public int rcPaint_top;
|
public int rcPaint_top;
|
||||||
@@ -258,17 +258,17 @@ namespace CustomControls
|
|||||||
public int reserved8;
|
public int reserved8;
|
||||||
}
|
}
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern IntPtr BeginPaint(IntPtr hWnd,
|
private static extern nint BeginPaint(nint hWnd,
|
||||||
[In, Out] ref PAINTSTRUCT lpPaint);
|
[In, Out] ref PAINTSTRUCT lpPaint);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[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")]
|
[DllImport("gdi32.dll")]
|
||||||
public static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn);
|
public static extern int SelectClipRgn(nint hDC, nint hRgn);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[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
|
public enum RegionFlags
|
||||||
{
|
{
|
||||||
ERROR = 0,
|
ERROR = 0,
|
||||||
@@ -277,10 +277,10 @@ namespace CustomControls
|
|||||||
COMPLEXREGION = 3,
|
COMPLEXREGION = 3,
|
||||||
}
|
}
|
||||||
[DllImport("gdi32.dll")]
|
[DllImport("gdi32.dll")]
|
||||||
internal static extern bool DeleteObject(IntPtr hObject);
|
internal static extern bool DeleteObject(nint hObject);
|
||||||
|
|
||||||
[DllImport("gdi32.dll")]
|
[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
|
public class RButton : Button
|
||||||
@@ -316,7 +316,7 @@ namespace CustomControls
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (activated != value)
|
if (activated != value)
|
||||||
this.Invalidate();
|
Invalidate();
|
||||||
activated = value;
|
activated = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -362,19 +362,19 @@ namespace CustomControls
|
|||||||
float ratio = pevent.Graphics.DpiX / 192.0f;
|
float ratio = pevent.Graphics.DpiX / 192.0f;
|
||||||
int border = (int)(ratio * borderSize);
|
int border = (int)(ratio * borderSize);
|
||||||
|
|
||||||
Rectangle rectSurface = this.ClientRectangle;
|
Rectangle rectSurface = ClientRectangle;
|
||||||
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -border, -border);
|
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -border, -border);
|
||||||
|
|
||||||
Color borderDrawColor = activated ? borderColor : Color.Transparent;
|
Color borderDrawColor = activated ? borderColor : Color.Transparent;
|
||||||
|
|
||||||
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius + border))
|
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius + border))
|
||||||
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius))
|
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))
|
using (Pen penBorder = new Pen(borderDrawColor, border))
|
||||||
{
|
{
|
||||||
penBorder.Alignment = PenAlignment.Outset;
|
penBorder.Alignment = PenAlignment.Outset;
|
||||||
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
this.Region = new Region(pathSurface);
|
Region = new Region(pathSurface);
|
||||||
pevent.Graphics.DrawPath(penSurface, pathSurface);
|
pevent.Graphics.DrawPath(penSurface, pathSurface);
|
||||||
pevent.Graphics.DrawPath(penBorder, pathBorder);
|
pevent.Graphics.DrawPath(penBorder, pathBorder);
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,7 @@ namespace CustomControls
|
|||||||
rect.Height -= Image.Height;
|
rect.Height -= Image.Height;
|
||||||
}
|
}
|
||||||
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
namespace WinFormsSliderBar
|
namespace GHelper.UI
|
||||||
{
|
{
|
||||||
public static class GraphicsExtensions
|
public static class GraphicsExtensions
|
||||||
{
|
{
|
||||||
8
app/Updates.Designer.cs
generated
8
app/Updates.Designer.cs
generated
@@ -1,4 +1,6 @@
|
|||||||
namespace GHelper
|
using GHelper.UI;
|
||||||
|
|
||||||
|
namespace GHelper
|
||||||
{
|
{
|
||||||
partial class Updates
|
partial class Updates
|
||||||
{
|
{
|
||||||
@@ -34,7 +36,7 @@
|
|||||||
pictureBios = new PictureBox();
|
pictureBios = new PictureBox();
|
||||||
panelBiosTitle = new Panel();
|
panelBiosTitle = new Panel();
|
||||||
labelUpdates = new Label();
|
labelUpdates = new Label();
|
||||||
buttonRefresh = new CustomControls.RButton();
|
buttonRefresh = new RButton();
|
||||||
panelBios = new Panel();
|
panelBios = new Panel();
|
||||||
panelDrivers = new Panel();
|
panelDrivers = new Panel();
|
||||||
tableDrivers = new TableLayoutPanel();
|
tableDrivers = new TableLayoutPanel();
|
||||||
@@ -242,7 +244,7 @@
|
|||||||
private Panel panelDriversTitle;
|
private Panel panelDriversTitle;
|
||||||
private Label labelDrivers;
|
private Label labelDrivers;
|
||||||
private PictureBox pictureDrivers;
|
private PictureBox pictureDrivers;
|
||||||
private CustomControls.RButton buttonRefresh;
|
private RButton buttonRefresh;
|
||||||
private Label labelUpdates;
|
private Label labelUpdates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using CustomControls;
|
using GHelper.UI;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|||||||
Reference in New Issue
Block a user