diff --git a/ColorControl/ADL.cs b/ColorControl/ADL.cs
index 3ecc89e..440da50 100644
--- a/ColorControl/ADL.cs
+++ b/ColorControl/ADL.cs
@@ -23,12 +23,10 @@
using System;
using System.Collections.Generic;
-using System.Text;
using System.Runtime.InteropServices;
-using System.Diagnostics;
-using System.Threading;
using FARPROC = System.IntPtr;
using HMODULE = System.IntPtr;
+using ADL_CONTEXT_HANDLE = System.IntPtr;
#endregion Using
@@ -36,52 +34,6 @@ using HMODULE = System.IntPtr;
namespace ATI.ADL
{
- #region Export Delegates
- /// ADL Memory allocation function allows ADL to callback for memory allocation
- /// input size
- /// retrun ADL Error Code
- internal delegate IntPtr ADL_Main_Memory_Alloc (int size);
-
- // ///// ADL Create Function to create ADL Data
- /// Call back functin pointer which is ised to allocate memeory
- /// If it is 1, then ADL will only retuen the physical exist adapters
- ///// retrun ADL Error Code
- internal delegate int ADL_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters);
-
- /// ADL Destroy Function to free up ADL Data
- /// retrun ADL Error Code
- internal delegate int ADL_Main_Control_Destroy ();
-
- /// ADL Function to get the number of adapters
- /// return number of adapters
- /// retrun ADL Error Code
- internal delegate int ADL_Adapter_NumberOfAdapters_Get (ref int numAdapters);
-
- /// ADL Function to get the GPU adapter information
- /// return GPU adapter information
- /// the size of the GPU adapter struct
- /// retrun ADL Error Code
- internal delegate int ADL_Adapter_AdapterInfo_Get (IntPtr info, int inputSize);
-
- /// Function to determine if the adapter is active or not.
- /// The function is used to check if the adapter associated with iAdapterIndex is active
- /// Adapter Index.
- /// Status of the adapter. True: Active; False: Dsiabled
- /// Non zero is successfull
- internal delegate int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
-
- /// Get display information based on adapter index
- /// Adapter Index
- /// return the total number of supported displays
- /// return ADLDisplayInfo Array for supported displays' information
- /// force detect or not
- /// return ADL Error Code
- internal delegate int ADL_Display_DisplayInfo_Get(int adapterIndex, ref int numDisplays, out IntPtr displayInfoArray, int forceDetect);
-
- internal delegate int ADL_Display_Size_Get(int adapterIndex, int displayIndex, ref int lpWidth, ref int lpHeight, ref int lpDefaultWidth, ref int lpDefaultHeight, ref int lpMinWidth, ref int lpMinHeight, ref int lpMaxWidth, ref int lpMaxHeight, ref int lpStepWidth, ref int lpStepHeight);
-
- #endregion Export Delegates
-
#region Export Struct
#region ADLAdapterInfo
@@ -207,10 +159,74 @@ namespace ATI.ADL
/// Maximum number of GL-Sync ports on the GL-Sync module
internal const int ADL_MAX_GLSYNC_PORT_LEDS = 8;
/// Maximum number of ADLMOdes for the adapter
- internal const int ADL_MAX_NUM_DISPLAYMODES = 1024;
+ internal const int ADL_MAX_NUM_DISPLAYMODES = 1024;
+
+ internal static Dictionary ADLDelegates = new Dictionary();
#endregion Internal Constant
+ #region Export Delegates
+ /// ADL Memory allocation function allows ADL to callback for memory allocation
+ /// input size
+ /// retrun ADL Error Code
+ internal delegate IntPtr ADL_Main_Memory_Alloc(int size);
+
+ // ///// ADL Create Function to create ADL Data
+ /// Call back functin pointer which is ised to allocate memeory
+ /// If it is 1, then ADL will only retuen the physical exist adapters
+ ///// retrun ADL Error Code
+ internal delegate int ADL_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters);
+
+ internal delegate int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, ref ADL_CONTEXT_HANDLE context);
+
+ /// ADL Destroy Function to free up ADL Data
+ /// retrun ADL Error Code
+ internal delegate int ADL_Main_Control_Destroy();
+
+ internal delegate int ADL2_Main_Control_Destroy(ADL_CONTEXT_HANDLE context);
+
+ /// ADL Function to get the number of adapters
+ /// return number of adapters
+ /// retrun ADL Error Code
+ internal delegate int ADL_Adapter_NumberOfAdapters_Get(ref int numAdapters);
+
+ /// ADL Function to get the GPU adapter information
+ /// return GPU adapter information
+ /// the size of the GPU adapter struct
+ /// retrun ADL Error Code
+ internal delegate int ADL_Adapter_AdapterInfo_Get(IntPtr info, int inputSize);
+
+ /// Function to determine if the adapter is active or not.
+ /// The function is used to check if the adapter associated with iAdapterIndex is active
+ /// Adapter Index.
+ /// Status of the adapter. True: Active; False: Dsiabled
+ /// Non zero is successfull
+ internal delegate int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
+
+ /// Get display information based on adapter index
+ /// Adapter Index
+ /// return the total number of supported displays
+ /// return ADLDisplayInfo Array for supported displays' information
+ /// force detect or not
+ /// return ADL Error Code
+ internal delegate int ADL_Display_DisplayInfo_Get(int adapterIndex, ref int numDisplays, out IntPtr displayInfoArray, int forceDetect);
+
+ internal delegate int ADL_Display_Size_Get(int adapterIndex, int displayIndex, ref int lpWidth, ref int lpHeight, ref int lpDefaultWidth, ref int lpDefaultHeight, ref int lpMinWidth, ref int lpMinHeight, ref int lpMaxWidth, ref int lpMaxHeight, ref int lpStepWidth, ref int lpStepHeight);
+
+ internal delegate int ADL_Display_PixelFormat_Get(int adapterIndex, int displayIndex, ref int pixelFormat);
+ internal delegate int ADL_Display_PixelFormat_Set(int adapterIndex, int displayIndex, int pixelFormat);
+
+ internal delegate int ADL_Display_ColorDepth_Get(int adapterIndex, int displayIndex, ref int colorDepth);
+ internal delegate int ADL_Display_ColorDepth_Set(int adapterIndex, int displayIndex, int colorDepth);
+
+ internal delegate int ADL_Display_DitherState_Get(int adapterIndex, int displayIndex, ref int ditherState);
+ internal delegate int ADL_Display_DitherState_Set(int adapterIndex, int displayIndex, int ditherState);
+
+ internal delegate int ADL2_Display_HDRState_Get(ADL_CONTEXT_HANDLE context, int adapterIndex, ADLDisplayID displayID, ref int support, ref int enable);
+ internal delegate int ADL2_Display_HDRState_Set(ADL_CONTEXT_HANDLE context, int adapterIndex, ADLDisplayID displayID, int enable);
+
+ #endregion Export Delegates
+
#region Class ADLImport
/// ADLImport class
private static class ADLImport
@@ -227,31 +243,10 @@ namespace ATI.ADL
internal static extern HMODULE GetModuleHandle (string moduleName);
[DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Main_Control_Create (ADL_Main_Memory_Alloc callback, int enumConnectedAdapters);
+ internal static extern int ADL_Main_Control_IsFunctionValid(HMODULE module, string procName);
[DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Main_Control_Destroy ();
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Main_Control_IsFunctionValid (HMODULE module, string procName);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern FARPROC ADL_Main_Control_GetProcAddress (HMODULE module, string procName);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Adapter_NumberOfAdapters_Get (ref int numAdapters);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Adapter_AdapterInfo_Get (IntPtr info, int inputSize);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Display_DisplayInfo_Get(int adapterIndex, ref int numDisplays, out IntPtr displayInfoArray, int forceDetect);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL_Display_Size_Get(int iAdapterIndex, int iDisplayIndex, ref int lpWidth, ref int lpHeight, ref int lpDefaultWidth, ref int lpDefaultHeight, ref int lpMinWidth, ref int lpMinHeight, ref int lpMaxWidth, ref int lpMaxHeight, ref int lpStepWidth, ref int lpStepHeight);
+ internal static extern FARPROC ADL_Main_Control_GetProcAddress(HMODULE module, string procName);
#endregion DLLImport
}
@@ -291,9 +286,13 @@ namespace ATI.ADL
/// Destructor to force calling ADL Destroy function before free up the ADL library
~ADLCheckLibrary ()
{
- if (System.IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
+ if (IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
{
- ADLImport.ADL_Main_Control_Destroy();
+ var del = ADL.GetDelegate();
+ if (del != null)
+ {
+ del();
+ }
}
}
#endregion Destructor
@@ -304,8 +303,8 @@ namespace ATI.ADL
/// return true, if function exists
internal static bool IsFunctionValid (string functionName)
{
- bool result = false;
- if (System.IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
+ var result = false;
+ if (IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
{
if (1 == ADLImport.ADL_Main_Control_IsFunctionValid(ADLCheckLibrary_.ADLLibrary, functionName))
{
@@ -322,8 +321,8 @@ namespace ATI.ADL
/// return function pointer, if function exists
internal static FARPROC GetProcAddress (string functionName)
{
- FARPROC result = System.IntPtr.Zero;
- if (System.IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
+ var result = IntPtr.Zero;
+ if (IntPtr.Zero != ADLCheckLibrary_.ADLLibrary)
{
result = ADLImport.ADL_Main_Control_GetProcAddress(ADLCheckLibrary_.ADLLibrary, functionName);
}
@@ -337,7 +336,7 @@ namespace ATI.ADL
#region ADL_Main_Memory_Alloc
/// Build in memory allocation function
- internal static ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc = ADL_Main_Memory_Alloc_;
+ internal static ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc_Func = ADL_Main_Memory_Alloc_;
/// Build in memory allocation function
/// input size
/// return the memory buffer
@@ -360,166 +359,29 @@ namespace ATI.ADL
}
#endregion ADL_Main_Memory_Free
- #region ADL_Main_Control_Create
- /// ADL_Main_Control_Create Delegates
- internal static ADL_Main_Control_Create ADL_Main_Control_Create
+ public static T GetDelegate() where T : class
{
- get
- {
- if (!ADL_Main_Control_Create_Check && null == ADL_Main_Control_Create_)
- {
- ADL_Main_Control_Create_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Main_Control_Create"))
- {
- ADL_Main_Control_Create_ = ADLImport.ADL_Main_Control_Create;
- }
- }
- return ADL_Main_Control_Create_;
- }
- }
- /// Private Delegate
- private static ADL_Main_Control_Create ADL_Main_Control_Create_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Main_Control_Create_Check = false;
- #endregion ADL_Main_Control_Create
+ var type = typeof(T);
- #region ADL_Main_Control_Destroy
- /// ADL_Main_Control_Destroy Delegates
- internal static ADL_Main_Control_Destroy ADL_Main_Control_Destroy
- {
- get
+ lock (ADLDelegates)
{
- if (!ADL_Main_Control_Destroy_Check && null == ADL_Main_Control_Destroy_)
+ if (ADLDelegates.ContainsKey(type))
{
- ADL_Main_Control_Destroy_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Main_Control_Destroy"))
- {
- ADL_Main_Control_Destroy_ = ADLImport.ADL_Main_Control_Destroy;
- }
+ return ADLDelegates[type] as T;
}
- return ADL_Main_Control_Destroy_;
- }
- }
- /// Private Delegate
- private static ADL_Main_Control_Destroy ADL_Main_Control_Destroy_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Main_Control_Destroy_Check = false;
- #endregion ADL_Main_Control_Destroy
- #region ADL_Adapter_NumberOfAdapters_Get
- /// ADL_Adapter_NumberOfAdapters_Get Delegates
- internal static ADL_Adapter_NumberOfAdapters_Get ADL_Adapter_NumberOfAdapters_Get
- {
- get
- {
- if (!ADL_Adapter_NumberOfAdapters_Get_Check && null == ADL_Adapter_NumberOfAdapters_Get_)
+ var ptr = ADLCheckLibrary.GetProcAddress(type.Name);
+ if (ptr != FARPROC.Zero)
{
- ADL_Adapter_NumberOfAdapters_Get_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Adapter_NumberOfAdapters_Get"))
- {
- ADL_Adapter_NumberOfAdapters_Get_ = ADLImport.ADL_Adapter_NumberOfAdapters_Get;
- }
- }
- return ADL_Adapter_NumberOfAdapters_Get_;
- }
- }
- /// Private Delegate
- private static ADL_Adapter_NumberOfAdapters_Get ADL_Adapter_NumberOfAdapters_Get_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Adapter_NumberOfAdapters_Get_Check = false;
- #endregion ADL_Adapter_NumberOfAdapters_Get
+ var delegateValue = Marshal.GetDelegateForFunctionPointer(ptr, type);
+ ADLDelegates.Add(type, delegateValue);
- #region ADL_Adapter_AdapterInfo_Get
- /// ADL_Adapter_AdapterInfo_Get Delegates
- internal static ADL_Adapter_AdapterInfo_Get ADL_Adapter_AdapterInfo_Get
- {
- get
- {
- if (!ADL_Adapter_AdapterInfo_Get_Check && null == ADL_Adapter_AdapterInfo_Get_)
- {
- ADL_Adapter_AdapterInfo_Get_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Adapter_AdapterInfo_Get"))
- {
- ADL_Adapter_AdapterInfo_Get_ = ADLImport.ADL_Adapter_AdapterInfo_Get;
- }
+ return delegateValue as T;
}
- return ADL_Adapter_AdapterInfo_Get_;
}
- }
- /// Private Delegate
- private static ADL_Adapter_AdapterInfo_Get ADL_Adapter_AdapterInfo_Get_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Adapter_AdapterInfo_Get_Check = false;
- #endregion ADL_Adapter_AdapterInfo_Get
- #region ADL_Adapter_Active_Get
- /// ADL_Adapter_Active_Get Delegates
- internal static ADL_Adapter_Active_Get ADL_Adapter_Active_Get
- {
- get
- {
- if (!ADL_Adapter_Active_Get_Check && null == ADL_Adapter_Active_Get_)
- {
- ADL_Adapter_Active_Get_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Adapter_Active_Get"))
- {
- ADL_Adapter_Active_Get_ = ADLImport.ADL_Adapter_Active_Get;
- }
- }
- return ADL_Adapter_Active_Get_;
- }
+ throw new InvalidProgramException("ADL-function not supported");
}
- /// Private Delegate
- private static ADL_Adapter_Active_Get ADL_Adapter_Active_Get_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Adapter_Active_Get_Check = false;
- #endregion ADL_Adapter_Active_Get
-
- #region ADL_Display_DisplayInfo_Get
- /// ADL_Display_DisplayInfo_Get Delegates
- internal static ADL_Display_DisplayInfo_Get ADL_Display_DisplayInfo_Get
- {
- get
- {
- if (!ADL_Display_DisplayInfo_Get_Check && null == ADL_Display_DisplayInfo_Get_)
- {
- ADL_Display_DisplayInfo_Get_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Display_DisplayInfo_Get"))
- {
- ADL_Display_DisplayInfo_Get_ = ADLImport.ADL_Display_DisplayInfo_Get;
- }
- }
- return ADL_Display_DisplayInfo_Get_;
- }
- }
- /// Private Delegate
- private static ADL_Display_DisplayInfo_Get ADL_Display_DisplayInfo_Get_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Display_DisplayInfo_Get_Check = false;
- #endregion ADL_Display_DisplayInfo_Get
-
- #region ADL_Display_Size_Get
- /// ADL_Display_Size_Get Delegates
- internal static ADL_Display_Size_Get ADL_Display_Size_Get
- {
- get
- {
- if (!ADL_Display_Size_Get_Check && null == ADL_Display_Size_Get)
- {
- ADL_Display_Size_Get_Check = true;
- if (ADLCheckLibrary.IsFunctionValid("ADL_Display_Size_Get"))
- {
- ADL_Display_Size_Get_ = ADLImport.ADL_Display_Size_Get;
- }
- }
- return ADL_Display_Size_Get_;
- }
- }
- /// Private Delegate
- private static ADL_Display_Size_Get ADL_Display_Size_Get_ = null;
- /// check flag to indicate the delegate has been checked
- private static bool ADL_Display_Size_Get_Check = false;
- #endregion ADL_Display_Size_Get
#endregion Export Functions
}
diff --git a/ColorControl/ADLWrapper.cs b/ColorControl/ADLWrapper.cs
index dcf86fa..f61cd6d 100644
--- a/ColorControl/ADLWrapper.cs
+++ b/ColorControl/ADLWrapper.cs
@@ -3,28 +3,114 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Windows.Forms;
+using ADL_CONTEXT_HANDLE = System.IntPtr;
namespace ColorControl
{
+ enum ADLPixelFormat
+ {
+ UNKNOWN = 0,
+ RGB_FULL_RANGE = 1,
+ YCRCB444 = 2,
+ YCRCB422 = 3,
+ RGB_LIMITED_RANGE = 4,
+ YCRCB420 = 8
+ }
+
+ enum ADLColorDepth
+ {
+ UNKNOWN = 0,
+ BPC6 = 1,
+ BPC8 = 2,
+ BPC10 = 3,
+ BPC12 = 4,
+ BPC14 = 5,
+ BPC16 = 6
+ }
+
+ enum ADLDitherState
+ {
+ DISABLED = 0,
+ DRIVER_DEFAULT = 1,
+ FM6 = 2,
+ FM8 = 3,
+ FM10 = 4,
+ DITH6 = 5,
+ DITH8 = 6,
+ DITH10 = 7,
+ DITH6_NO_FRAME_RAND = 8,
+ DITH8_NO_FRAME_RAND = 9,
+ DITH10_NO_FRAME_RAND = 10,
+ TRUN6 = 11,
+ TRUN8 = 12,
+ TRUN10 = 13,
+ TRUN8_DITH8 = 14,
+ TRUN10_DUTH6 = 15,
+ TRUN10_FM8 = 16,
+ TRUN10_FM6 = 17,
+ TRUN10_DITH8_FM6 = 18,
+ DITH10_FM8 = 19,
+ DITH10_FM6 = 20,
+ TRUN8_DITH6 = 21,
+ TRUN8_FM6 = 22,
+ DITH8_FM6 = 23
+ }
+
class ADLWrapper
{
+ private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
+ private static ADL_CONTEXT_HANDLE context = IntPtr.Zero;
+
public static bool Initialize()
{
int ADLRet = -1;
- if (null != ADL.ADL_Main_Control_Create)
+ Logger.Debug("Initialize");
+
+ var del = ADL.GetDelegate();
+
+ if (del != null)
{
// Second parameter is 1: Get only the present adapters
- ADLRet = ADL.ADL_Main_Control_Create(ADL.ADL_Main_Memory_Alloc, 1);
+ ADLRet = del(ADL.ADL_Main_Memory_Alloc_Func, 1);
+ CheckError(ADLRet, nameof(ADL.ADL_Main_Control_Create));
}
+
+ Logger.Debug("ADLRet1: " + ADLRet);
+
+ var del2 = ADL.GetDelegate();
+
+ if (del2 != null)
+ {
+ // Second parameter is 1: Get only the present adapters
+ ADLRet = del2(ADL.ADL_Main_Memory_Alloc_Func, 1, ref context);
+ Logger.Debug("ADLRet2: " + ADLRet);
+ CheckError(ADLRet, nameof(ADL.ADL2_Main_Control_Create));
+ }
+
return (ADL.ADL_SUCCESS == ADLRet);
}
public static void Uninitialze()
{
- if (null != ADL.ADL_Main_Control_Destroy)
+ if (!ADL.ADLDelegates.Any())
{
- ADL.ADL_Main_Control_Destroy();
+ return;
+ }
+
+ var del = ADL.GetDelegate();
+
+ if (null != del)
+ {
+ del();
+ }
+
+ var del2 = ADL.GetDelegate();
+
+ if (null != del2 && context != IntPtr.Zero)
+ {
+ del2(context);
}
}
@@ -33,11 +119,13 @@ namespace ColorControl
int ADLRet = -1;
int NumberOfAdapters = 0;
- if (null != ADL.ADL_Adapter_NumberOfAdapters_Get)
+ var delNumberOfAdapters = ADL.GetDelegate();
+
+ if (null != delNumberOfAdapters)
{
- ADL.ADL_Adapter_NumberOfAdapters_Get(ref NumberOfAdapters);
+ delNumberOfAdapters(ref NumberOfAdapters);
}
- Console.WriteLine("Number Of Adapters: " + NumberOfAdapters.ToString() + "\n");
+ Logger.Debug("Number Of Adapters: " + NumberOfAdapters.ToString() + "\n");
if (NumberOfAdapters > 0)
{
@@ -45,37 +133,38 @@ namespace ColorControl
ADLAdapterInfoArray OSAdapterInfoData;
OSAdapterInfoData = new ADLAdapterInfoArray();
- if (null != ADL.ADL_Adapter_AdapterInfo_Get)
+ var delAdapterInfo = ADL.GetDelegate();
+
+ if (null != delAdapterInfo)
{
IntPtr AdapterBuffer = IntPtr.Zero;
int size = Marshal.SizeOf(OSAdapterInfoData);
AdapterBuffer = Marshal.AllocCoTaskMem((int)size);
Marshal.StructureToPtr(OSAdapterInfoData, AdapterBuffer, false);
- if (null != ADL.ADL_Adapter_AdapterInfo_Get)
+ ADLRet = delAdapterInfo(AdapterBuffer, size);
+ if (ADL.ADL_SUCCESS == ADLRet)
{
- ADLRet = ADL.ADL_Adapter_AdapterInfo_Get(AdapterBuffer, size);
- if (ADL.ADL_SUCCESS == ADLRet)
+ OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType());
+ int IsActive = 0;
+
+ var delActive = ADL.GetDelegate();
+
+ for (int i = 0; i < NumberOfAdapters; i++)
{
- OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType());
- int IsActive = 0;
+ // Check if the adapter is active
+ if (null != delActive)
+ ADLRet = delActive(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref IsActive);
- for (int i = 0; i < NumberOfAdapters; i++)
+ if (ADL.ADL_SUCCESS == ADLRet)
{
- // Check if the adapter is active
- if (null != ADL.ADL_Adapter_Active_Get)
- ADLRet = ADL.ADL_Adapter_Active_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref IsActive);
- if (ADL.ADL_SUCCESS == ADLRet)
- {
-
- }
}
}
- else
- {
- Console.WriteLine("ADL_Adapter_AdapterInfo_Get() returned error code " + ADLRet.ToString());
- }
+ }
+ else
+ {
+ Logger.Debug("ADL_Adapter_AdapterInfo_Get() returned error code " + ADLRet.ToString());
}
// Release the memory for the AdapterInfo structure
if (IntPtr.Zero != AdapterBuffer)
@@ -88,7 +177,7 @@ namespace ColorControl
return null;
}
- public static List GetAllDisplays()
+ public static List GetAllDisplays(bool connected = true)
{
int ADLRet;
int NumberOfDisplays = 0;
@@ -104,24 +193,28 @@ namespace ColorControl
ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo();
- if (null != ADL.ADL_Display_DisplayInfo_Get)
+ var del = ADL.GetDelegate();
+
+ if (null != del)
{
IntPtr DisplayBuffer = IntPtr.Zero;
int j = 0;
// Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection
- ADLRet = ADL.ADL_Display_DisplayInfo_Get(primaryAdapter.AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 1);
+ ADLRet = del(primaryAdapter.AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 1);
if (ADL.ADL_SUCCESS == ADLRet)
{
for (j = 0; j < NumberOfDisplays; j++)
{
- oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt32() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType());
- DisplayInfoData.Add(oneDisplayInfo);
+ oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt64() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType());
+ if (!connected || (1 == (oneDisplayInfo.DisplayInfoValue & 1))) {
+ DisplayInfoData.Add(oneDisplayInfo);
+ }
}
- Console.WriteLine("\nTotal Number of Displays supported: " + NumberOfDisplays.ToString());
- Console.WriteLine("\nDispID AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName ");
+ Logger.Debug("Total Number of Displays supported: " + NumberOfDisplays.ToString());
+ Logger.Debug("DispID DispPhyId AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName ");
- for (j = 0; j < NumberOfDisplays; j++)
+ for (j = 0; j < DisplayInfoData.Count; j++)
{
int InfoValue = DisplayInfoData[j].DisplayInfoValue;
string StrConnected = (1 == (InfoValue & 1)) ? "Yes" : "No ";
@@ -129,21 +222,21 @@ namespace ColorControl
int AdpID = DisplayInfoData[j].DisplayID.DisplayLogicalAdapterIndex;
string StrAdpID = (AdpID < 0) ? "--" : AdpID.ToString("d2");
- Console.WriteLine(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " +
- StrAdpID + " " +
- DisplayInfoData[j].DisplayType.ToString() + " " +
- DisplayInfoData[j].DisplayOutputType.ToString() + " " +
- DisplayInfoData[j].DisplayConnector.ToString() + " " +
- StrConnected + " " +
- StrMapped + " " +
- InfoValue.ToString("x4") + " " +
- DisplayInfoData[j].DisplayName.ToString());
+ Logger.Debug(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " +
+ DisplayInfoData[j].DisplayID.DisplayPhysicalIndex.ToString() + " " +
+ StrAdpID + " " +
+ DisplayInfoData[j].DisplayType.ToString() + " " +
+ DisplayInfoData[j].DisplayOutputType.ToString() + " " +
+ DisplayInfoData[j].DisplayConnector.ToString() + " " +
+ StrConnected + " " +
+ StrMapped + " " +
+ InfoValue.ToString("x4") + " " +
+ DisplayInfoData[j].DisplayName.ToString());
}
- Console.WriteLine();
}
else
{
- Console.WriteLine("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString());
+ Logger.Debug("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString());
}
// Release the memory for the DisplayInfo structure
if (IntPtr.Zero != DisplayBuffer)
@@ -152,17 +245,155 @@ namespace ColorControl
return DisplayInfoData;
}
- public static bool GetDisplayResolution(string displayName, ref int horizontal, ref int vertical)
+ private static bool CheckError(int ADLRet, string functionName)
{
- var displays = GetAllDisplays();
- var display = displays.FirstOrDefault(d => d.DisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase));
- if (display.DisplayID.DisplayPhysicalIndex >= 0 && ADL.ADL_Display_Size_Get != null)
- {
- int lpDefaultWidth, lpDefaultHeight, lpMinWidth, lpMinHeight, lpMaxWidth, lpMaxHeight, lpStepWidth, lpStepHeight;
- lpDefaultWidth = lpDefaultHeight = lpMinWidth = lpMinHeight = lpMaxWidth = lpMaxHeight = lpStepWidth = lpStepHeight = 0;
- var ADLRet = ADL.ADL_Display_Size_Get(display.DisplayID.DisplayPhysicalAdapterIndex, display.DisplayID.DisplayPhysicalIndex, ref horizontal, ref vertical, ref lpDefaultWidth, ref lpDefaultHeight, ref lpMinWidth, ref lpMinHeight, ref lpMaxWidth, ref lpMaxHeight, ref lpStepWidth, ref lpStepHeight);
+ var result = ADLRet == ADL.ADL_SUCCESS;
- return ADLRet == ADL.ADL_SUCCESS;
+ if (!result)
+ {
+ Logger.Error($"Error calling ADL ({functionName}): {ADLRet}");
+ }
+
+ return result;
+ }
+
+ public static bool GetDisplayResolution(ADLDisplayInfo display, ref int horizontal, ref int vertical)
+ {
+ var screen = Screen.PrimaryScreen;
+ var bounds = screen.Bounds;
+
+ horizontal = bounds.Width;
+ vertical = bounds.Height;
+
+ Logger.Debug($"GetDisplayResolution: {horizontal}x{vertical}");
+
+ //var del = ADL.GetDelegate();
+
+ //if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ //{
+ // int lpDefaultWidth, lpDefaultHeight, lpMinWidth, lpMinHeight, lpMaxWidth, lpMaxHeight, lpStepWidth, lpStepHeight;
+ // lpDefaultWidth = lpDefaultHeight = lpMinWidth = lpMinHeight = lpMaxWidth = lpMaxHeight = lpStepWidth = lpStepHeight = 0;
+ // var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, ref horizontal, ref vertical, ref lpDefaultWidth, ref lpDefaultHeight, ref lpMinWidth, ref lpMinHeight, ref lpMaxWidth, ref lpMaxHeight, ref lpStepWidth, ref lpStepHeight);
+
+ // return CheckError(ADLRet, nameof(ADL.ADL_Display_Size_Get));
+ //}
+ return true;
+ }
+
+ public static bool GetDisplayPixelFormat(ADLDisplayInfo display, ref ADLPixelFormat pixelFormat)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ int pixelFormatInt = 0;
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, ref pixelFormatInt);
+
+ pixelFormat = (ADLPixelFormat)pixelFormatInt;
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_PixelFormat_Get));
+ }
+ return false;
+ }
+
+ public static bool SetDisplayPixelFormat(ADLDisplayInfo display, ADLPixelFormat pixelFormat)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)pixelFormat);
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_PixelFormat_Set));
+ }
+ return false;
+ }
+
+ public static bool GetDisplayColorDepth(ADLDisplayInfo display, ref ADLColorDepth colorDepth)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ int colorDepthInt = 0;
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, ref colorDepthInt);
+
+ colorDepth = (ADLColorDepth)colorDepthInt;
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_ColorDepth_Get));
+ }
+ return false;
+ }
+
+ public static bool SetDisplayColorDepth(ADLDisplayInfo display, ADLColorDepth colorDepth)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)colorDepth);
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_ColorDepth_Set));
+ }
+ return false;
+ }
+
+ public static bool GetDisplayDitherState(ADLDisplayInfo display, ref ADLDitherState ditherState)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var ditherStateInt = 0;
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, ref ditherStateInt);
+
+ ditherState = (ADLDitherState)ditherStateInt;
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_DitherState_Get));
+ }
+ return false;
+ }
+
+ public static bool SetDisplayDitherState(ADLDisplayInfo display, ADLDitherState ditherState)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)ditherState);
+
+ return CheckError(ADLRet, nameof(ADL.ADL_Display_DitherState_Set));
+ }
+ return false;
+ }
+
+ public static bool GetDisplayHDRState(ADLDisplayInfo display, ref bool supported, ref bool enabled)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var supportedInt = 0;
+ var enabledInt = 0;
+ var ADLRet = del(context, display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID, ref supportedInt, ref enabledInt);
+
+ supported = supportedInt != 0;
+ enabled = enabledInt != 0;
+
+ return CheckError(ADLRet, nameof(ADL.ADL2_Display_HDRState_Get));
+ }
+ return false;
+ }
+
+ public static bool SetDisplayHDRState(ADLDisplayInfo display, bool enabled)
+ {
+ var del = ADL.GetDelegate();
+
+ if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null)
+ {
+ var ADLRet = del(context, display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID, enabled ? 1 : 0);
+
+ return CheckError(ADLRet, nameof(ADL.ADL2_Display_HDRState_Set));
}
return false;
}
diff --git a/ColorControl/AmdDisplayInfo.cs b/ColorControl/AmdDisplayInfo.cs
new file mode 100644
index 0000000..0a93571
--- /dev/null
+++ b/ColorControl/AmdDisplayInfo.cs
@@ -0,0 +1,21 @@
+using ATI.ADL;
+using System.Collections.Generic;
+
+namespace ColorControl
+{
+ class AmdDisplayInfo
+ {
+ public ADLDisplayInfo Display { get; }
+
+ public List Values { get; }
+
+ public string InfoLine { get; }
+
+ public AmdDisplayInfo(ADLDisplayInfo display, List values, string infoLine)
+ {
+ Display = display;
+ Values = values;
+ InfoLine = infoLine;
+ }
+ }
+}
diff --git a/ColorControl/AmdPreset.cs b/ColorControl/AmdPreset.cs
index 3459c0c..e2d4050 100644
--- a/ColorControl/AmdPreset.cs
+++ b/ColorControl/AmdPreset.cs
@@ -1,6 +1,4 @@
-using NvAPIWrapper.Display;
-using NvAPIWrapper.Native.Display;
-using System;
+using System;
using System.Collections.Generic;
using System.Text;
@@ -9,12 +7,13 @@ namespace ColorControl
class AmdPreset : PresetBase
{
public bool applyColorData { get; set; }
- public ColorData colorData { get; set; }
+ public ADLColorDepth colorDepth { get; set; }
+ public ADLPixelFormat pixelFormat { get; set; }
public bool applyHDR { get; set; }
public bool HDREnabled { get; set; }
public bool toggleHDR { get; set; }
public bool applyDithering { get; set; }
- public bool ditheringEnabled { get; set; }
+ public ADLDitherState ditherState { get; set; }
public bool applyRefreshRate { get; set; }
public uint refreshRate { get; set; }
public bool primaryDisplay { get; set; }
@@ -24,7 +23,7 @@ namespace ColorControl
{
applyColorData = true;
applyDithering = false;
- ditheringEnabled = true;
+ ditherState = ADLDitherState.DRIVER_DEFAULT;
applyHDR = false;
HDREnabled = false;
toggleHDR = false;
@@ -33,12 +32,6 @@ namespace ColorControl
primaryDisplay = true;
}
- public AmdPreset(ColorData colorData) : this()
- {
- id = GetNewId();
- this.colorData = colorData;
- }
-
public AmdPreset(AmdPreset preset): this()
{
id = GetNewId();
@@ -46,15 +39,15 @@ namespace ColorControl
primaryDisplay = preset.primaryDisplay;
displayName = preset.displayName;
- var colorData = preset.colorData;
- this.colorData = new ColorData(colorData.ColorFormat, dynamicRange: colorData.DynamicRange, colorDepth: colorData.ColorDepth, colorSelectionPolicy: colorData.SelectionPolicy);
applyColorData = preset.applyColorData;
+ colorDepth = preset.colorDepth;
+ pixelFormat = preset.pixelFormat;
applyHDR = preset.applyHDR;
HDREnabled = preset.HDREnabled;
toggleHDR = preset.toggleHDR;
applyDithering = preset.applyDithering;
- ditheringEnabled = preset.ditheringEnabled;
+ ditherState = preset.ditherState;
applyRefreshRate = preset.applyRefreshRate;
refreshRate = preset.refreshRate;
}
@@ -69,28 +62,24 @@ namespace ColorControl
public static string[] GetColumnNames()
{
//return new[] { "BPC", "Format", "Dynamic range", "Toggle HDR", "Shortcut" };
- return new[] { "Display|140", "Color settings (BPC, format, dyn. range, color space)|260", "Refresh rate|100", "Dithering", "HDR", "Shortcut" };
+ return new[] { "Display|140", "Color settings (BPC, format)|260", "Refresh rate|100", "Dithering", "HDR", "Shortcut", "Apply on startup" };
}
- public List GetDisplayValues()
+ public override List GetDisplayValues(Config config = null)
{
var values = new List();
var display = string.Format("{0}", primaryDisplay ? "Primary" : displayName);
values.Add(display);
- var colorSettings = string.Format("{0}: {1}, {2}, {3}, {4}", applyColorData ? "Included" : "Excluded", colorData.ColorDepth, colorData.ColorFormat, colorData.DynamicRange, colorData.Colorimetry);
+ var colorSettings = string.Format("{0}: {1}, {2}", applyColorData ? "Included" : "Excluded", colorDepth, pixelFormat);
values.Add(colorSettings);
values.Add(string.Format("{0}: {1}Hz", applyRefreshRate ? "Included" : "Excluded", refreshRate));
- values.Add(string.Format("{0}: {1}", applyDithering ? "Included" : "Excluded", ditheringEnabled ? "Enabled" : "Disabled"));
+ values.Add(string.Format("{0}: {1}", applyDithering ? "Included" : "Excluded", ditherState));
values.Add(string.Format("{0}: {1}", applyHDR ? "Included" : "Excluded", toggleHDR ? "Toggle" : HDREnabled ? "Enabled" : "Disabled"));
-
- //values.Add(colorData.ColorDepth.ToString());
- //values.Add(colorData.ColorFormat.ToString());
- //values.Add(colorData.DynamicRange.ToString());
- //values.Add(toggleHDR.ToString());
values.Add(shortcut);
+ values.Add(string.Format("{0}", config?.AmdPresetId_ApplyOnStartup == id ? "Yes" : string.Empty));
return values;
}
@@ -99,21 +88,11 @@ namespace ColorControl
{
var presets = new List();
- presets.Add(new AmdPreset(new ColorData(ColorDataFormat.Auto, dynamicRange: ColorDataDynamicRange.Auto, colorDepth: ColorDataDepth.Default, colorSelectionPolicy: ColorDataSelectionPolicy.BestQuality)));
+ var preset = new AmdPreset();
+ preset.colorDepth = ADLColorDepth.BPC8;
+ preset.pixelFormat = ADLPixelFormat.RGB_FULL_RANGE;
- for (var dynamicRange = ColorDataDynamicRange.VESA; dynamicRange <= ColorDataDynamicRange.CEA; dynamicRange++)
- {
- presets.Add(new AmdPreset(new ColorData(ColorDataFormat.RGB, dynamicRange: dynamicRange, colorDepth: ColorDataDepth.BPC8, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- presets.Add(new AmdPreset(new ColorData(ColorDataFormat.RGB, dynamicRange: dynamicRange, colorDepth: ColorDataDepth.BPC10, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- presets.Add(new AmdPreset(new ColorData(ColorDataFormat.RGB, dynamicRange: dynamicRange, colorDepth: ColorDataDepth.BPC12, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- }
-
- for (var format = ColorDataFormat.YUV422; format <= ColorDataFormat.YUV420; format++)
- {
- presets.Add(new AmdPreset(new ColorData(format, dynamicRange: ColorDataDynamicRange.Auto, colorDepth: ColorDataDepth.BPC8, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- presets.Add(new AmdPreset(new ColorData(format, dynamicRange: ColorDataDynamicRange.Auto, colorDepth: ColorDataDepth.BPC10, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- presets.Add(new AmdPreset(new ColorData(format, dynamicRange: ColorDataDynamicRange.Auto, colorDepth: ColorDataDepth.BPC12, colorSelectionPolicy: ColorDataSelectionPolicy.User)));
- }
+ presets.Add(preset);
return presets;
}
@@ -127,7 +106,7 @@ namespace ColorControl
}
if (applyColorData)
{
- var colorSettings = string.Format("Format: {0}, {1}, {2}", colorData.ColorDepth, colorData.ColorFormat, colorData.DynamicRange);
+ var colorSettings = string.Format("Format: {0}, {1}", colorDepth, pixelFormat);
sb.Append(colorSettings);
sb.Append(" / ");
}
@@ -138,7 +117,7 @@ namespace ColorControl
}
if (applyDithering)
{
- sb.AppendFormat("Dithering: {0}", ditheringEnabled ? "Yes" : "No");
+ sb.AppendFormat("Dithering: {0}", ditherState);
sb.Append(" / ");
}
if (applyHDR)
@@ -149,38 +128,6 @@ namespace ColorControl
return sb.ToString(0, Math.Max(0, sb.Length - 3));
}
-
- public static ColorData GenerateColorData(IDictionary dictionary)
- {
- var format = ColorDataFormat.RGB;
- var dynamicRange = ColorDataDynamicRange.VESA;
- var colorDepth = ColorDataDepth.BPC8;
- var colorimetry = ColorDataColorimetry.Auto;
- var selectionPolicy = ColorDataSelectionPolicy.User;
- object value;
- if (dictionary.TryGetValue("ColorFormat", out value))
- {
- format = (ColorDataFormat)Enum.ToObject(typeof(ColorDataFormat), value);
- }
- if (dictionary.TryGetValue("ColorDepth", out value))
- {
- colorDepth = (ColorDataDepth)Enum.ToObject(typeof(ColorDataDepth), value);
- }
- if (dictionary.TryGetValue("Colorimetry", out value))
- {
- colorimetry = (ColorDataColorimetry)Enum.ToObject(typeof(ColorDataColorimetry), value);
- }
- if (dictionary.TryGetValue("DynamicRange", out value))
- {
- dynamicRange = (ColorDataDynamicRange)Enum.ToObject(typeof(ColorDataDynamicRange), value);
- }
- if (dictionary.TryGetValue("SelectionPolicy", out value))
- {
- selectionPolicy = (ColorDataSelectionPolicy)Enum.ToObject(typeof(ColorDataSelectionPolicy), value);
- }
- return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy);
- }
-
}
}
diff --git a/ColorControl/AmdService.cs b/ColorControl/AmdService.cs
index 7b5e58f..18771cb 100644
--- a/ColorControl/AmdService.cs
+++ b/ColorControl/AmdService.cs
@@ -1,86 +1,209 @@
-//using ATI.ADL;
+using ATI.ADL;
using System;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
namespace ColorControl
{
class AmdService : GraphicsService
{
- private string CurrentDisplay;
+ private ADLDisplayInfo _currentDisplay;
- public AmdService()
+ private List _presets;
+
+ private AmdPreset _lastAppliedPreset;
+
+ public AmdService(string dataPath) : base(dataPath)
{
+ LoadPresets();
+ }
+
+ public List GetPresets()
+ {
+ return _presets;
+ }
+
+ public AmdPreset GetLastAppliedPreset()
+ {
+ return _lastAppliedPreset;
+ }
+
+ private void LoadPresets()
+ {
+ _presetsFilename = Path.Combine(_dataPath, "AmdPresets.json");
+
+ if (File.Exists(_presetsFilename))
+ {
+ var json = File.ReadAllText(_presetsFilename);
+
+ _presets = _JsonDeserializer.Deserialize>(json);
+ }
+ else
+ {
+ _presets = AmdPreset.GetDefaultPresets();
+ }
+ }
+
+ private void SavePresets()
+ {
+ try
+ {
+ var json = _JsonSerializer.Serialize(_presets);
+ File.WriteAllText(_presetsFilename, json);
+ }
+ catch (Exception e)
+ {
+ Logger.Error(e.ToLogString());
+ }
+ }
+
+ public void GlobalSave()
+ {
+ SavePresets();
+ }
+
+ public bool HasDisplaysAttached()
+ {
+ try
+ {
+ return GetDisplays().Any();
+ }
+ catch (Exception)
+ {
+ return false;
+ }
}
public void SetCurrentDisplay(AmdPreset preset)
{
- CurrentDisplay = preset.displayName;
+ var displays = GetDisplays();
+ if (preset.primaryDisplay)
+ {
+ _currentDisplay = displays.FirstOrDefault();
+ }
+ else
+ {
+ _currentDisplay = displays.FirstOrDefault(x => x.DisplayName.Equals(preset.displayName));
+ }
}
- public string GetCurrentDisplay()
+ public ADLDisplayInfo GetCurrentDisplay()
{
- return CurrentDisplay;
+ if (string.IsNullOrEmpty(_currentDisplay.DisplayName))
+ {
+ _currentDisplay = GetDisplays().FirstOrDefault();
+ }
+
+ return _currentDisplay;
}
public bool ApplyPreset(AmdPreset preset, Config config)
{
SetCurrentDisplay(preset);
+ if (string.IsNullOrEmpty(_currentDisplay.DisplayName))
+ {
+ Logger.Error("Could not set current display");
+ return false;
+ }
+
+ var result = true;
+
if (preset.applyHDR)
{
- if (preset.toggleHDR || preset.HDREnabled != IsHDREnabled())
+ var hdrEnabled = IsHDREnabled();
+ if (preset.toggleHDR)
{
- ToggleHDR(config.DisplaySettingsDelay);
+ result = ADLWrapper.SetDisplayHDRState(_currentDisplay, !hdrEnabled);
}
+ else
+ {
+ result = ADLWrapper.SetDisplayHDRState(_currentDisplay, preset.HDREnabled);
+ }
+
+ //if (preset.toggleHDR || preset.HDREnabled != hdrEnabled)
+ //{
+ // ToggleHDR(config.DisplaySettingsDelay);
+ //}
}
if (preset.applyRefreshRate)
{
- SetRefreshRate(preset.refreshRate);
+ if (!SetRefreshRate(preset.refreshRate))
+ {
+ result = false;
+ }
}
if (preset.applyColorData)
{
- var display = GetCurrentDisplay();
- // TODO: ADL call to set color format, depth, space
- // ADL_Display_PixelFormat_Set
- // ADL_Display_ColorDepth_Set
-
- //var data = new ColorData(ColorDataFormat.YUV444, ColorDataColorimetry.YCC709, ColorDataDynamicRange.Auto, ColorDataDepth.BPC8, preset.colorData.SelectionPolicy, ColorDataDesktopDepth.Default);
- //display.DisplayDevice.SetColorData(preset.colorData);
+ if (!ADLWrapper.SetDisplayColorDepth(_currentDisplay, preset.colorDepth))
+ {
+ Logger.Error("Could not set color depth");
+ result = false;
+ }
+ if (preset.pixelFormat != ADLPixelFormat.UNKNOWN && !ADLWrapper.SetDisplayPixelFormat(_currentDisplay, preset.pixelFormat))
+ {
+ Logger.Error("Could not set pixel format");
+ result = false;
+ }
}
if (preset.applyDithering)
{
- SetDithering(preset.ditheringEnabled);
+ if (!SetDithering(preset.ditherState))
+ {
+ result = false;
+ }
}
- return true;
+ _lastAppliedPreset = preset;
+
+ return result;
}
- public void SetDithering(bool enabled)
+ public bool SetDithering(ADLDitherState ditherState)
{
- // TODO: ADL call to set dithering state
- // ADL_Display_DitherState_Get
+ var display = GetCurrentDisplay();
+
+ return ADLWrapper.SetDisplayDitherState(display, ditherState);
}
- public bool GetDithering()
+ public ADLDitherState GetDithering(ADLDisplayInfo display = default(ADLDisplayInfo))
{
- // TODO: ADL call to get dithering state
- // ADL_Display_DitherState_Set
- return false;
+ if (string.IsNullOrEmpty(display.DisplayName))
+ {
+ display = GetCurrentDisplay();
+ }
+
+ var ditherState = ADLDitherState.DRIVER_DEFAULT;
+
+ if (ADLWrapper.GetDisplayDitherState(display, ref ditherState))
+ {
+ return ditherState;
+ }
+
+ return ditherState;
+ }
+
+ public string GetDisplayDeviceName(ADLDisplayInfo display)
+ {
+ return Screen.PrimaryScreen.DeviceName;
}
public bool SetRefreshRate(uint refreshRate)
{
- var portrait = false;
var horizontal = 3840;
var vertical = 2160;
var display = GetCurrentDisplay();
- //ADLWrapper.GetDisplayResolution(display, ref horizontal, ref vertical);
+ ADLWrapper.GetDisplayResolution(display, ref horizontal, ref vertical);
- return SetRefreshRateInternal(display, refreshRate, portrait, horizontal, vertical);
+ var portrait = vertical > horizontal;
+
+ return SetRefreshRateInternal(GetDisplayDeviceName(display), refreshRate, portrait, horizontal, vertical);
}
public List GetAvailableRefreshRates(AmdPreset preset = null)
@@ -90,43 +213,133 @@ namespace ColorControl
SetCurrentDisplay(preset);
}
- var portrait = false;
var horizontal = 3840;
var vertical = 2160;
var display = GetCurrentDisplay();
- //ADLWrapper.GetDisplayResolution(display, ref horizontal, ref vertical);
+ ADLWrapper.GetDisplayResolution(display, ref horizontal, ref vertical);
- return GetAvailableRefreshRatesInternal(display, portrait, horizontal, vertical);
+ var portrait = vertical > horizontal;
+
+ return GetAvailableRefreshRatesInternal(GetDisplayDeviceName(display), portrait, horizontal, vertical);
}
public bool IsHDREnabled()
{
- // TODO: ADL call to get HDR state
- //var displayDevice = GetCurrentDisplay().DisplayDevice;
- //var hdr = displayDevice.HDRColorData;
- //return hdr?.HDRMode == ColorDataHDRMode.UHDA;
- return false;
+ var display = GetCurrentDisplay();
+
+ var supported = false;
+ var enabled = false;
+ ADLWrapper.GetDisplayHDRState(display, ref supported, ref enabled);
+
+ Logger.Debug($"IsHDREnabled: supported {supported}, enabled {enabled}");
+
+ return enabled;
}
- public List GetDisplays()
+ public List GetDisplays()
{
- //return ADLWrapper.GetAllDisplays();
- return null;
+ var displays = ADLWrapper.GetAllDisplays();
+
+ //if (!displays.Any())
+ //{
+ // displays.Add(new ADLDisplayInfo
+ // {
+ // DisplayName = "Dummy"
+ // });
+ //}
+
+ return displays;
}
+ public string GetFullDisplayName(ADLDisplayInfo display)
+ {
+ var name = display.DisplayName;
+
+ var screen = GetScreenForDisplay(display);
+ if (screen != null)
+ {
+ name = $"{screen.DeviceName} ({name})";
+ }
+
+ return name;
+ }
+
+ public Screen GetScreenForDisplay(ADLDisplayInfo display)
+ {
+ var index = 0;
+ foreach (var screen in Screen.AllScreens)
+ {
+ Logger.Debug($"SCREEN[{index}]: {screen.DeviceName}, {screen.DeviceFriendlyName()}, {screen.Primary}");
+ index++;
+ }
+ return Screen.AllScreens.FirstOrDefault(x => x.DeviceFriendlyName().Equals(display.DisplayName));
+ }
+
+ public List GetDisplayInfos()
+ {
+ List displays;
+ try
+ {
+ displays = GetDisplays();
+ }
+ catch (Exception e)
+ {
+ Logger.Error("Error while getting displays: " + e.ToLogString());
+ return null;
+ }
+
+ var list = new List();
+
+ foreach (var display in displays)
+ {
+ var values = new List();
+
+ var screen = GetScreenForDisplay(display);
+
+ var name = GetFullDisplayName(display);
+ values.Add(name);
+
+ var colorDepth = ADLColorDepth.UNKNOWN;
+ ADLWrapper.GetDisplayColorDepth(display, ref colorDepth);
+
+ var pixelFormat = ADLPixelFormat.UNKNOWN;
+ ADLWrapper.GetDisplayPixelFormat(display, ref pixelFormat);
+
+ var colorSettings = $"{colorDepth}, {pixelFormat}";
+ values.Add(colorSettings);
+
+ var refreshRate = GetCurrentRefreshRate(screen?.DeviceName);
+ values.Add($"{refreshRate}Hz");
+
+ var ditherState = GetDithering(display);
+ values.Add(ditherState.ToString());
+
+ var hdrEnabled = IsHDREnabled();
+ values.Add(hdrEnabled ? "Yes" : "No");
+
+ var infoLine = string.Format("{0}: {1}, {2}Hz, HDR: {3}", name, colorSettings, refreshRate, hdrEnabled ? "Yes" : "No");
+
+ var displayInfo = new AmdDisplayInfo(display, values, infoLine);
+
+ list.Add(displayInfo);
+ }
+
+ return list;
+ }
+
+
protected override void Initialize()
{
- //if (!ADLWrapper.Initialize())
- //{
- // throw new InvalidOperationException("Cannot load AMD API");
- //}
- throw new InvalidOperationException("Cannot load AMD API");
+ if (!ADLWrapper.Initialize())
+ {
+ throw new InvalidOperationException("Cannot load AMD API");
+ }
}
protected override void Uninitialize()
{
- //ADLWrapper.Uninitialze();
+ ADLWrapper.Uninitialze();
}
}
}
diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj
index 45a84c9..06b6214 100644
--- a/ColorControl/ColorControl.csproj
+++ b/ColorControl/ColorControl.csproj
@@ -27,7 +27,7 @@
ColorControl
Maassoft
0
- 1.6.0.0
+ 2.0.0.0
false
true
true
@@ -172,6 +172,11 @@
+
+
+
+
+
diff --git a/ColorControl/Config.cs b/ColorControl/Config.cs
index 951602f..dd66afe 100644
--- a/ColorControl/Config.cs
+++ b/ColorControl/Config.cs
@@ -15,6 +15,8 @@
public int NvPresetId_ApplyOnStartup { get; set; }
+ public int AmdPresetId_ApplyOnStartup { get; set; }
+
public Config()
{
DisplaySettingsDelay = 1000;
diff --git a/ColorControl/GraphicsService.cs b/ColorControl/GraphicsService.cs
index 14dd8ce..cda4856 100644
--- a/ColorControl/GraphicsService.cs
+++ b/ColorControl/GraphicsService.cs
@@ -9,11 +9,15 @@ using System.Threading;
namespace ColorControl
{
- class GraphicsService
+ class GraphicsService : ServiceBase
{
- protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
+ [DllImport("user32.dll")]
+ public static extern bool EnumDisplaySettingsA(string deviceName, int modeNum, out DEVMODEA devMode);
- public GraphicsService()
+ const int ENUM_CURRENT_SETTINGS = -1;
+ const int ENUM_REGISTRY_SETTINGS = -2;
+
+ public GraphicsService(string dataPath) : base(dataPath)
{
Initialize();
}
@@ -23,16 +27,6 @@ namespace ColorControl
Uninitialize();
}
- protected virtual void Initialize()
- {
-
- }
-
- protected virtual void Uninitialize()
- {
-
- }
-
protected void ToggleHDR(int delay = 1000)
{
Process.Start("ms-settings:display");
@@ -105,5 +99,15 @@ namespace ColorControl
return list;
}
+ protected uint GetCurrentRefreshRate(string displayName)
+ {
+ DEVMODEA devMode;
+ // NativeMethods defines modeNum as an 'uint' but we need to pass '-1'
+ if (EnumDisplaySettingsA(displayName, ENUM_CURRENT_SETTINGS, out devMode))
+ {
+ return devMode.dmDisplayFrequency;
+ }
+ return 0;
+ }
}
}
diff --git a/ColorControl/LgPreset.cs b/ColorControl/LgPreset.cs
index e7f59a4..c5de34f 100644
--- a/ColorControl/LgPreset.cs
+++ b/ColorControl/LgPreset.cs
@@ -41,7 +41,7 @@ namespace ColorControl
return new List() { "Name", "App|200", "Steps|400", "Shortcut" };
}
- public List GetDisplayValues()
+ public override List GetDisplayValues(Config config = null)
{
var values = new List();
diff --git a/ColorControl/LgService.cs b/ColorControl/LgService.cs
index 240e2b4..3709ad5 100644
--- a/ColorControl/LgService.cs
+++ b/ColorControl/LgService.cs
@@ -32,6 +32,9 @@ namespace ColorControl
public LgServiceConfig Config { get; private set; }
+ private List _lgPresets;
+ private string _lgPresetsFilename;
+
private LgTvApi _lgTvApi;
private string _dataDir;
private string _configFilename;
@@ -40,18 +43,24 @@ namespace ColorControl
private PnpDev _selectedDevice;
private string _rcButtonsFilename;
private List _remoteControlButtons;
+ private List _lgApps = new List();
+
+ private JavaScriptSerializer _JsonSerializer = new JavaScriptSerializer();
private JavaScriptSerializer _JsonDeserializer = new JavaScriptSerializer();
- private Dictionary _invokableActions = new Dictionary();
+ private Dictionary> _invokableActions = new Dictionary>();
public LgService(string dataDir, bool allowPowerOn)
{
_dataDir = dataDir;
_allowPowerOn = allowPowerOn;
- _invokableActions.Add("WOL", new Action(WakeSelectedDevice));
+ _invokableActions.Add("WOL", new Func(WakeSelectedDevice));
+
+ LgPreset.LgApps = _lgApps;
LoadConfig();
+ LoadPresets();
LoadRemoteControlButtons();
//foreach (var screen in Screen.AllScreens)
@@ -63,7 +72,7 @@ namespace ColorControl
// }
//}
- RefreshDevices(afterStartUp: true);
+ var _ = RefreshDevices(afterStartUp: true);
}
~LgService()
@@ -74,9 +83,60 @@ namespace ColorControl
public void GlobalSave()
{
SaveConfig();
+ SavePresets();
SaveRemoteControlButtons();
}
+ public List GetPresets()
+ {
+ return _lgPresets;
+ }
+
+ public LgPreset CreateNewPreset()
+ {
+ var preset = new LgPreset();
+ var name = "New preset";
+ string fullname;
+ var number = 1;
+ do
+ {
+ fullname = $"{name} ({number})";
+ number++;
+ } while (_lgPresets.Any(x => x.name.Equals(fullname)));
+
+ preset.name = fullname;
+
+ return preset;
+ }
+
+ private void LoadPresets()
+ {
+ _lgPresetsFilename = Path.Combine(_dataDir, "LgPresets.json");
+ var toCopy = Path.Combine(Directory.GetCurrentDirectory(), "LgPresets.json");
+ if (!File.Exists(_lgPresetsFilename) && File.Exists(toCopy))
+ {
+ try
+ {
+ File.Copy(toCopy, _lgPresetsFilename);
+ }
+ catch (Exception e)
+ {
+ Logger.Error($"Error while copying {toCopy} to {_lgPresetsFilename}: {e.Message}");
+ }
+ }
+
+ if (File.Exists(_lgPresetsFilename))
+ {
+ var json = File.ReadAllText(_lgPresetsFilename);
+
+ _lgPresets = _JsonDeserializer.Deserialize>(json);
+ }
+ else
+ {
+ _lgPresets = new List();
+ }
+ }
+
private void LoadConfig()
{
_configFilename = Path.Combine(_dataDir, "LgConfig.json");
@@ -115,7 +175,7 @@ namespace ColorControl
return _remoteControlButtons;
}
- public Dictionary GetInvokableActions()
+ public Dictionary> GetInvokableActions()
{
return _invokableActions;
}
@@ -166,6 +226,19 @@ namespace ColorControl
return preset;
}
+ private void SavePresets()
+ {
+ try
+ {
+ var json = _JsonSerializer.Serialize(_lgPresets);
+ File.WriteAllText(_lgPresetsFilename, json);
+ }
+ catch (Exception e)
+ {
+ Logger.Error(e.ToLogString());
+ }
+ }
+
private void SaveConfig()
{
var json = JsonConvert.SerializeObject(Config);
@@ -199,11 +272,11 @@ namespace ColorControl
{
if (Config.PowerOnAfterStartup && _allowPowerOn)
{
- WakeAndConnectToSelectedDevice(0);
+ var _ = WakeAndConnectToSelectedDeviceWithRetries();
}
else
{
- ConnectToSelectedDevice();
+ var _ = ConnectToSelectedDevice();
}
}
}
@@ -225,6 +298,8 @@ namespace ColorControl
{
DisposeConnection();
_lgTvApi = await LgTvApi.CreateLgTvApi(SelectedDevice.IpAddress, retries);
+
+ //_lgTvApi.GetServiceList();
return _lgTvApi != null;
}
catch (Exception ex)
@@ -376,23 +451,25 @@ namespace ColorControl
return await _lgTvApi.GetMouse();
}
- public async Task> RefreshApps(bool force = false)
+ public async Task RefreshApps(bool force = false)
{
if (SelectedDevice == null)
{
Logger.Debug("Cannot refresh apps: no device has been selected");
- return null;
}
if (!await Connected(force))
{
Logger.Debug("Cannot refresh apps: no connection could be made");
- return null;
}
- var list = await _lgTvApi.GetApps(force);
+ _lgApps.Clear();
+ _lgApps.AddRange(await _lgTvApi.GetApps(force));
+ }
- return list.ToList();
+ public List GetApps()
+ {
+ return _lgApps;
}
internal void DisposeConnection()
@@ -415,34 +492,64 @@ namespace ColorControl
return true;
}
- internal void WakeSelectedDevice()
+ internal bool WakeSelectedDevice()
{
- WakeSelectedDevice(SelectedDevice?.MacAddress ?? Config.PreferredMacAddress);
+ return WakeSelectedDevice(SelectedDevice?.MacAddress ?? Config.PreferredMacAddress);
}
- internal void WakeSelectedDevice(string macAddress)
+ internal bool WakeSelectedDevice(string macAddress)
{
+ var result = false;
+
macAddress = string.IsNullOrEmpty(macAddress) ? SelectedDevice?.MacAddress : macAddress;
if (macAddress != null)
{
- WOL.WakeFunction(macAddress, !Config.UseAlternateWol);
+ result = WOL.WakeFunction(macAddress, Config.UseOldNpcapWol);
_justWokeUp = true;
}
else
{
Logger.Debug("Cannot wake device: no device has been selected or there is no preferred MAC-address stored in the configuration");
}
+
+ return result;
}
internal void WakeAfterResume()
{
if (Config.PowerOnAfterResume)
{
- WakeAndConnectToSelectedDevice(Config.PowerOnDelayAfterResume);
+ var _ = WakeAndConnectToSelectedDeviceWithRetries();
}
}
- private async Task WakeAndConnectToSelectedDevice(int wakeDelay = 5000, int connectDelay = 1000)
+ private async Task WakeAndConnectToSelectedDeviceWithRetries()
+ {
+ var wakeDelay = 0;
+ var maxRetries = Config.PowerOnRetries <= 1 ? 5 : Config.PowerOnRetries;
+
+ var result = false;
+ for (var retry = 0; retry < maxRetries && !result; retry++)
+ {
+ Logger.Debug($"WakeAndConnectToSelectedDeviceWithRetries: attempt {retry + 1} of {maxRetries}...");
+
+ var ms = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+ result = await WakeAndConnectToSelectedDevice(retry == 0 ? wakeDelay : 0);
+ ms = DateTimeOffset.Now.ToUnixTimeMilliseconds() - ms;
+ if (!result)
+ {
+ var delay = 2000 - ms;
+ if (delay > 0)
+ {
+ await Task.Delay((int)delay);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private async Task WakeAndConnectToSelectedDevice(int wakeDelay = 5000, int connectDelay = 500)
{
try
{
@@ -456,9 +563,17 @@ namespace ColorControl
//}
await Task.Delay(wakeDelay);
- WakeSelectedDevice();
+ var result = WakeSelectedDevice();
+ if (!result)
+ {
+ Logger.Debug("WOL failed");
+ return false;
+ }
+ Logger.Debug("WOL succeeded");
await Task.Delay(connectDelay);
- return await ConnectToSelectedDevice();
+ result = await ConnectToSelectedDevice();
+ Logger.Debug("Connect succeeded: " + result);
+ return result;
}
catch (Exception e)
{
diff --git a/ColorControl/LgServiceConfig.cs b/ColorControl/LgServiceConfig.cs
index 7a451d0..3a00d18 100644
--- a/ColorControl/LgServiceConfig.cs
+++ b/ColorControl/LgServiceConfig.cs
@@ -12,16 +12,19 @@
public int PowerOnDelayAfterResume { get; set; }
+ public int PowerOnRetries { get; set; }
+
public string PreferredMacAddress { get; set; }
public string DeviceSearchKey { get; set; }
- public bool UseAlternateWol { get; set; }
+ public bool UseOldNpcapWol { get; set; }
public LgServiceConfig()
{
PowerOnDelayAfterResume = 5000;
DeviceSearchKey = "[LG]";
+ PowerOnRetries = 10;
}
}
}
diff --git a/ColorControl/MainForm.Designer.cs b/ColorControl/MainForm.Designer.cs
index af1296b..b200ca7 100644
--- a/ColorControl/MainForm.Designer.cs
+++ b/ColorControl/MainForm.Designer.cs
@@ -70,13 +70,40 @@
this.btnApply = new System.Windows.Forms.Button();
this.lvNvPresets = new System.Windows.Forms.ListView();
this.tabAMD = new System.Windows.Forms.TabPage();
+ this.btnAddAmd = new System.Windows.Forms.Button();
this.lblErrorAMD = new System.Windows.Forms.Label();
+ this.btnDeleteAmd = new System.Windows.Forms.Button();
+ this.btnCloneAmd = new System.Windows.Forms.Button();
+ this.btnSetAmdShortcut = new System.Windows.Forms.Button();
+ this.lblAmdShortcut = new System.Windows.Forms.Label();
+ this.edtAmdShortcut = new System.Windows.Forms.TextBox();
+ this.btnChangeAmd = new System.Windows.Forms.Button();
+ this.mnuAmdPresets = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.miAmdApply = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdPresetApplyOnStartup = new System.Windows.Forms.ToolStripMenuItem();
+ this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
+ this.mnuAmdDisplay = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdPrimaryDisplay = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnuAmdColorSettings = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdColorSettingsIncluded = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnuAmdRefreshRate = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdRefreshRateIncluded = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnuAmdDithering = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdDitheringIncluded = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnuAmdHDR = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdHDRIncluded = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdHDRToggle = new System.Windows.Forms.ToolStripMenuItem();
+ this.miAmdHDREnabled = new System.Windows.Forms.ToolStripMenuItem();
+ this.btnApplyAmd = new System.Windows.Forms.Button();
+ this.lvAmdPresets = new System.Windows.Forms.ListView();
this.tabLG = new System.Windows.Forms.TabPage();
this.btnLGRemoteControl = new System.Windows.Forms.Button();
this.btnLgDeviceFilterRefresh = new System.Windows.Forms.Button();
this.clbLgPower = new System.Windows.Forms.CheckedListBox();
this.btnLgAddButton = new System.Windows.Forms.Button();
this.mnuLgButtons = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.mnuLgRcButtons = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnuLgActions = new System.Windows.Forms.ToolStripMenuItem();
this.label3 = new System.Windows.Forms.Label();
this.cbxLgDevices = new System.Windows.Forms.ComboBox();
this.btnLgRefreshApps = new System.Windows.Forms.Button();
@@ -109,14 +136,14 @@
this.btnSetShortcutScreenSaver = new System.Windows.Forms.Button();
this.label11 = new System.Windows.Forms.Label();
this.edtBlankScreenSaverShortcut = new System.Windows.Forms.TextBox();
- this.label10 = new System.Windows.Forms.Label();
+ this.lblFixChromeFontsDescription = new System.Windows.Forms.Label();
this.chkFixChromeFonts = new System.Windows.Forms.CheckBox();
this.grpLGOptions = new System.Windows.Forms.GroupBox();
- this.chkLgAlternateWolMechanism = new System.Windows.Forms.CheckBox();
+ this.chkLgOldWolMechanism = new System.Windows.Forms.CheckBox();
this.btnLGTestPower = new System.Windows.Forms.Button();
- this.label9 = new System.Windows.Forms.Label();
- this.edtLgPowerOnAfterResumeDelay = new System.Windows.Forms.NumericUpDown();
- this.label8 = new System.Windows.Forms.Label();
+ this.lblLgMaxPowerOnRetriesDescription = new System.Windows.Forms.Label();
+ this.edtLgMaxPowerOnRetries = new System.Windows.Forms.NumericUpDown();
+ this.lblLgMaxPowerOnRetries = new System.Windows.Forms.Label();
this.grpHDROptions = new System.Windows.Forms.GroupBox();
this.edtDelayDisplaySettings = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
@@ -135,12 +162,11 @@
this.lbPlugins = new System.Windows.Forms.ListBox();
this.label7 = new System.Windows.Forms.Label();
this.lblInfo = new System.Windows.Forms.Label();
- this.mnuLgRcButtons = new System.Windows.Forms.ToolStripMenuItem();
- this.mnuLgActions = new System.Windows.Forms.ToolStripMenuItem();
this.tcMain.SuspendLayout();
this.tabNVIDIA.SuspendLayout();
this.mnuNvPresets.SuspendLayout();
this.tabAMD.SuspendLayout();
+ this.mnuAmdPresets.SuspendLayout();
this.tabLG.SuspendLayout();
this.mnuLgButtons.SuspendLayout();
this.tabOptions.SuspendLayout();
@@ -148,7 +174,7 @@
((System.ComponentModel.ISupportInitialize)(this.pbGradient)).BeginInit();
this.grpMiscellaneousOptions.SuspendLayout();
this.grpLGOptions.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.edtLgPowerOnAfterResumeDelay)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.edtLgMaxPowerOnRetries)).BeginInit();
this.grpHDROptions.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.edtDelayDisplaySettings)).BeginInit();
this.grpGeneralOptions.SuspendLayout();
@@ -310,7 +336,7 @@
this.miNvApply.Name = "miNvApply";
this.miNvApply.Size = new System.Drawing.Size(162, 22);
this.miNvApply.Text = "Apply";
- this.miNvApply.Click += new System.EventHandler(this.miNvApply_Click);
+ this.miNvApply.Click += new System.EventHandler(this.btnApply_Click);
//
// miNvPresetApplyOnStartup
//
@@ -540,11 +566,20 @@
this.lvNvPresets.UseCompatibleStateImageBehavior = false;
this.lvNvPresets.View = System.Windows.Forms.View.Details;
this.lvNvPresets.SelectedIndexChanged += new System.EventHandler(this.lvNvPresets_SelectedIndexChanged);
- this.lvNvPresets.DoubleClick += new System.EventHandler(this.lvNvPresets_DoubleClick);
+ this.lvNvPresets.DoubleClick += new System.EventHandler(this.btnApply_Click);
//
// tabAMD
//
+ this.tabAMD.Controls.Add(this.btnAddAmd);
this.tabAMD.Controls.Add(this.lblErrorAMD);
+ this.tabAMD.Controls.Add(this.btnDeleteAmd);
+ this.tabAMD.Controls.Add(this.btnCloneAmd);
+ this.tabAMD.Controls.Add(this.btnSetAmdShortcut);
+ this.tabAMD.Controls.Add(this.lblAmdShortcut);
+ this.tabAMD.Controls.Add(this.edtAmdShortcut);
+ this.tabAMD.Controls.Add(this.btnChangeAmd);
+ this.tabAMD.Controls.Add(this.btnApplyAmd);
+ this.tabAMD.Controls.Add(this.lvAmdPresets);
this.tabAMD.Location = new System.Drawing.Point(4, 22);
this.tabAMD.Name = "tabAMD";
this.tabAMD.Padding = new System.Windows.Forms.Padding(3);
@@ -553,16 +588,256 @@
this.tabAMD.Text = "AMD controller";
this.tabAMD.UseVisualStyleBackColor = true;
//
+ // btnAddAmd
+ //
+ this.btnAddAmd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnAddAmd.Location = new System.Drawing.Point(574, 417);
+ this.btnAddAmd.Name = "btnAddAmd";
+ this.btnAddAmd.Size = new System.Drawing.Size(75, 23);
+ this.btnAddAmd.TabIndex = 18;
+ this.btnAddAmd.Text = "Add";
+ this.btnAddAmd.UseVisualStyleBackColor = true;
+ this.btnAddAmd.Click += new System.EventHandler(this.btnAddAmd_Click);
+ //
// lblErrorAMD
//
this.lblErrorAMD.AutoSize = true;
- this.lblErrorAMD.Location = new System.Drawing.Point(6, 3);
+ this.lblErrorAMD.Location = new System.Drawing.Point(6, 6);
this.lblErrorAMD.Name = "lblErrorAMD";
this.lblErrorAMD.Size = new System.Drawing.Size(50, 13);
this.lblErrorAMD.TabIndex = 8;
this.lblErrorAMD.Text = "ErrorText";
this.lblErrorAMD.Visible = false;
//
+ // btnDeleteAmd
+ //
+ this.btnDeleteAmd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnDeleteAmd.Enabled = false;
+ this.btnDeleteAmd.Location = new System.Drawing.Point(493, 417);
+ this.btnDeleteAmd.Name = "btnDeleteAmd";
+ this.btnDeleteAmd.Size = new System.Drawing.Size(75, 23);
+ this.btnDeleteAmd.TabIndex = 17;
+ this.btnDeleteAmd.Text = "Delete";
+ this.btnDeleteAmd.UseVisualStyleBackColor = true;
+ this.btnDeleteAmd.Click += new System.EventHandler(this.btnDeleteAmd_Click);
+ //
+ // btnCloneAmd
+ //
+ this.btnCloneAmd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnCloneAmd.Enabled = false;
+ this.btnCloneAmd.Location = new System.Drawing.Point(412, 417);
+ this.btnCloneAmd.Name = "btnCloneAmd";
+ this.btnCloneAmd.Size = new System.Drawing.Size(75, 23);
+ this.btnCloneAmd.TabIndex = 16;
+ this.btnCloneAmd.Text = "Clone";
+ this.btnCloneAmd.UseVisualStyleBackColor = true;
+ this.btnCloneAmd.Click += new System.EventHandler(this.btnCloneAmd_Click);
+ //
+ // btnSetAmdShortcut
+ //
+ this.btnSetAmdShortcut.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnSetAmdShortcut.Enabled = false;
+ this.btnSetAmdShortcut.Location = new System.Drawing.Point(372, 417);
+ this.btnSetAmdShortcut.Name = "btnSetAmdShortcut";
+ this.btnSetAmdShortcut.Size = new System.Drawing.Size(34, 23);
+ this.btnSetAmdShortcut.TabIndex = 15;
+ this.btnSetAmdShortcut.Text = "Set";
+ this.btnSetAmdShortcut.UseVisualStyleBackColor = true;
+ this.btnSetAmdShortcut.Click += new System.EventHandler(this.btnSetAmdShortcut_Click);
+ //
+ // lblAmdShortcut
+ //
+ this.lblAmdShortcut.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.lblAmdShortcut.AutoSize = true;
+ this.lblAmdShortcut.Location = new System.Drawing.Point(168, 422);
+ this.lblAmdShortcut.Name = "lblAmdShortcut";
+ this.lblAmdShortcut.Size = new System.Drawing.Size(50, 13);
+ this.lblAmdShortcut.TabIndex = 14;
+ this.lblAmdShortcut.Text = "Shortcut:";
+ //
+ // edtAmdShortcut
+ //
+ this.edtAmdShortcut.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.edtAmdShortcut.Enabled = false;
+ this.edtAmdShortcut.Location = new System.Drawing.Point(224, 419);
+ this.edtAmdShortcut.Name = "edtAmdShortcut";
+ this.edtAmdShortcut.ReadOnly = true;
+ this.edtAmdShortcut.Size = new System.Drawing.Size(142, 20);
+ this.edtAmdShortcut.TabIndex = 13;
+ this.edtAmdShortcut.TextChanged += new System.EventHandler(this.edtAmdShortcut_TextChanged);
+ this.edtAmdShortcut.KeyDown += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyDown);
+ this.edtAmdShortcut.KeyUp += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyUp);
+ //
+ // btnChangeAmd
+ //
+ this.btnChangeAmd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnChangeAmd.ContextMenuStrip = this.mnuAmdPresets;
+ this.btnChangeAmd.Enabled = false;
+ this.btnChangeAmd.Location = new System.Drawing.Point(87, 417);
+ this.btnChangeAmd.Name = "btnChangeAmd";
+ this.btnChangeAmd.Size = new System.Drawing.Size(75, 23);
+ this.btnChangeAmd.TabIndex = 12;
+ this.btnChangeAmd.Text = "Change...";
+ this.btnChangeAmd.UseVisualStyleBackColor = true;
+ this.btnChangeAmd.Click += new System.EventHandler(this.btnChangeAmd_Click);
+ //
+ // mnuAmdPresets
+ //
+ this.mnuAmdPresets.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.mnuAmdPresets.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdApply,
+ this.miAmdPresetApplyOnStartup,
+ this.toolStripSeparator2,
+ this.mnuAmdDisplay,
+ this.mnuAmdColorSettings,
+ this.mnuAmdRefreshRate,
+ this.mnuAmdDithering,
+ this.mnuAmdHDR});
+ this.mnuAmdPresets.Name = "mnuNvPresets";
+ this.mnuAmdPresets.Size = new System.Drawing.Size(163, 164);
+ this.mnuAmdPresets.Opening += new System.ComponentModel.CancelEventHandler(this.mnuAmdPresets_Opening);
+ //
+ // miAmdApply
+ //
+ this.miAmdApply.Name = "miAmdApply";
+ this.miAmdApply.Size = new System.Drawing.Size(162, 22);
+ this.miAmdApply.Text = "Apply";
+ this.miAmdApply.Click += new System.EventHandler(this.btnApplyAmd_Click);
+ //
+ // miAmdPresetApplyOnStartup
+ //
+ this.miAmdPresetApplyOnStartup.CheckOnClick = true;
+ this.miAmdPresetApplyOnStartup.Name = "miAmdPresetApplyOnStartup";
+ this.miAmdPresetApplyOnStartup.Size = new System.Drawing.Size(162, 22);
+ this.miAmdPresetApplyOnStartup.Text = "Apply on startup";
+ this.miAmdPresetApplyOnStartup.Click += new System.EventHandler(this.miAmdPresetApplyOnStartup_Click);
+ //
+ // toolStripSeparator2
+ //
+ this.toolStripSeparator2.Name = "toolStripSeparator2";
+ this.toolStripSeparator2.Size = new System.Drawing.Size(159, 6);
+ //
+ // mnuAmdDisplay
+ //
+ this.mnuAmdDisplay.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdPrimaryDisplay});
+ this.mnuAmdDisplay.Name = "mnuAmdDisplay";
+ this.mnuAmdDisplay.Size = new System.Drawing.Size(162, 22);
+ this.mnuAmdDisplay.Text = "Display";
+ //
+ // miAmdPrimaryDisplay
+ //
+ this.miAmdPrimaryDisplay.Name = "miAmdPrimaryDisplay";
+ this.miAmdPrimaryDisplay.Size = new System.Drawing.Size(155, 22);
+ this.miAmdPrimaryDisplay.Text = "Primary display";
+ this.miAmdPrimaryDisplay.Click += new System.EventHandler(this.displayMenuItemAmd_Click);
+ //
+ // mnuAmdColorSettings
+ //
+ this.mnuAmdColorSettings.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdColorSettingsIncluded});
+ this.mnuAmdColorSettings.Name = "mnuAmdColorSettings";
+ this.mnuAmdColorSettings.Size = new System.Drawing.Size(162, 22);
+ this.mnuAmdColorSettings.Text = "Color settings";
+ //
+ // miAmdColorSettingsIncluded
+ //
+ this.miAmdColorSettingsIncluded.Name = "miAmdColorSettingsIncluded";
+ this.miAmdColorSettingsIncluded.Size = new System.Drawing.Size(120, 22);
+ this.miAmdColorSettingsIncluded.Text = "Included";
+ this.miAmdColorSettingsIncluded.Click += new System.EventHandler(this.miAmdColorSettingsIncluded_Click);
+ //
+ // mnuAmdRefreshRate
+ //
+ this.mnuAmdRefreshRate.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdRefreshRateIncluded});
+ this.mnuAmdRefreshRate.Name = "mnuAmdRefreshRate";
+ this.mnuAmdRefreshRate.Size = new System.Drawing.Size(162, 22);
+ this.mnuAmdRefreshRate.Text = "Refresh Rate";
+ //
+ // miAmdRefreshRateIncluded
+ //
+ this.miAmdRefreshRateIncluded.Name = "miAmdRefreshRateIncluded";
+ this.miAmdRefreshRateIncluded.Size = new System.Drawing.Size(120, 22);
+ this.miAmdRefreshRateIncluded.Text = "Included";
+ this.miAmdRefreshRateIncluded.Click += new System.EventHandler(this.miAmdRefreshRateIncluded_Click);
+ //
+ // mnuAmdDithering
+ //
+ this.mnuAmdDithering.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdDitheringIncluded});
+ this.mnuAmdDithering.Name = "mnuAmdDithering";
+ this.mnuAmdDithering.Size = new System.Drawing.Size(162, 22);
+ this.mnuAmdDithering.Text = "Dithering";
+ //
+ // miAmdDitheringIncluded
+ //
+ this.miAmdDitheringIncluded.Name = "miAmdDitheringIncluded";
+ this.miAmdDitheringIncluded.Size = new System.Drawing.Size(120, 22);
+ this.miAmdDitheringIncluded.Text = "Included";
+ this.miAmdDitheringIncluded.Click += new System.EventHandler(this.miAmdDitheringIncluded_Click);
+ //
+ // mnuAmdHDR
+ //
+ this.mnuAmdHDR.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.miAmdHDRIncluded,
+ this.miAmdHDRToggle,
+ this.miAmdHDREnabled});
+ this.mnuAmdHDR.Name = "mnuAmdHDR";
+ this.mnuAmdHDR.Size = new System.Drawing.Size(162, 22);
+ this.mnuAmdHDR.Text = "HDR";
+ //
+ // miAmdHDRIncluded
+ //
+ this.miAmdHDRIncluded.Name = "miAmdHDRIncluded";
+ this.miAmdHDRIncluded.Size = new System.Drawing.Size(136, 22);
+ this.miAmdHDRIncluded.Text = "Included";
+ this.miAmdHDRIncluded.Click += new System.EventHandler(this.miAmdHDRIncluded_Click);
+ //
+ // miAmdHDRToggle
+ //
+ this.miAmdHDRToggle.Name = "miAmdHDRToggle";
+ this.miAmdHDRToggle.Size = new System.Drawing.Size(136, 22);
+ this.miAmdHDRToggle.Text = "Toggle HDR";
+ this.miAmdHDRToggle.Click += new System.EventHandler(this.miAmdHDRToggle_Click);
+ //
+ // miAmdHDREnabled
+ //
+ this.miAmdHDREnabled.Name = "miAmdHDREnabled";
+ this.miAmdHDREnabled.Size = new System.Drawing.Size(136, 22);
+ this.miAmdHDREnabled.Text = "Enabled";
+ this.miAmdHDREnabled.Click += new System.EventHandler(this.miAmdHDREnabled_Click);
+ //
+ // btnApplyAmd
+ //
+ this.btnApplyAmd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btnApplyAmd.Enabled = false;
+ this.btnApplyAmd.Location = new System.Drawing.Point(6, 417);
+ this.btnApplyAmd.Name = "btnApplyAmd";
+ this.btnApplyAmd.Size = new System.Drawing.Size(75, 23);
+ this.btnApplyAmd.TabIndex = 11;
+ this.btnApplyAmd.Text = "Apply";
+ this.btnApplyAmd.UseVisualStyleBackColor = true;
+ this.btnApplyAmd.Click += new System.EventHandler(this.btnApplyAmd_Click);
+ //
+ // lvAmdPresets
+ //
+ this.lvAmdPresets.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.lvAmdPresets.ContextMenuStrip = this.mnuAmdPresets;
+ this.lvAmdPresets.FullRowSelect = true;
+ this.lvAmdPresets.HideSelection = false;
+ this.lvAmdPresets.Location = new System.Drawing.Point(6, 6);
+ this.lvAmdPresets.MultiSelect = false;
+ this.lvAmdPresets.Name = "lvAmdPresets";
+ this.lvAmdPresets.Size = new System.Drawing.Size(829, 405);
+ this.lvAmdPresets.TabIndex = 10;
+ this.lvAmdPresets.UseCompatibleStateImageBehavior = false;
+ this.lvAmdPresets.View = System.Windows.Forms.View.Details;
+ this.lvAmdPresets.SelectedIndexChanged += new System.EventHandler(this.lvAmdPresets_SelectedIndexChanged);
+ this.lvAmdPresets.DoubleClick += new System.EventHandler(this.btnApplyAmd_Click);
+ //
// tabLG
//
this.tabLG.Controls.Add(this.btnLGRemoteControl);
@@ -658,7 +933,19 @@
this.mnuLgRcButtons,
this.mnuLgActions});
this.mnuLgButtons.Name = "mnuLgButtons";
- this.mnuLgButtons.Size = new System.Drawing.Size(181, 70);
+ this.mnuLgButtons.Size = new System.Drawing.Size(116, 48);
+ //
+ // mnuLgRcButtons
+ //
+ this.mnuLgRcButtons.Name = "mnuLgRcButtons";
+ this.mnuLgRcButtons.Size = new System.Drawing.Size(115, 22);
+ this.mnuLgRcButtons.Text = "Buttons";
+ //
+ // mnuLgActions
+ //
+ this.mnuLgActions.Name = "mnuLgActions";
+ this.mnuLgActions.Size = new System.Drawing.Size(115, 22);
+ this.mnuLgActions.Text = "Actions";
//
// label3
//
@@ -844,8 +1131,9 @@
this.edtShortcutLg.ReadOnly = true;
this.edtShortcutLg.Size = new System.Drawing.Size(200, 20);
this.edtShortcutLg.TabIndex = 11;
+ this.edtShortcutLg.TextChanged += new System.EventHandler(this.edtShortcutLg_TextChanged);
this.edtShortcutLg.KeyDown += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyDown);
- this.edtShortcutLg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.edtShortcut_KeyPress);
+ this.edtShortcutLg.KeyUp += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyUp);
//
// btnApplyLg
//
@@ -978,7 +1266,7 @@
this.grpMiscellaneousOptions.Controls.Add(this.btnSetShortcutScreenSaver);
this.grpMiscellaneousOptions.Controls.Add(this.label11);
this.grpMiscellaneousOptions.Controls.Add(this.edtBlankScreenSaverShortcut);
- this.grpMiscellaneousOptions.Controls.Add(this.label10);
+ this.grpMiscellaneousOptions.Controls.Add(this.lblFixChromeFontsDescription);
this.grpMiscellaneousOptions.Controls.Add(this.chkFixChromeFonts);
this.grpMiscellaneousOptions.Location = new System.Drawing.Point(6, 309);
this.grpMiscellaneousOptions.Name = "grpMiscellaneousOptions";
@@ -1016,14 +1304,14 @@
this.edtBlankScreenSaverShortcut.KeyDown += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyDown);
this.edtBlankScreenSaverShortcut.KeyUp += new System.Windows.Forms.KeyEventHandler(this.edtShortcut_KeyUp);
//
- // label10
+ // lblFixChromeFontsDescription
//
- this.label10.AutoSize = true;
- this.label10.Location = new System.Drawing.Point(3, 39);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(373, 13);
- this.label10.TabIndex = 6;
- this.label10.Text = "This will add the parameter --disable-lcd-text to Chrome and requires elevation.";
+ this.lblFixChromeFontsDescription.AutoSize = true;
+ this.lblFixChromeFontsDescription.Location = new System.Drawing.Point(3, 39);
+ this.lblFixChromeFontsDescription.Name = "lblFixChromeFontsDescription";
+ this.lblFixChromeFontsDescription.Size = new System.Drawing.Size(373, 13);
+ this.lblFixChromeFontsDescription.TabIndex = 6;
+ this.lblFixChromeFontsDescription.Text = "This will add the parameter --disable-lcd-text to Chrome and requires elevation.";
//
// chkFixChromeFonts
//
@@ -1038,11 +1326,11 @@
//
// grpLGOptions
//
- this.grpLGOptions.Controls.Add(this.chkLgAlternateWolMechanism);
+ this.grpLGOptions.Controls.Add(this.chkLgOldWolMechanism);
this.grpLGOptions.Controls.Add(this.btnLGTestPower);
- this.grpLGOptions.Controls.Add(this.label9);
- this.grpLGOptions.Controls.Add(this.edtLgPowerOnAfterResumeDelay);
- this.grpLGOptions.Controls.Add(this.label8);
+ this.grpLGOptions.Controls.Add(this.lblLgMaxPowerOnRetriesDescription);
+ this.grpLGOptions.Controls.Add(this.edtLgMaxPowerOnRetries);
+ this.grpLGOptions.Controls.Add(this.lblLgMaxPowerOnRetries);
this.grpLGOptions.Location = new System.Drawing.Point(6, 196);
this.grpLGOptions.Name = "grpLGOptions";
this.grpLGOptions.Size = new System.Drawing.Size(403, 107);
@@ -1050,16 +1338,16 @@
this.grpLGOptions.TabStop = false;
this.grpLGOptions.Text = "LG controller";
//
- // chkLgAlternateWolMechanism
+ // chkLgOldWolMechanism
//
- this.chkLgAlternateWolMechanism.AutoSize = true;
- this.chkLgAlternateWolMechanism.Location = new System.Drawing.Point(158, 72);
- this.chkLgAlternateWolMechanism.Name = "chkLgAlternateWolMechanism";
- this.chkLgAlternateWolMechanism.Size = new System.Drawing.Size(173, 17);
- this.chkLgAlternateWolMechanism.TabIndex = 7;
- this.chkLgAlternateWolMechanism.Text = "Use alternate WOL mechanism";
- this.chkLgAlternateWolMechanism.UseVisualStyleBackColor = true;
- this.chkLgAlternateWolMechanism.CheckedChanged += new System.EventHandler(this.chkLgAlternateWolMechanism_CheckedChanged);
+ this.chkLgOldWolMechanism.AutoSize = true;
+ this.chkLgOldWolMechanism.Location = new System.Drawing.Point(158, 72);
+ this.chkLgOldWolMechanism.Name = "chkLgOldWolMechanism";
+ this.chkLgOldWolMechanism.Size = new System.Drawing.Size(187, 17);
+ this.chkLgOldWolMechanism.TabIndex = 7;
+ this.chkLgOldWolMechanism.Text = "Use old WOL mechanism (Npcap)";
+ this.chkLgOldWolMechanism.UseVisualStyleBackColor = true;
+ this.chkLgOldWolMechanism.CheckedChanged += new System.EventHandler(this.chkLgAlternateWolMechanism_CheckedChanged);
//
// btnLGTestPower
//
@@ -1071,43 +1359,39 @@
this.btnLGTestPower.UseVisualStyleBackColor = true;
this.btnLGTestPower.Click += new System.EventHandler(this.btnLGTestPower_Click);
//
- // label9
+ // lblLgMaxPowerOnRetriesDescription
//
- this.label9.AutoSize = true;
- this.label9.Location = new System.Drawing.Point(6, 40);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(332, 13);
- this.label9.TabIndex = 5;
- this.label9.Text = "This delay is necessary to wait for the network link to be established. ";
+ this.lblLgMaxPowerOnRetriesDescription.AutoSize = true;
+ this.lblLgMaxPowerOnRetriesDescription.Location = new System.Drawing.Point(6, 40);
+ this.lblLgMaxPowerOnRetriesDescription.Name = "lblLgMaxPowerOnRetriesDescription";
+ this.lblLgMaxPowerOnRetriesDescription.Size = new System.Drawing.Size(375, 13);
+ this.lblLgMaxPowerOnRetriesDescription.TabIndex = 5;
+ this.lblLgMaxPowerOnRetriesDescription.Text = "Retries are necessary to wait for the network link of your pc to be established. " +
+ "";
//
- // edtLgPowerOnAfterResumeDelay
+ // edtLgMaxPowerOnRetries
//
- this.edtLgPowerOnAfterResumeDelay.Increment = new decimal(new int[] {
- 100,
+ this.edtLgMaxPowerOnRetries.Location = new System.Drawing.Point(299, 17);
+ this.edtLgMaxPowerOnRetries.Maximum = new decimal(new int[] {
+ 25,
0,
0,
0});
- this.edtLgPowerOnAfterResumeDelay.Location = new System.Drawing.Point(299, 17);
- this.edtLgPowerOnAfterResumeDelay.Maximum = new decimal(new int[] {
- 10000,
- 0,
- 0,
- 0});
- this.edtLgPowerOnAfterResumeDelay.Name = "edtLgPowerOnAfterResumeDelay";
- this.edtLgPowerOnAfterResumeDelay.ReadOnly = true;
- this.edtLgPowerOnAfterResumeDelay.Size = new System.Drawing.Size(74, 20);
- this.edtLgPowerOnAfterResumeDelay.TabIndex = 1;
- this.edtLgPowerOnAfterResumeDelay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- this.edtLgPowerOnAfterResumeDelay.ValueChanged += new System.EventHandler(this.edtLgPowerOnAfterResumeDelay_ValueChanged);
+ this.edtLgMaxPowerOnRetries.Name = "edtLgMaxPowerOnRetries";
+ this.edtLgMaxPowerOnRetries.ReadOnly = true;
+ this.edtLgMaxPowerOnRetries.Size = new System.Drawing.Size(74, 20);
+ this.edtLgMaxPowerOnRetries.TabIndex = 1;
+ this.edtLgMaxPowerOnRetries.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ this.edtLgMaxPowerOnRetries.ValueChanged += new System.EventHandler(this.edtLgPowerOnAfterResumeDelay_ValueChanged);
//
- // label8
+ // lblLgMaxPowerOnRetries
//
- this.label8.AutoSize = true;
- this.label8.Location = new System.Drawing.Point(6, 19);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(214, 13);
- this.label8.TabIndex = 0;
- this.label8.Text = "Delay before powering on after resume (ms):";
+ this.lblLgMaxPowerOnRetries.AutoSize = true;
+ this.lblLgMaxPowerOnRetries.Location = new System.Drawing.Point(6, 19);
+ this.lblLgMaxPowerOnRetries.Name = "lblLgMaxPowerOnRetries";
+ this.lblLgMaxPowerOnRetries.Size = new System.Drawing.Size(294, 13);
+ this.lblLgMaxPowerOnRetries.TabIndex = 0;
+ this.lblLgMaxPowerOnRetries.Text = "Maximum number of retries powering on after startup/resume:";
//
// grpHDROptions
//
@@ -1314,18 +1598,6 @@
this.lblInfo.TabIndex = 1;
this.lblInfo.Text = "Info";
//
- // mnuLgRcButtons
- //
- this.mnuLgRcButtons.Name = "mnuLgRcButtons";
- this.mnuLgRcButtons.Size = new System.Drawing.Size(180, 22);
- this.mnuLgRcButtons.Text = "Buttons";
- //
- // mnuLgActions
- //
- this.mnuLgActions.Name = "mnuLgActions";
- this.mnuLgActions.Size = new System.Drawing.Size(180, 22);
- this.mnuLgActions.Text = "Actions";
- //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1349,6 +1621,7 @@
this.mnuNvPresets.ResumeLayout(false);
this.tabAMD.ResumeLayout(false);
this.tabAMD.PerformLayout();
+ this.mnuAmdPresets.ResumeLayout(false);
this.tabLG.ResumeLayout(false);
this.tabLG.PerformLayout();
this.mnuLgButtons.ResumeLayout(false);
@@ -1360,7 +1633,7 @@
this.grpMiscellaneousOptions.PerformLayout();
this.grpLGOptions.ResumeLayout(false);
this.grpLGOptions.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.edtLgPowerOnAfterResumeDelay)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.edtLgMaxPowerOnRetries)).EndInit();
this.grpHDROptions.ResumeLayout(false);
this.grpHDROptions.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.edtDelayDisplaySettings)).EndInit();
@@ -1447,13 +1720,13 @@
private System.Windows.Forms.ToolStripMenuItem miNvPresetColorSettings;
private System.Windows.Forms.CheckedListBox clbLgPower;
private System.Windows.Forms.GroupBox grpLGOptions;
- private System.Windows.Forms.NumericUpDown edtLgPowerOnAfterResumeDelay;
- private System.Windows.Forms.Label label8;
+ private System.Windows.Forms.NumericUpDown edtLgMaxPowerOnRetries;
+ private System.Windows.Forms.Label lblLgMaxPowerOnRetries;
private System.Windows.Forms.Button btnLGTestPower;
- private System.Windows.Forms.Label label9;
+ private System.Windows.Forms.Label lblLgMaxPowerOnRetriesDescription;
private System.Windows.Forms.GroupBox grpMiscellaneousOptions;
private System.Windows.Forms.CheckBox chkFixChromeFonts;
- private System.Windows.Forms.Label label10;
+ private System.Windows.Forms.Label lblFixChromeFontsDescription;
private System.Windows.Forms.Button btnSetShortcutScreenSaver;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox edtBlankScreenSaverShortcut;
@@ -1482,9 +1755,34 @@
private System.Windows.Forms.ToolStripMenuItem temporalToolStripMenuItem;
private System.Windows.Forms.Button btnLGRemoteControl;
private System.Windows.Forms.ToolStripMenuItem miNvPresetApplyOnStartup;
- private System.Windows.Forms.CheckBox chkLgAlternateWolMechanism;
+ private System.Windows.Forms.CheckBox chkLgOldWolMechanism;
private System.Windows.Forms.ToolStripMenuItem mnuLgRcButtons;
private System.Windows.Forms.ToolStripMenuItem mnuLgActions;
+ private System.Windows.Forms.Button btnDeleteAmd;
+ private System.Windows.Forms.Button btnCloneAmd;
+ private System.Windows.Forms.Button btnSetAmdShortcut;
+ private System.Windows.Forms.Label lblAmdShortcut;
+ private System.Windows.Forms.TextBox edtAmdShortcut;
+ private System.Windows.Forms.Button btnChangeAmd;
+ private System.Windows.Forms.ContextMenuStrip mnuAmdPresets;
+ private System.Windows.Forms.ToolStripMenuItem miAmdApply;
+ private System.Windows.Forms.ToolStripMenuItem miAmdPresetApplyOnStartup;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
+ private System.Windows.Forms.ToolStripMenuItem mnuAmdDisplay;
+ private System.Windows.Forms.ToolStripMenuItem miAmdPrimaryDisplay;
+ private System.Windows.Forms.ToolStripMenuItem mnuAmdColorSettings;
+ private System.Windows.Forms.ToolStripMenuItem miAmdColorSettingsIncluded;
+ private System.Windows.Forms.ToolStripMenuItem mnuAmdRefreshRate;
+ private System.Windows.Forms.ToolStripMenuItem miAmdRefreshRateIncluded;
+ private System.Windows.Forms.ToolStripMenuItem mnuAmdDithering;
+ private System.Windows.Forms.ToolStripMenuItem miAmdDitheringIncluded;
+ private System.Windows.Forms.ToolStripMenuItem mnuAmdHDR;
+ private System.Windows.Forms.ToolStripMenuItem miAmdHDRIncluded;
+ private System.Windows.Forms.ToolStripMenuItem miAmdHDRToggle;
+ private System.Windows.Forms.ToolStripMenuItem miAmdHDREnabled;
+ private System.Windows.Forms.Button btnApplyAmd;
+ private System.Windows.Forms.ListView lvAmdPresets;
+ private System.Windows.Forms.Button btnAddAmd;
}
}
diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs
index 7bde64d..a2a3263 100644
--- a/ColorControl/MainForm.cs
+++ b/ColorControl/MainForm.cs
@@ -1,6 +1,6 @@
-using LgTv;
+using ATI.ADL;
+using LgTv;
using Microsoft.Win32;
-using Microsoft.Win32.TaskScheduler;
using NLog;
using NStandard;
using NvAPIWrapper.Display;
@@ -18,23 +18,14 @@ using System.Linq;
using System.Reflection;
// 1. Import the InteropServices type
using System.Runtime.InteropServices;
-using System.Security.Principal;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
-using Action = System.Action;
namespace ColorControl
{
public partial class MainForm : Form
{
- //private Bitmap bitmap, bitmap2;
-
- [DllImport("user32.dll")]
- public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
- [DllImport("user32.dll")]
- public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
-
[DllImport("user32.dll")]
public extern static bool ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pwszReason);
@@ -53,11 +44,8 @@ namespace ColorControl
private string _dataDir;
private NvService _nvService;
- private List _presets;
- private string _nvPresetsFilename;
- private JavaScriptSerializer _JsonSerializer;
- private JavaScriptSerializer _JsonDeserializer;
- private Keys _pressedModifiers;
+ private JavaScriptSerializer _JsonSerializer = new JavaScriptSerializer();
+ private JavaScriptSerializer _JsonDeserializer = new JavaScriptSerializer();
private string _lastDisplayRefreshRates = string.Empty;
private NotifyIcon trayIcon;
@@ -65,13 +53,9 @@ namespace ColorControl
private string _configFilename;
private Config _config;
private bool _setVisibleCalled = false;
- private bool _winKeyDown = false;
private RestartDetector _restartDetector;
private LgService _lgService;
- private List _lgPresets;
- private string _lgPresetsFilename;
- private List _lgApps;
private RemoteControlForm _remoteControlForm;
private MenuItem _nvTrayMenu;
@@ -111,7 +95,7 @@ namespace ColorControl
trayIcon.MouseDoubleClick += trayIcon_MouseDoubleClick;
trayIcon.ContextMenu.Popup += trayIconContextMenu_Popup;
- chkStartAfterLogin.Checked = TaskExists(true);
+ chkStartAfterLogin.Checked = Utils.TaskExists(TS_TASKNAME, true);
chkFixChromeFonts.Enabled = Utils.IsChromeInstalled();
if (chkFixChromeFonts.Enabled)
@@ -119,63 +103,68 @@ namespace ColorControl
chkFixChromeFonts.Checked = Utils.IsChromeFixInstalled();
}
- _JsonSerializer = new JavaScriptSerializer();
- _JsonDeserializer = new JavaScriptSerializer();
-
- var converter = new ColorDataConverter();
- _JsonDeserializer.RegisterConverters(new[] { converter });
-
_configFilename = Path.Combine(_dataDir, "Settings.json");
LoadConfig();
+ InitNvService();
+ InitAmdService();
+ InitLgService();
+
+ InitInfo();
+
+ _restartDetector = new RestartDetector();
+
+ //Scale(new SizeF(1.25F, 1.25F));
+
+ _initialized = true;
+
+ AfterInitialized();
+ }
+
+ private void InitNvService()
+ {
try
{
- _nvService = new NvService();
+ _nvService = new NvService(_dataDir);
+ FillNvPresets();
}
- catch (Exception)
+ catch (Exception e)
{
+ Logger.Error("Error initializing NvService: " + e.ToLogString());
+ tcMain.TabPages.Remove(tabNVIDIA);
}
+ }
- _nvPresetsFilename = Path.Combine(_dataDir, "NvPresets.json");
- FillNvPresets();
-
- //try
- //{
- // _amdService = new AmdService();
- // lblErrorAMD.Text = "If you see this message, it means you have AMD graphics drivers installed. Unfortunately, this feature is not completed yet. If I get an AMD card I might finish it.";
- //}
- //catch (Exception)
- //{
- // tcMain.TabPages.Remove(tabAMD);
- //}
- tcMain.TabPages.Remove(tabAMD);
-
- _lgPresetsFilename = Path.Combine(_dataDir, "LgPresets.json");
- var toCopy = Path.Combine(Directory.GetCurrentDirectory(), "LgPresets.json");
- if (!File.Exists(_lgPresetsFilename) && File.Exists(toCopy))
+ private void InitAmdService()
+ {
+ try
{
- try
- {
- File.Copy(toCopy, _lgPresetsFilename);
- }
- catch (Exception e)
- {
- Logger.Error($"Error while copying {toCopy} to {_lgPresetsFilename}: {e.Message}");
- }
+ _amdService = new AmdService(_dataDir);
+ //lblErrorAMD.Text = "If you see this message, it means you have AMD graphics drivers installed. Unfortunately, this feature is not completed yet. If I get an AMD card I might finish it.";
+ FillAmdPresets();
}
- FillLgPresets();
+ catch (Exception e)
+ {
+ Logger.Error("Error initializing AmdService: " + e.ToLogString());
+ tcMain.TabPages.Remove(tabAMD);
+ }
+ }
+ private void InitLgService()
+ {
try
{
_lgService = new LgService(_dataDir, StartUpParams.RunningFromScheduledTask);
+ FillLgPresets();
+
clbLgPower.SetItemChecked(0, _lgService.Config.PowerOnAfterStartup);
clbLgPower.SetItemChecked(1, _lgService.Config.PowerOnAfterResume);
clbLgPower.SetItemChecked(2, _lgService.Config.PowerOffOnShutdown);
clbLgPower.SetItemChecked(3, _lgService.Config.PowerOffOnStandby);
- edtLgPowerOnAfterResumeDelay.Value = _lgService.Config.PowerOnDelayAfterResume;
+ edtLgMaxPowerOnRetries.Value = _lgService.Config.PowerOnRetries;
edtLgDeviceFilter.Text = _lgService.Config.DeviceSearchKey;
- chkLgAlternateWolMechanism.Checked = _lgService.Config.UseAlternateWol;
+ chkLgOldWolMechanism.Checked = _lgService.Config.UseOldNpcapWol;
var values = Enum.GetValues(typeof(ButtonType));
foreach (var button in values)
@@ -207,16 +196,6 @@ namespace ColorControl
{
Logger.Error("Error initializing LgService: " + e.ToLogString());
}
-
- InitInfo();
-
- _restartDetector = new RestartDetector();
-
- //Scale(new SizeF(1.25F, 1.25F));
-
- _initialized = true;
-
- AfterInitialized();
}
private void PowerModeChanged(object sender, PowerModeChangedEventArgs e)
@@ -319,90 +298,45 @@ namespace ColorControl
WindowState = FormWindowState.Normal;
}
- private void button1_Click(object sender, EventArgs e)
- {
- //Display.GetDisplays().First().DisplayDevice.CurrentColorData.ColorFormat = NvAPIWrapper.Native.Display.ColorDataFormat.RGB;
- // var colorData = new ColorData(NvAPIWrapper.Native.Display.ColorDataFormat.YUV444, NvAPIWrapper.Native.Display.ColorDataColorimetry.Auto, NvAPIWrapper.Native.Display.ColorDataDynamicRange.Auto, NvAPIWrapper.Native.Display.ColorDataDepth.BPC8);
- //var hdrColorData = new HDRColorData(NvAPIWrapper.Native.Display.ColorDataHDRMode.UHDA);
- //DisplayDevice.GetGDIPrimaryDisplayDevice().SetColorData(colorData);
- //Display.GetDisplays().First().DisplayDevice.SetColorData(colorData);
- //pictureBox1.Load("d:\\ss.png");
-
- //bitmap = new Bitmap("d:\\ss2.png");
-
- //Bitmap bitmap2 = Utils.SubPixelShift(bitmap);
-
- //pictureBox1.Image = bitmap2;
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- }
-
private void FillNvPresets()
{
- var colums = NvPreset.GetColumnNames();
-
- foreach (var name in colums)
- {
- var columnName = name;
- var parts = name.Split('|');
-
- var width = 120;
- if (parts.Length > 1)
- {
- width = Int32.Parse(parts[1]);
- columnName = parts[0];
- }
-
- var header = lvNvPresets.Columns.Add(columnName);
- header.Width = width == 120 ? -2 : width;
- }
-
- if (File.Exists(_nvPresetsFilename))
- {
- var json = File.ReadAllText(_nvPresetsFilename);
-
- _presets = _JsonDeserializer.Deserialize>(json);
- }
- else
- {
- _presets = NvPreset.GetDefaultPresets();
-
- }
+ Utils.InitListView(lvNvPresets, NvPreset.GetColumnNames());
UpdateDisplayInfoItems();
- foreach (var preset in _presets)
+ foreach (var preset in _nvService.GetPresets())
{
AddOrUpdateItem(preset);
- RegisterShortcut(preset.id, preset.shortcut);
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut);
}
+ }
- //UpdateTrayMenuNv();
+ private void FillAmdPresets()
+ {
+ Utils.InitListView(lvAmdPresets, AmdPreset.GetColumnNames());
+
+ UpdateDisplayInfoItemsAmd();
+
+ foreach (var preset in _amdService.GetPresets())
+ {
+ AddOrUpdateItemAmd(preset);
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut);
+ }
}
private void UpdateDisplayInfoItems()
{
- if (_nvService == null)
+ var displays = _nvService?.GetDisplayInfos();
+ if (displays == null)
{
return;
}
- Display[] displays;
- try
- {
- displays = _nvService.GetDisplays();
- }
- catch (Exception e)
- {
- Logger.Error("Error while getting displays: " + e.ToLogString());
- return;
- }
-
var text = TS_TASKNAME;
- foreach (var display in displays)
+ foreach (var displayInfo in displays)
{
+ var display = displayInfo.Display;
+
var id = Math.Abs((int)display.Handle.MemoryAddress.ToInt64());
ListViewItem item = null;
@@ -425,39 +359,7 @@ namespace ColorControl
item.BackColor = Color.LightGray;
}
- var values = new List();
-
- var name = display.Name;
-
- var screen = Screen.AllScreens.FirstOrDefault(x => x.DeviceName.Equals(name));
- if (screen != null)
- {
- name += " (" + screen.DeviceFriendlyName() + ")";
- }
-
- values.Add(name);
-
- var colorData = display.DisplayDevice.CurrentColorData;
- var colorSettings = string.Format("{0}, {1}, {2}, {3}", colorData.ColorDepth, colorData.ColorFormat, colorData.DynamicRange, colorData.Colorimetry);
-
- values.Add(colorSettings);
-
- var refreshRate = display.DisplayDevice.CurrentTiming.Extra.RefreshRate;
-
- values.Add($"{refreshRate}Hz");
-
- var lastPreset = _nvService.GetLastAppliedPreset();
- if (lastPreset != null)
- {
- //values.Add(_nvService.GetDithering() ? "Yes" : "No");
- values.Add(lastPreset.GetDitheringDescription());
- }
- else
- {
- values.Add(string.Empty);
- }
-
- values.Add(_nvService.IsHDREnabled() ? "Yes" : "No");
+ var values = displayInfo.Values;
item.Text = values[0];
for (var i = 1; i < values.Count; i++)
@@ -472,57 +374,76 @@ namespace ColorControl
}
}
- text += "\n" + string.Format("{0}: {1}, {2}Hz, HDR: {3}", name, colorSettings, refreshRate, _nvService.IsHDREnabled() ? "Yes" : "No");
+ text += "\n" + displayInfo.InfoLine;
}
Utils.SetNotifyIconText(trayIcon, text);
}
- private void RegisterShortcut(int id, string shortcut, bool clear = false)
+ private void UpdateDisplayInfoItemsAmd()
{
- if (clear)
+ var displays = _amdService?.GetDisplayInfos();
+ if (displays == null)
{
- UnregisterHotKey(Handle, id);
+ return;
}
- if (!string.IsNullOrEmpty(shortcut))
+ var text = TS_TASKNAME;
+ foreach (var displayInfo in displays)
{
- var (mods, key) = Utils.ParseShortcut(shortcut);
- bool registered = RegisterHotKey(Handle, id, mods, key);
+ var display = displayInfo.Display;
+
+ var id = display.DisplayID.DisplayPhysicalIndex;
+
+ ListViewItem item = null;
+ for (var i = 0; i < lvAmdPresets.Items.Count; i++)
+ {
+ item = lvAmdPresets.Items[i];
+
+ if (item.Tag == null && item.ImageIndex == id)
+ {
+ break;
+ }
+ item = null;
+ }
+
+ if (item == null)
+ {
+ item = lvAmdPresets.Items.Add(display.DisplayName);
+ item.ImageIndex = id;
+ item.Font = new Font(item.Font, item.Font.Style | FontStyle.Bold);
+ item.BackColor = Color.LightGray;
+ }
+
+ var values = displayInfo.Values;
+
+ item.Text = values[0];
+ for (var i = 1; i < values.Count; i++)
+ {
+ if (item.SubItems.Count - 1 >= i)
+ {
+ item.SubItems[i].Text = values[i];
+ }
+ else
+ {
+ item.SubItems.Add(values[i]);
+ }
+ }
+
+ text += "\n" + displayInfo.InfoLine;
}
+
+ Utils.SetNotifyIconText(trayIcon, text);
}
private void AddOrUpdateItem(NvPreset preset = null)
{
- ListViewItem item = null;
- if (preset == null)
- {
- item = lvNvPresets.SelectedItems[0];
- preset = (NvPreset)item.Tag;
- }
+ Utils.AddOrUpdateListItem(lvNvPresets, _nvService.GetPresets(), _config, preset);
+ }
- var values = preset.GetDisplayValues(_config);
-
- if (item == null)
- {
- item = lvNvPresets.Items.Add(values[0]);
- item.Tag = preset;
- for (var i = 1; i < values.Count; i++)
- {
- item.SubItems.Add(values[i]);
- }
- if (!_presets.Any(x => x.id == preset.id)) {
- _presets.Add(preset);
- }
- }
- else
- {
- item.Text = values[0];
- for (var i = 1; i < values.Count; i++)
- {
- item.SubItems[i].Text = values[i];
- }
- }
+ private void AddOrUpdateItemAmd(AmdPreset preset = null)
+ {
+ Utils.AddOrUpdateListItem(lvAmdPresets, _amdService.GetPresets(), _config, preset);
}
private void btnApply_Click(object sender, EventArgs e)
@@ -567,40 +488,13 @@ namespace ColorControl
private void GlobalSave()
{
- SaveNvPresets();
- SaveLgPresets();
-
+ _nvService?.GlobalSave();
+ _amdService?.GlobalSave();
_lgService?.GlobalSave();
SaveConfig();
}
- private void SaveNvPresets()
- {
- try
- {
- var json = _JsonSerializer.Serialize(_presets);
- File.WriteAllText(_nvPresetsFilename, json);
- }
- catch (Exception e)
- {
- Logger.Error(e.ToLogString());
- }
- }
-
- private void SaveLgPresets()
- {
- try
- {
- var json = _JsonSerializer.Serialize(_lgPresets);
- File.WriteAllText(_lgPresetsFilename, json);
- }
- catch (Exception e)
- {
- Logger.Error(e.ToLogString());
- }
- }
-
private void lvNvPresets_SelectedIndexChanged(object sender, EventArgs e)
{
var preset = GetSelectedNvPreset();
@@ -626,10 +520,9 @@ namespace ColorControl
protected override void WndProc(ref Message m)
{
// 5. Catch when a HotKey is pressed !
- if (m.Msg == WM_HOTKEY && !edtShortcut.Focused && !edtShortcutLg.Focused)
+ if (m.Msg == WM_HOTKEY && !edtShortcut.Focused && !edtShortcutLg.Focused && !edtAmdShortcut.Focused && !edtBlankScreenSaverShortcut.Focused)
{
int id = m.WParam.ToInt32();
- // MessageBox.Show(string.Format("Hotkey #{0} pressed", id));
// 6. Handle what will happen once a respective hotkey is pressed
if (id == SHORTCUTID_SCREENSAVER)
@@ -639,25 +532,24 @@ namespace ColorControl
}
else
{
- var preset = _presets.FirstOrDefault(x => x.id == id);
+ var preset = _nvService?.GetPresets().FirstOrDefault(x => x.id == id);
if (preset != null)
{
ApplyNvPreset(preset);
}
- var lgPreset = _lgPresets.FirstOrDefault(x => x.id == id);
+ var amdPreset = _amdService?.GetPresets().FirstOrDefault(x => x.id == id);
+ if (amdPreset != null)
+ {
+ ApplyAmdPreset(amdPreset);
+ }
+
+ var lgPreset = _lgService?.GetPresets().FirstOrDefault(x => x.id == id);
if (lgPreset != null)
{
ApplyLgPreset(lgPreset);
}
}
-
- //switch (id)
- //{
- // case 1:
- // MessageBox.Show("F9 Key Pressed ! Do something here ... ");
- // break;
- //}
}
else if (m.Msg == NativeConstants.WM_QUERYENDSESSION)
{
@@ -673,36 +565,7 @@ namespace ColorControl
private void edtShortcut_KeyDown(object sender, KeyEventArgs e)
{
- _pressedModifiers = e.Modifiers;
-
- //Debug.WriteLine("KD: " + e.Modifiers + ", " + e.KeyCode);
-
- var shortcutString = (_pressedModifiers > 0 ? _pressedModifiers.ToString() : "");
- if (e.KeyCode == Keys.LWin || _winKeyDown)
- {
- _winKeyDown = true;
- if (!string.IsNullOrEmpty(shortcutString))
- {
- shortcutString += ", ";
- }
- shortcutString += "Win";
- }
-
- if (!string.IsNullOrEmpty(shortcutString) && e.KeyCode != Keys.ControlKey && e.KeyCode != Keys.ShiftKey && e.KeyCode != Keys.Menu && e.KeyCode != Keys.LWin)
- {
- shortcutString += " + " + e.KeyCode.ToString();
- }
-
- if (_pressedModifiers == 0 && !_winKeyDown)
- {
- e.SuppressKeyPress = true;
- }
-
- ((TextBox)sender).Text = shortcutString;
- }
-
- private void edtShortcut_KeyPress(object sender, KeyPressEventArgs e)
- {
+ ((TextBox)sender).Text = Utils.FormatKeyboardShortcut(e);
}
private void btnSetShortcut_Click(object sender, EventArgs e)
@@ -723,7 +586,7 @@ namespace ColorControl
AddOrUpdateItem();
- RegisterShortcut(preset.id, preset.shortcut, clear);
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut, clear);
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
@@ -752,67 +615,7 @@ namespace ColorControl
return;
}
var enabled = chkStartAfterLogin.Checked;
- RegisterTask(enabled);
- }
-
- private void RegisterTask(bool enabled)
- {
- var file = Assembly.GetExecutingAssembly().Location;
- var directory = Path.GetDirectoryName(file);
-
- try
- {
- using (TaskService ts = new TaskService())
- {
- if (enabled)
- {
- TaskDefinition td = ts.NewTask();
- td.RegistrationInfo.Description = "Start ColorControl";
-
- td.Triggers.Add(new LogonTrigger { UserId = WindowsIdentity.GetCurrent().Name });
-
- td.Actions.Add(new ExecAction(file, StartUpParams.RunningFromScheduledTaskParam, directory));
-
- ts.RootFolder.RegisterTaskDefinition(TS_TASKNAME, td);
- }
- else
- {
- ts.RootFolder.DeleteTask(TS_TASKNAME, false);
- }
- }
- }
- catch (Exception e)
- {
- MessageForms.ErrorOk("Could not create/delete task: " + e.Message);
- }
- }
-
- private bool TaskExists(bool update)
- {
- var file = Assembly.GetExecutingAssembly().Location;
- using (TaskService ts = new TaskService())
- {
- var task = ts.RootFolder.Tasks.FirstOrDefault(x => x.Name.Equals(TS_TASKNAME));
-
- if (task != null)
- {
- if (update && ApplicationDeployment.IsNetworkDeployed)
- {
- var action = task.Definition.Actions.FirstOrDefault(x => x.ActionType == TaskActionType.Execute);
- if (action != null)
- {
- var execAction = action as ExecAction;
- if (!execAction.Path.Equals(file))
- {
- RegisterTask(false);
- RegisterTask(true);
- }
- }
- }
- return true;
- }
- return false;
- }
+ Utils.RegisterTask(TS_TASKNAME, enabled);
}
private void LoadConfig()
@@ -834,7 +637,7 @@ namespace ColorControl
if (!string.IsNullOrEmpty(_config.ScreenSaverShortcut))
{
- RegisterShortcut(SHORTCUTID_SCREENSAVER, _config.ScreenSaverShortcut);
+ Utils.RegisterShortcut(Handle, SHORTCUTID_SCREENSAVER, _config.ScreenSaverShortcut);
}
Width = _config.FormWidth;
@@ -861,10 +664,6 @@ namespace ColorControl
}
}
- private void MainForm_Load(object sender, EventArgs e)
- {
- }
-
private void ShowControls(Control parent, bool show = true, Control exclude = null)
{
for (var i = 0; i < parent.Controls.Count; i++)
@@ -917,10 +716,7 @@ namespace ColorControl
private void edtShortcut_KeyUp(object sender, KeyEventArgs e)
{
- if (e.KeyCode == Keys.LWin)
- {
- _winKeyDown = false;
- }
+ Utils.HandleKeyboardShortcutUp(e);
}
private void edtShortcut_TextChanged(object sender, EventArgs e)
@@ -935,7 +731,7 @@ namespace ColorControl
}
else
{
- edtShortcut.ForeColor = _presets.Any(x => x.id != preset.id && text.Equals(x.shortcut)) ? Color.Red : SystemColors.WindowText;
+ edtShortcut.ForeColor = ShortCutExists(text, preset.id) ? Color.Red : SystemColors.WindowText;
}
}
@@ -952,6 +748,19 @@ namespace ColorControl
}
}
+ private AmdPreset GetSelectedAmdPreset()
+ {
+ if (lvAmdPresets.SelectedItems.Count > 0)
+ {
+ var item = lvAmdPresets.SelectedItems[0];
+ return (AmdPreset)item.Tag;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
private void btnClone_Click(object sender, EventArgs e)
{
var preset = GetSelectedNvPreset();
@@ -1037,10 +846,10 @@ namespace ColorControl
}
}
- BuildDropDownMenu(mnuNvPresetsColorSettings, "Bit depth", typeof(ColorDataDepth), preset.colorData, "ColorDepth");
- BuildDropDownMenu(mnuNvPresetsColorSettings, "Format", typeof(ColorDataFormat), preset.colorData, "ColorFormat");
- BuildDropDownMenu(mnuNvPresetsColorSettings, "Dynamic range", typeof(ColorDataDynamicRange), preset.colorData, "DynamicRange");
- BuildDropDownMenu(mnuNvPresetsColorSettings, "Color space", typeof(ColorDataColorimetry), preset.colorData, "Colorimetry");
+ Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Bit depth", typeof(ColorDataDepth), preset.colorData, "ColorDepth", nvPresetColorDataMenuItem_Click);
+ Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Format", typeof(ColorDataFormat), preset.colorData, "ColorFormat", nvPresetColorDataMenuItem_Click);
+ Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Dynamic range", typeof(ColorDataDynamicRange), preset.colorData, "DynamicRange", nvPresetColorDataMenuItem_Click);
+ Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Color space", typeof(ColorDataColorimetry), preset.colorData, "Colorimetry", nvPresetColorDataMenuItem_Click);
if (preset.displayName != _lastDisplayRefreshRates)
{
@@ -1115,47 +924,6 @@ namespace ColorControl
}
}
- private void BuildDropDownMenu(ToolStripMenuItem mnuParent, string name, Type enumType, ColorData colorData, string propertyName)
- {
- PropertyInfo property;
- var subMenuItems = mnuParent.DropDownItems.Find("miColorSettings_" + name, false);
- ToolStripMenuItem subMenuItem = null;
- if (subMenuItems.Length == 0)
- {
- subMenuItem = (ToolStripMenuItem)mnuParent.DropDownItems.Add(name);
- subMenuItem.Name = "miColorSettings_" + name;
-
- property = typeof(ColorData).GetDeclaredProperty(propertyName);
- subMenuItem.Tag = property;
-
- foreach (var enumValue in Enum.GetValues(enumType))
- {
- var item = subMenuItem.DropDownItems.Add(enumValue.ToString());
- item.Tag = enumValue;
- item.Click += nvPresetColorDataMenuItem_Click;
- }
- }
- else
- {
- subMenuItem = (ToolStripMenuItem)subMenuItems[0];
- property = (PropertyInfo)subMenuItem.Tag;
- }
-
- var value = property.GetValue(colorData);
-
- foreach (var item in subMenuItem.DropDownItems)
- {
- if (item is ToolStripMenuItem)
- {
- var menuItem = (ToolStripMenuItem)item;
- if (menuItem.Tag != null)
- {
- menuItem.Checked = menuItem.Tag.Equals(value);
- }
- }
- }
- }
-
private void nvPresetColorDataMenuItem_Click(object sender, EventArgs e)
{
var menuItem = (ToolStripMenuItem)sender;
@@ -1194,6 +962,17 @@ namespace ColorControl
AddOrUpdateItem();
}
+ private void refreshRateMenuItemAmd_Click(object sender, EventArgs e)
+ {
+ var refreshRate = (uint)((ToolStripItem)sender).Tag;
+
+ var preset = GetSelectedAmdPreset();
+
+ preset.refreshRate = refreshRate;
+
+ AddOrUpdateItemAmd();
+ }
+
private void displayMenuItem_Click(object sender, EventArgs e)
{
var preset = GetSelectedNvPreset();
@@ -1215,6 +994,27 @@ namespace ColorControl
AddOrUpdateItem();
}
+ private void displayMenuItemAmd_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ var menuItem = (ToolStripItem)sender;
+ if (menuItem.Tag != null)
+ {
+ var display = (ADLDisplayInfo)menuItem.Tag;
+
+ preset.displayName = display.DisplayName;
+ preset.primaryDisplay = false;
+ }
+ else
+ {
+ preset.primaryDisplay = true;
+ preset.displayName = null;
+ }
+
+ AddOrUpdateItemAmd();
+ }
+
private void miHDRIncluded_Click(object sender, EventArgs e)
{
var preset = GetSelectedNvPreset();
@@ -1250,83 +1050,18 @@ namespace ColorControl
private void FillLgPresets()
{
- var columns = LgPreset.GetColumnNames();
+ Utils.InitListView(lvLgPresets, LgPreset.GetColumnNames());
- foreach (var name in columns)
- {
- var columnName = name;
- var parts = name.Split('|');
-
- var width = 120;
- if (parts.Length > 1)
- {
- width = Int32.Parse(parts[1]);
- columnName = parts[0];
- }
-
- var header = lvLgPresets.Columns.Add(columnName);
- header.Width = width == 120 ? -2 : width;
- }
-
- if (File.Exists(_lgPresetsFilename))
- {
- var json = File.ReadAllText(_lgPresetsFilename);
-
- _lgPresets = _JsonDeserializer.Deserialize>(json);
- }
- else
- {
- _lgPresets = new List();
- }
-
- foreach (var preset in _lgPresets)
+ foreach (var preset in _lgService.GetPresets())
{
AddOrUpdateItemLg(preset);
- RegisterShortcut(preset.id, preset.shortcut);
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut);
}
}
private void AddOrUpdateItemLg(LgPreset preset = null, ListViewItem specItem = null)
{
- ListViewItem item = null;
- if (preset == null)
- {
- item = lvLgPresets.SelectedItems[0];
- preset = (LgPreset)item.Tag;
- }
- else
- {
- item = specItem;
- }
-
- if (preset.id == 0)
- {
- preset.id = preset.GetHashCode();
- }
-
- var values = preset.GetDisplayValues();
-
- if (item == null)
- {
- item = lvLgPresets.Items.Add(values[0]);
- item.Tag = preset;
- for (var i = 1; i < values.Count; i++)
- {
- item.SubItems.Add(values[i]);
- }
- if (!_lgPresets.Any(x => x.id == preset.id))
- {
- _lgPresets.Add(preset);
- }
- }
- else
- {
- item.Text = values[0];
- for (var i = 1; i < values.Count; i++)
- {
- item.SubItems[i].Text = values[i];
- }
- }
+ Utils.AddOrUpdateListItem(lvLgPresets, _lgService.GetPresets(), _config, preset, specItem);
}
private void btnCloneLg_Click(object sender, EventArgs e)
@@ -1368,7 +1103,8 @@ namespace ColorControl
if (preset != null)
{
edtNameLg.Text = preset.name;
- cbxLgApps.SelectedIndex = _lgApps == null ? -1 : _lgApps.FindIndex(x => x.appId.Equals(preset.appId));
+ var lgApps = _lgService?.GetApps();
+ cbxLgApps.SelectedIndex = lgApps == null ? -1 : lgApps.FindIndex(x => x.appId.Equals(preset.appId));
edtShortcutLg.Text = preset.shortcut;
edtStepsLg.Text = preset.steps.Aggregate("", (a, b) => (string.IsNullOrEmpty(a) ? "" : a + ", ") + b);
}
@@ -1401,7 +1137,7 @@ namespace ColorControl
var name = edtNameLg.Text.Trim();
- if (name.Length == 0 || _lgPresets.Any(x => x.id != preset.id && x.name.Equals(name, StringComparison.OrdinalIgnoreCase)))
+ if (name.Length == 0 || _lgService.GetPresets().Any(x => x.id != preset.id && x.name.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
MessageForms.WarningOk("The name can not be empty and must be unique.");
return;
@@ -1440,11 +1176,9 @@ namespace ColorControl
AddOrUpdateItemLg();
- SaveLgPresets();
-
if (shortcutChanged)
{
- RegisterShortcut(preset.id, preset.shortcut, clear);
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut, clear);
}
}
@@ -1459,10 +1193,10 @@ namespace ColorControl
if (!string.IsNullOrEmpty(preset.shortcut))
{
- UnregisterHotKey(Handle, preset.id);
+ Utils.UnregisterHotKey(Handle, preset.id);
}
- _presets.Remove(preset);
+ _nvService.GetPresets().Remove(preset);
var item = lvNvPresets.SelectedItems[0];
lvNvPresets.Items.Remove(item);
@@ -1475,7 +1209,7 @@ namespace ColorControl
foreach (var preset in presets)
{
- if (!_presets.Any(x => x.colorData.Equals(preset.colorData)))
+ if (!_nvService.GetPresets().Any(x => x.colorData.Equals(preset.colorData)))
{
AddOrUpdateItem(preset);
added = true;
@@ -1531,8 +1265,8 @@ namespace ColorControl
var preset = _nvService.GetLastAppliedPreset() ?? GetSelectedNvPreset();
chkDitheringEnabled.Checked = preset?.ditheringEnabled ?? true;
- cbxDitheringBitDepth.SelectedIndex = (int)(preset?.ditheringBits ?? 1);
- cbxDitheringMode.SelectedIndex = (int)(preset?.ditheringMode ?? 4);
+ cbxDitheringBitDepth.SelectedIndex = (int)(preset?.ditheringBits ?? (int)NvDitherBits.Bits8);
+ cbxDitheringMode.SelectedIndex = (int)(preset?.ditheringMode ?? (int)NvDitherMode.Temporal);
FillGradient();
}
}
@@ -1558,14 +1292,14 @@ namespace ColorControl
if (cbxLgApps.Items.Count == 0 && _lgService.SelectedDevice != null)
{
- _lgService.RefreshApps().ContinueWith((task) => BeginInvoke(new Action>>(FillLgApps), new[] { task }));
+ _lgService.RefreshApps().ContinueWith((task) => BeginInvoke(new Action(FillLgApps)));
}
}
- private void FillLgApps(Task> task)
+ private void FillLgApps()
{
- _lgApps = task.Result;
- if (_lgApps == null || !_lgApps.Any())
+ var lgApps = _lgService?.GetApps();
+ if (lgApps == null || !lgApps.Any())
{
MessageForms.WarningOk("Could not refresh the apps. Check the log for details.");
return;
@@ -1574,9 +1308,13 @@ namespace ColorControl
}
private void InitLgApps() {
- LgPreset.LgApps = _lgApps;
+ var lgApps = _lgService?.GetApps();
+
cbxLgApps.Items.Clear();
- cbxLgApps.Items.AddRange(_lgApps.ToArray());
+ if (lgApps != null)
+ {
+ cbxLgApps.Items.AddRange(lgApps.ToArray());
+ }
for (var i = 0; i < lvLgPresets.Items.Count; i++)
{
@@ -1587,13 +1325,13 @@ namespace ColorControl
var preset = GetSelectedLgPreset();
if (preset != null)
{
- cbxLgApps.SelectedIndex = _lgApps == null ? -1 : _lgApps.FindIndex(x => x.appId.Equals(preset.appId));
+ cbxLgApps.SelectedIndex = lgApps == null ? -1 : lgApps.FindIndex(x => x.appId.Equals(preset.appId));
}
}
private void UpdateTrayMenuNv()
{
- var presets = _presets.Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate);
+ var presets = _nvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate);
_nvTrayMenu.MenuItems.Clear();
@@ -1639,7 +1377,7 @@ namespace ColorControl
private void UpdateTrayMenuLg()
{
- var presets = _lgPresets.Where(x => !string.IsNullOrEmpty(x.appId) || x.steps.Any());
+ var presets = _lgService.GetPresets().Where(x => !string.IsNullOrEmpty(x.appId) || x.steps.Any());
_lgTrayMenu.MenuItems.Clear();
@@ -1666,22 +1404,18 @@ namespace ColorControl
ApplyLgPreset(preset);
}
- private void lvNvPresets_DoubleClick(object sender, EventArgs e)
- {
- ApplySelectedNvPreset();
- }
-
- private void miNvApply_Click(object sender, EventArgs e)
- {
- ApplySelectedNvPreset();
- }
-
private void ApplySelectedNvPreset()
{
var preset = GetSelectedNvPreset();
ApplyNvPreset(preset);
}
+ private void ApplySelectedAmdPreset()
+ {
+ var preset = GetSelectedAmdPreset();
+ ApplyAmdPreset(preset);
+ }
+
private void btnDeleteLg_Click(object sender, EventArgs e)
{
var preset = GetSelectedLgPreset();
@@ -1693,10 +1427,10 @@ namespace ColorControl
if (!string.IsNullOrEmpty(preset.shortcut))
{
- UnregisterHotKey(Handle, preset.id);
+ Utils.UnregisterHotKey(Handle, preset.id);
}
- _lgPresets.Remove(preset);
+ _lgService.GetPresets().Remove(preset);
var item = lvLgPresets.SelectedItems[0];
lvLgPresets.Items.Remove(item);
@@ -1704,19 +1438,7 @@ namespace ColorControl
private void btnAddLg_Click(object sender, EventArgs e)
{
- var preset = new LgPreset();
- var name = "New preset";
- string fullname;
- var number = 1;
- do
- {
- fullname = $"{name} ({number})";
- number++;
- } while (_lgPresets.Any(x => x.name.Equals(fullname)));
-
- preset.name = fullname;
-
- AddOrUpdateItemLg(preset);
+ AddOrUpdateItemLg(_lgService.CreateNewPreset());
}
private void edtDelayDisplaySettings_ValueChanged(object sender, EventArgs e)
@@ -1748,6 +1470,30 @@ namespace ColorControl
}
}
+ private bool ApplyAmdPreset(AmdPreset preset)
+ {
+ if (preset == null || _amdService == null)
+ {
+ return false;
+ }
+ try
+ {
+ var result = _amdService.ApplyPreset(preset, _config);
+ if (!result)
+ {
+ throw new Exception("Error while applying AMD preset. At least one setting could not be applied. Check the log for details.");
+ }
+
+ UpdateDisplayInfoItemsAmd();
+ return true;
+ }
+ catch (Exception e)
+ {
+ MessageForms.ErrorOk($"Error applying AMD-preset ({e.TargetSite.Name}): {e.Message}");
+ return false;
+ }
+ }
+
private void ApplyLgPreset(LgPreset preset, bool reconnect = false, bool wait = false)
{
if (preset == null)
@@ -1790,7 +1536,7 @@ namespace ColorControl
private void btnLgRefreshApps_Click(object sender, EventArgs e)
{
- _lgService.RefreshApps(true).ContinueWith((task) => BeginInvoke(new Action>>(FillLgApps), new[] { task }));
+ _lgService.RefreshApps(true).ContinueWith((task) => BeginInvoke(new Action(FillLgApps)));
}
private void cbxLgDevices_SelectedIndexChanged(object sender, EventArgs e)
@@ -1906,7 +1652,7 @@ See Options to test this functionality."
private void edtLgPowerOnAfterResumeDelay_ValueChanged(object sender, EventArgs e)
{
- _lgService.Config.PowerOnDelayAfterResume = (int)edtLgPowerOnAfterResumeDelay.Value;
+ _lgService.Config.PowerOnRetries = (int)edtLgMaxPowerOnRetries.Value;
}
private void chkFixChromeFonts_CheckedChanged(object sender, EventArgs e)
@@ -1939,7 +1685,7 @@ Do you want to continue?";
if (MessageForms.QuestionYesNo(text) == DialogResult.Yes)
{
- _lgService.PowerOff();
+ Utils.WaitForTask(_lgService.PowerOff());
MessageForms.InfoOk("Press ENTER to wake the TV.");
@@ -1963,7 +1709,7 @@ Do you want to continue?";
_config.ScreenSaverShortcut = shortcut;
- RegisterShortcut(SHORTCUTID_SCREENSAVER, shortcut, clear);
+ Utils.RegisterShortcut(Handle, SHORTCUTID_SCREENSAVER, shortcut, clear);
}
private void chkMinimizeOnClose_CheckedChanged(object sender, EventArgs e)
@@ -1974,6 +1720,7 @@ Do you want to continue?";
private void MainForm_Activated(object sender, EventArgs e)
{
UpdateDisplayInfoItems();
+ UpdateDisplayInfoItemsAmd();
}
private void btnClearLog_Click(object sender, EventArgs e)
@@ -2022,7 +1769,7 @@ Do you want to continue?";
var bitDepth = cbxDitheringBitDepth.SelectedIndex;
var mode = cbxDitheringMode.SelectedIndex;
- _nvService.SetDithering(chkDitheringEnabled.Checked, (uint)bitDepth, (uint)mode);
+ _nvService.SetDithering(chkDitheringEnabled.Checked, (uint)bitDepth, (uint)(mode > -1 ? mode : (int)NvDitherMode.Temporal));
}
private void cbxDitheringBitDepth_SelectedIndexChanged(object sender, EventArgs e)
@@ -2075,12 +1822,13 @@ Do you want to continue?";
private void AfterInitialized()
{
ApplyNvPresetOnStartup();
+ ApplyAmdPresetOnStartup();
}
private void ApplyNvPresetOnStartup(int attempts = 5) {
if (_config.NvPresetId_ApplyOnStartup != 0)
{
- var preset = _presets.FirstOrDefault(p => p.id == _config.NvPresetId_ApplyOnStartup);
+ var preset = _nvService?.GetPresets().FirstOrDefault(p => p.id == _config.NvPresetId_ApplyOnStartup);
if (preset == null)
{
_config.NvPresetId_ApplyOnStartup = 0;
@@ -2096,9 +1844,9 @@ Do you want to continue?";
attempts--;
if (attempts > 0)
{
- System.Threading.Tasks.Task.Run(async () =>
+ Task.Run(async () =>
{
- await System.Threading.Tasks.Task.Delay(2000);
+ await Task.Delay(2000);
BeginInvoke(new Action(() => ApplyNvPresetOnStartup(attempts)));
});
}
@@ -2107,6 +1855,37 @@ Do you want to continue?";
}
}
+ private void ApplyAmdPresetOnStartup(int attempts = 5)
+ {
+ if (_config.AmdPresetId_ApplyOnStartup != 0)
+ {
+ var preset = _amdService?.GetPresets().FirstOrDefault(p => p.id == _config.AmdPresetId_ApplyOnStartup);
+ if (preset == null)
+ {
+ _config.AmdPresetId_ApplyOnStartup = 0;
+ }
+ else if (_amdService != null)
+ {
+ if (_amdService.HasDisplaysAttached())
+ {
+ ApplyAmdPreset(preset);
+ }
+ else
+ {
+ attempts--;
+ if (attempts > 0)
+ {
+ Task.Run(async () =>
+ {
+ await Task.Delay(2000);
+ BeginInvoke(new Action(() => ApplyAmdPresetOnStartup(attempts)));
+ });
+ }
+ }
+ }
+ }
+ }
+
private void miNvPresetApplyOnStartup_Click(object sender, EventArgs e)
{
var preset = GetSelectedNvPreset();
@@ -2117,12 +1896,327 @@ Do you want to continue?";
private void chkLgAlternateWolMechanism_CheckedChanged(object sender, EventArgs e)
{
- _lgService.Config.UseAlternateWol = chkLgAlternateWolMechanism.Checked;
+ _lgService.Config.UseOldNpcapWol = chkLgOldWolMechanism.Checked;
}
private void MainForm_Deactivate(object sender, EventArgs e)
{
GlobalSave();
}
+
+ private void btnApplyAmd_Click(object sender, EventArgs e)
+ {
+ ApplySelectedAmdPreset();
+ }
+
+ private void btnChangeAmd_Click(object sender, EventArgs e)
+ {
+ mnuAmdPresets.Show(btnChangeAmd, btnChangeAmd.PointToClient(Cursor.Position));
+ }
+
+ private void edtAmdShortcut_TextChanged(object sender, EventArgs e)
+ {
+ var text = edtAmdShortcut.Text;
+
+ var preset = GetSelectedAmdPreset();
+
+ if (preset == null || string.IsNullOrEmpty(text))
+ {
+ edtAmdShortcut.ForeColor = SystemColors.WindowText;
+ }
+ else
+ {
+ edtAmdShortcut.ForeColor = ShortCutExists(text, preset.id) ? Color.Red : SystemColors.WindowText;
+ }
+ }
+
+ private bool ShortCutExists(string shortcut, int presetId)
+ {
+ return
+ (_nvService?.GetPresets().Any(x => x.id != presetId && shortcut.Equals(x.shortcut)) ?? false) ||
+ (_amdService?.GetPresets().Any(x => x.id != presetId && shortcut.Equals(x.shortcut)) ?? false) ||
+ (_lgService?.GetPresets().Any(x => x.id != presetId && shortcut.Equals(x.shortcut)) ?? false);
+ }
+
+ private void edtShortcutLg_TextChanged(object sender, EventArgs e)
+ {
+ var text = edtShortcutLg.Text;
+
+ var preset = GetSelectedLgPreset();
+
+ if (preset == null || string.IsNullOrEmpty(text))
+ {
+ edtShortcutLg.ForeColor = SystemColors.WindowText;
+ }
+ else
+ {
+ edtShortcutLg.ForeColor = ShortCutExists(text, preset.id) ? Color.Red : SystemColors.WindowText;
+ }
+ }
+
+ private void btnSetAmdShortcut_Click(object sender, EventArgs e)
+ {
+ var shortcut = edtAmdShortcut.Text.Trim();
+
+ if (!string.IsNullOrWhiteSpace(shortcut) && !shortcut.Contains("+"))
+ {
+ MessageForms.WarningOk("Invalid shortcut. The shortcut should have modifiers and a normal key.");
+ return;
+ }
+
+ var preset = GetSelectedAmdPreset();
+
+ var clear = !string.IsNullOrEmpty(preset.shortcut);
+
+ preset.shortcut = shortcut;
+
+ AddOrUpdateItemAmd();
+
+ Utils.RegisterShortcut(Handle, preset.id, preset.shortcut, clear);
+ }
+
+ private void btnCloneAmd_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ var newPreset = preset.Clone();
+ AddOrUpdateItemAmd(newPreset);
+ }
+
+ private void btnDeleteAmd_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ if (preset == null)
+ {
+ return;
+ }
+
+ if (!string.IsNullOrEmpty(preset.shortcut))
+ {
+ Utils.UnregisterHotKey(Handle, preset.id);
+ }
+
+ _amdService.GetPresets().Remove(preset);
+
+ var item = lvAmdPresets.SelectedItems[0];
+ lvAmdPresets.Items.Remove(item);
+ }
+
+ private void mnuAmdPresets_Opening(object sender, CancelEventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ miAmdApply.Enabled = preset != null;
+ miAmdPresetApplyOnStartup.Enabled = preset != null;
+ mnuAmdDisplay.Enabled = preset != null;
+ mnuAmdColorSettings.Enabled = preset != null;
+ mnuAmdRefreshRate.Enabled = preset != null;
+ mnuAmdDithering.Enabled = preset != null;
+ mnuAmdHDR.Enabled = preset != null;
+
+ if (preset != null)
+ {
+ miAmdPresetApplyOnStartup.Checked = _config.AmdPresetId_ApplyOnStartup == preset.id;
+
+ if (mnuAmdDisplay.DropDownItems.Count == 1)
+ {
+ var displays = _amdService.GetDisplays();
+ for (var i = 0; i < displays.Count; i++)
+ {
+ var display = displays[i];
+ var name = _amdService.GetFullDisplayName(display);
+
+ var item = mnuAmdDisplay.DropDownItems.Add(name);
+ item.Tag = display;
+ item.Click += displayMenuItemAmd_Click;
+ }
+ }
+
+ Utils.BuildDropDownMenu(mnuAmdColorSettings, "Color depth", typeof(ADLColorDepth), preset, "colorDepth", amdPresetColorDataMenuItem_Click);
+ Utils.BuildDropDownMenu(mnuAmdColorSettings, "Pixel format", typeof(ADLPixelFormat), preset, "pixelFormat", amdPresetColorDataMenuItem_Click);
+
+ if (preset.displayName != _lastDisplayRefreshRates)
+ {
+ while (mnuAmdRefreshRate.DropDownItems.Count > 1)
+ {
+ mnuAmdRefreshRate.DropDownItems.RemoveAt(mnuAmdRefreshRate.DropDownItems.Count - 1);
+ }
+ }
+
+ if (mnuAmdRefreshRate.DropDownItems.Count == 1)
+ {
+ var refreshRates = _amdService.GetAvailableRefreshRates(preset);
+ _lastDisplayRefreshRates = preset.displayName;
+
+ foreach (var refreshRate in refreshRates)
+ {
+ var item = mnuAmdRefreshRate.DropDownItems.Add(refreshRate.ToString() + "Hz");
+ item.Tag = refreshRate;
+ item.Click += refreshRateMenuItemAmd_Click;
+ }
+ }
+
+ miAmdPrimaryDisplay.Checked = preset.primaryDisplay;
+ foreach (var item in mnuAmdDisplay.DropDownItems)
+ {
+ if (item is ToolStripMenuItem)
+ {
+ var menuItem = (ToolStripMenuItem)item;
+ if (menuItem.Tag != null)
+ {
+ menuItem.Checked = ((ADLDisplayInfo)menuItem.Tag).DisplayName.Equals(preset.displayName);
+ }
+ }
+ }
+
+ miAmdColorSettingsIncluded.Checked = preset.applyColorData;
+
+ miAmdRefreshRateIncluded.Checked = preset.applyRefreshRate;
+ foreach (var item in mnuAmdRefreshRate.DropDownItems)
+ {
+ if (item is ToolStripMenuItem)
+ {
+ var menuItem = (ToolStripMenuItem)item;
+ if (menuItem.Tag != null)
+ {
+ menuItem.Checked = (uint)menuItem.Tag == preset.refreshRate;
+ }
+ }
+ }
+
+ miAmdDitheringIncluded.Checked = preset.applyDithering;
+
+ Utils.BuildDropDownMenu(mnuAmdDithering, "Mode", typeof(ADLDitherState), preset, "ditherState", amdPresetColorDataMenuItem_Click);
+
+ miAmdHDRIncluded.Checked = preset.applyHDR;
+ miAmdHDREnabled.Checked = preset.HDREnabled;
+ miAmdHDRToggle.Checked = preset.toggleHDR;
+ }
+ }
+
+ private void miAmdPresetApplyOnStartup_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+ _config.AmdPresetId_ApplyOnStartup = miAmdPresetApplyOnStartup.Checked ? preset.id : 0;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void lvAmdPresets_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+ var enabled = preset != null;
+
+ btnApplyAmd.Enabled = enabled;
+ btnChangeAmd.Enabled = enabled;
+ edtAmdShortcut.Enabled = enabled;
+ btnSetAmdShortcut.Enabled = enabled;
+ btnCloneAmd.Enabled = enabled;
+ btnDeleteAmd.Enabled = enabled;
+
+ if (preset != null)
+ {
+ edtAmdShortcut.Text = preset.shortcut;
+ }
+ else
+ {
+ edtAmdShortcut.Text = string.Empty;
+ }
+ }
+
+ private void amdPresetColorDataMenuItem_Click(object sender, EventArgs e)
+ {
+ var menuItem = (ToolStripMenuItem)sender;
+ var property = (PropertyInfo)menuItem.OwnerItem.Tag;
+
+ var value = menuItem.Tag;
+
+ var preset = GetSelectedAmdPreset();
+
+ property.SetValue(preset, value);
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdColorSettingsIncluded_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.applyColorData = !preset.applyColorData;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdRefreshRateIncluded_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.applyRefreshRate = !preset.applyRefreshRate;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdDitheringIncluded_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.applyDithering = !preset.applyDithering;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdHDRIncluded_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.applyHDR = !preset.applyHDR;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdHDRToggle_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.toggleHDR = !preset.toggleHDR;
+
+ if (preset.toggleHDR)
+ {
+ preset.HDREnabled = false;
+ }
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void miAmdHDREnabled_Click(object sender, EventArgs e)
+ {
+ var preset = GetSelectedAmdPreset();
+
+ preset.HDREnabled = !preset.HDREnabled;
+ preset.toggleHDR = false;
+
+ AddOrUpdateItemAmd();
+ }
+
+ private void btnAddAmd_Click(object sender, EventArgs e)
+ {
+ var presets = AmdPreset.GetDefaultPresets();
+ var added = false;
+
+ foreach (var preset in presets)
+ {
+ AddOrUpdateItemAmd(preset);
+ }
+
+ if (added)
+ {
+ MessageForms.InfoOk("Missing presets added.");
+ }
+ else
+ {
+ MessageForms.InfoOk("All presets for every color setting already exist.");
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ColorControl/MainForm.resx b/ColorControl/MainForm.resx
index 7b37833..3c2e711 100644
--- a/ColorControl/MainForm.resx
+++ b/ColorControl/MainForm.resx
@@ -120,6 +120,9 @@
17, 17
+
+ 278, 17
+
147, 17
diff --git a/ColorControl/NvDisplayInfo.cs b/ColorControl/NvDisplayInfo.cs
new file mode 100644
index 0000000..316d1f0
--- /dev/null
+++ b/ColorControl/NvDisplayInfo.cs
@@ -0,0 +1,21 @@
+using NvAPIWrapper.Display;
+using System.Collections.Generic;
+
+namespace ColorControl
+{
+ class NvDisplayInfo
+ {
+ public Display Display { get; }
+
+ public List Values { get; }
+
+ public string InfoLine { get; }
+
+ public NvDisplayInfo(Display display, List values, string infoLine)
+ {
+ Display = display;
+ Values = values;
+ InfoLine = infoLine;
+ }
+ }
+}
diff --git a/ColorControl/NvPreset.cs b/ColorControl/NvPreset.cs
index cc9ff63..3df171d 100644
--- a/ColorControl/NvPreset.cs
+++ b/ColorControl/NvPreset.cs
@@ -76,7 +76,7 @@ namespace ColorControl
return new[] { "Display|140", "Color settings (BPC, format, dyn. range, color space)|260", "Refresh rate|100", "Dithering", "HDR", "Shortcut", "Apply on startup" };
}
- public List GetDisplayValues(Config config)
+ public override List GetDisplayValues(Config config = null)
{
var values = new List();
@@ -99,7 +99,7 @@ namespace ColorControl
//values.Add(toggleHDR.ToString());
values.Add(shortcut);
- values.Add(string.Format("{0}", config.NvPresetId_ApplyOnStartup == id ? "Yes" : string.Empty));
+ values.Add(string.Format("{0}", config?.NvPresetId_ApplyOnStartup == id ? "Yes" : string.Empty));
return values;
}
diff --git a/ColorControl/NvService.cs b/ColorControl/NvService.cs
index 0ead587..7468eca 100644
--- a/ColorControl/NvService.cs
+++ b/ColorControl/NvService.cs
@@ -6,8 +6,11 @@ using NvAPIWrapper.Native.GPU.Structures;
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Windows.Forms;
+using Windows.Graphics.Display;
namespace ColorControl
{
@@ -63,12 +66,17 @@ namespace ColorControl
public uint mode;
};
+ private List _presets;
+
private Display _currentDisplay;
- private bool _initialized = false;
private NvPreset _lastAppliedPreset;
- public NvService()
+ public NvService(string dataPath) : base(dataPath)
{
+ var converter = new ColorDataConverter();
+ _JsonDeserializer.RegisterConverters(new[] { converter });
+
+ LoadPresets();
}
public Display GetCurrentDisplay()
@@ -93,6 +101,45 @@ namespace ColorControl
}
}
+ public void GlobalSave()
+ {
+ SavePresets();
+ }
+
+ public List GetPresets()
+ {
+ return _presets;
+ }
+
+ private void LoadPresets()
+ {
+ _presetsFilename = Path.Combine(_dataPath, "NvPresets.json");
+
+ if (File.Exists(_presetsFilename))
+ {
+ var json = File.ReadAllText(_presetsFilename);
+
+ _presets = _JsonDeserializer.Deserialize>(json);
+ }
+ else
+ {
+ _presets = NvPreset.GetDefaultPresets();
+ }
+ }
+
+ private void SavePresets()
+ {
+ try
+ {
+ var json = _JsonSerializer.Serialize(_presets);
+ File.WriteAllText(_presetsFilename, json);
+ }
+ catch (Exception e)
+ {
+ Logger.Error(e.ToLogString());
+ }
+ }
+
private void SetCurrentDisplay(NvPreset preset)
{
if (preset.primaryDisplay)
@@ -106,7 +153,6 @@ namespace ColorControl
}
}
-
public bool ApplyPreset(NvPreset preset, Config config)
{
var result = true;
@@ -326,6 +372,67 @@ namespace ColorControl
return Display.GetDisplays();
}
+ public List GetDisplayInfos()
+ {
+ Display[] displays;
+ try
+ {
+ displays = GetDisplays();
+ }
+ catch (Exception e)
+ {
+ Logger.Error("Error while getting displays: " + e.ToLogString());
+ return null;
+ }
+
+ var list = new List();
+
+ foreach (var display in displays)
+ {
+ var values = new List();
+
+ var name = display.Name;
+
+ var screen = Screen.AllScreens.FirstOrDefault(x => x.DeviceName.Equals(name));
+ if (screen != null)
+ {
+ name += " (" + screen.DeviceFriendlyName() + ")";
+ }
+
+ values.Add(name);
+
+ var colorData = display.DisplayDevice.CurrentColorData;
+ var colorSettings = string.Format("{0}, {1}, {2}, {3}", colorData.ColorDepth, colorData.ColorFormat, colorData.DynamicRange, colorData.Colorimetry);
+
+ values.Add(colorSettings);
+
+ var refreshRate = display.DisplayDevice.CurrentTiming.Extra.RefreshRate;
+
+ values.Add($"{refreshRate}Hz");
+
+ var lastPreset = GetLastAppliedPreset();
+ if (lastPreset != null)
+ {
+ values.Add(lastPreset.GetDitheringDescription());
+ }
+ else
+ {
+ values.Add(string.Empty);
+ }
+
+ var hdrEnabled = IsHDREnabled();
+ values.Add(hdrEnabled ? "Yes" : "No");
+
+ var infoLine = string.Format("{0}: {1}, {2}Hz, HDR: {3}", name, colorSettings, refreshRate, hdrEnabled ? "Yes" : "No");
+
+ var displayInfo = new NvDisplayInfo(display, values, infoLine);
+
+ list.Add(displayInfo);
+ }
+
+ return list;
+ }
+
public NvPreset GetLastAppliedPreset()
{
return _lastAppliedPreset;
diff --git a/ColorControl/PresetBase.cs b/ColorControl/PresetBase.cs
index a4301b7..eea6db3 100644
--- a/ColorControl/PresetBase.cs
+++ b/ColorControl/PresetBase.cs
@@ -45,5 +45,6 @@ namespace ColorControl
return id;
}
+ public abstract List GetDisplayValues(Config config = null);
}
}
\ No newline at end of file
diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs
index 11801a9..cbed0f4 100644
--- a/ColorControl/Properties/AssemblyInfo.cs
+++ b/ColorControl/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.6.0.0")]
-[assembly: AssemblyFileVersion("1.6.0.0")]
+[assembly: AssemblyVersion("2.0.0.0")]
+[assembly: AssemblyFileVersion("2.0.0.0")]
diff --git a/ColorControl/RemoteControlForm.cs b/ColorControl/RemoteControlForm.cs
index 417264c..5c659bb 100644
--- a/ColorControl/RemoteControlForm.cs
+++ b/ColorControl/RemoteControlForm.cs
@@ -2,11 +2,8 @@
using NWin32;
using System;
using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
using System.Drawing;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -53,7 +50,7 @@ namespace ColorControl
{
var preset = (LgPreset)(sender as Button).Tag;
- _lgService.ApplyPreset(preset);
+ var _ = _lgService.ApplyPreset(preset);
}
}
@@ -95,7 +92,7 @@ namespace ColorControl
var preset = _buttons.FirstOrDefault(p => p.shortcut != null && p.shortcut.Equals(shortcut));
if (preset != null)
{
- _lgService.ApplyPreset(preset);
+ var _ = _lgService.ApplyPreset(preset);
}
}
diff --git a/ColorControl/RestartDetector.cs b/ColorControl/RestartDetector.cs
index e4618b4..1a752f3 100644
--- a/ColorControl/RestartDetector.cs
+++ b/ColorControl/RestartDetector.cs
@@ -32,7 +32,7 @@ namespace ColorControl
// Activate the subscription
watcher.Enabled = true;
}
- catch (EventLogReadingException e)
+ catch (EventLogReadingException)
{
}
}
@@ -81,7 +81,7 @@ namespace ColorControl
// }
//}
}
- catch (Exception e)
+ catch (Exception)
{
}
}
diff --git a/ColorControl/ServiceBase.cs b/ColorControl/ServiceBase.cs
new file mode 100644
index 0000000..3d57f4d
--- /dev/null
+++ b/ColorControl/ServiceBase.cs
@@ -0,0 +1,40 @@
+using System.Web.Script.Serialization;
+
+namespace ColorControl
+{
+ class ServiceBase
+ {
+ protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
+
+ protected string _dataPath;
+ protected string _presetsFilename;
+ protected JavaScriptSerializer _JsonSerializer;
+ protected JavaScriptSerializer _JsonDeserializer;
+ protected bool _initialized = false;
+
+ public ServiceBase(string dataPath)
+ {
+ _dataPath = dataPath;
+
+ _JsonSerializer = new JavaScriptSerializer();
+ _JsonDeserializer = new JavaScriptSerializer();
+
+ Initialize();
+ }
+
+ ~ServiceBase()
+ {
+ Uninitialize();
+ }
+
+ protected virtual void Initialize()
+ {
+
+ }
+
+ protected virtual void Uninitialize()
+ {
+
+ }
+ }
+}
diff --git a/ColorControl/Utils.cs b/ColorControl/Utils.cs
index 549d8d2..06a8486 100644
--- a/ColorControl/Utils.cs
+++ b/ColorControl/Utils.cs
@@ -1,13 +1,19 @@
using Microsoft.Win32;
+using Microsoft.Win32.TaskScheduler;
+using NStandard;
+using NvAPIWrapper.Display;
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Deployment.Application;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -27,15 +33,20 @@ namespace ColorControl
Win = 8
}
- public static string PKEY_PNPX_IpAddress = "{656a3bb3-ecc0-43fd-8477-4ae0404a96cd} 12297";
- public static string PKEY_PNPX_PhysicalAddress = "{656a3bb3-ecc0-43fd-8477-4ae0404a96cd} 12294";
+ public static string PKEY_PNPX_IpAddress = "{656a3bb3-ecc0-43fd-8477-4ae0404a96cd} 12297";
+ public static string PKEY_PNPX_PhysicalAddress = "{656a3bb3-ecc0-43fd-8477-4ae0404a96cd} 12294";
+
+ [DllImport("user32.dll")]
+ public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
+ [DllImport("user32.dll")]
+ public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
-
+ private static bool WinKeyDown = false;
public static Bitmap SubPixelShift(Bitmap bitmap)
{
- Bitmap bitmap2 = (Bitmap) bitmap.Clone();
+ Bitmap bitmap2 = (Bitmap)bitmap.Clone();
int shift = -1;
bool shiftRed = true;
@@ -193,7 +204,7 @@ namespace ColorControl
internal static void GetRegistryKeyValue(string keyname, string valueName, bool deepSearch = false)
{
var key = Registry.LocalMachine.OpenSubKey(keyname);
-
+
foreach (var subKeyName in key.GetSubKeyNames())
{
var subKey = key.OpenSubKey(subKeyName);
@@ -270,9 +281,11 @@ namespace ColorControl
var list = await DeviceInformation.FindAllAsync("", new List());
- var reqs = new List();
- reqs.Add(PKEY_PNPX_IpAddress);
- reqs.Add(PKEY_PNPX_PhysicalAddress);
+ var reqs = new List
+ {
+ PKEY_PNPX_IpAddress,
+ PKEY_PNPX_PhysicalAddress
+ };
foreach (var dev in list)
{
@@ -301,7 +314,7 @@ namespace ColorControl
return devices;
}
- public static void WaitForTask(Task task)
+ public static void WaitForTask(System.Threading.Tasks.Task task)
{
while (task != null && (task.Status < TaskStatus.WaitingForChildrenToComplete))
{
@@ -374,5 +387,222 @@ namespace ColorControl
}
return list;
}
+
+ public static void RegisterTask(string taskName, bool enabled)
+ {
+ var file = Assembly.GetExecutingAssembly().Location;
+ var directory = Path.GetDirectoryName(file);
+
+ try
+ {
+ using (TaskService ts = new TaskService())
+ {
+ if (enabled)
+ {
+ TaskDefinition td = ts.NewTask();
+ td.RegistrationInfo.Description = "Start ColorControl";
+
+ td.Triggers.Add(new LogonTrigger { UserId = WindowsIdentity.GetCurrent().Name });
+
+ td.Actions.Add(new ExecAction(file, StartUpParams.RunningFromScheduledTaskParam, directory));
+
+ ts.RootFolder.RegisterTaskDefinition(taskName, td);
+ }
+ else
+ {
+ ts.RootFolder.DeleteTask(taskName, false);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageForms.ErrorOk("Could not create/delete task: " + e.Message);
+ }
+ }
+
+ public static bool TaskExists(string taskName, bool update)
+ {
+ var file = Assembly.GetExecutingAssembly().Location;
+ using (TaskService ts = new TaskService())
+ {
+ var task = ts.RootFolder.Tasks.FirstOrDefault(x => x.Name.Equals(taskName));
+
+ if (task != null)
+ {
+ if (update && ApplicationDeployment.IsNetworkDeployed)
+ {
+ var action = task.Definition.Actions.FirstOrDefault(x => x.ActionType == TaskActionType.Execute);
+ if (action != null)
+ {
+ var execAction = action as ExecAction;
+ if (!execAction.Path.Equals(file))
+ {
+ RegisterTask(taskName, false);
+ RegisterTask(taskName, true);
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ }
+
+ public static void RegisterShortcut(IntPtr handle, int id, string shortcut, bool clear = false)
+ {
+ if (clear)
+ {
+ UnregisterHotKey(handle, id);
+ }
+
+ if (!string.IsNullOrEmpty(shortcut))
+ {
+ var (mods, key) = ParseShortcut(shortcut);
+ RegisterHotKey(handle, id, mods, key);
+ }
+ }
+
+ public static void BuildDropDownMenu(ToolStripMenuItem mnuParent, string name, Type enumType, object colorData, string propertyName, EventHandler clickEvent)
+ {
+ PropertyInfo property;
+ var subMenuItems = mnuParent.DropDownItems.Find("miColorSettings_" + name, false);
+ ToolStripMenuItem subMenuItem;
+ if (subMenuItems.Length == 0)
+ {
+ subMenuItem = (ToolStripMenuItem)mnuParent.DropDownItems.Add(name);
+ subMenuItem.Name = "miColorSettings_" + name;
+
+ property = colorData.GetType().GetDeclaredProperty(propertyName);
+ subMenuItem.Tag = property;
+
+ foreach (var enumValue in Enum.GetValues(enumType))
+ {
+ var item = subMenuItem.DropDownItems.Add(enumValue.ToString());
+ item.Tag = enumValue;
+ item.Click += clickEvent;
+ }
+ }
+ else
+ {
+ subMenuItem = (ToolStripMenuItem)subMenuItems[0];
+ property = (PropertyInfo)subMenuItem.Tag;
+ }
+
+ var value = property.GetValue(colorData);
+
+ foreach (var item in subMenuItem.DropDownItems)
+ {
+ if (item is ToolStripMenuItem)
+ {
+ var menuItem = (ToolStripMenuItem)item;
+ if (menuItem.Tag != null)
+ {
+ menuItem.Checked = menuItem.Tag.Equals(value);
+ }
+ }
+ }
+ }
+
+ public static string FormatKeyboardShortcut(KeyEventArgs keyEvent)
+ {
+ var pressedModifiers = keyEvent.Modifiers;
+
+ //Debug.WriteLine("KD: " + e.Modifiers + ", " + e.KeyCode);
+
+ var shortcutString = (pressedModifiers > 0 ? pressedModifiers.ToString() : "");
+ if (keyEvent.KeyCode == Keys.LWin || WinKeyDown)
+ {
+ WinKeyDown = true;
+ if (!string.IsNullOrEmpty(shortcutString))
+ {
+ shortcutString += ", ";
+ }
+ shortcutString += "Win";
+ }
+
+ if (!string.IsNullOrEmpty(shortcutString) && keyEvent.KeyCode != Keys.ControlKey && keyEvent.KeyCode != Keys.ShiftKey && keyEvent.KeyCode != Keys.Menu && keyEvent.KeyCode != Keys.LWin)
+ {
+ shortcutString += " + " + keyEvent.KeyCode.ToString();
+ }
+
+ if (pressedModifiers == 0 && !WinKeyDown)
+ {
+ keyEvent.SuppressKeyPress = true;
+ }
+
+ return shortcutString;
+ }
+
+ public static void HandleKeyboardShortcutUp(KeyEventArgs keyEvent)
+ {
+ if (keyEvent.KeyCode == Keys.LWin)
+ {
+ WinKeyDown = false;
+ }
+ }
+
+ public static void InitListView(ListView listView, IEnumerable columns)
+ {
+ foreach (var name in columns)
+ {
+ var columnName = name;
+ var parts = name.Split('|');
+
+ var width = 120;
+ if (parts.Length > 1)
+ {
+ width = int.Parse(parts[1]);
+ columnName = parts[0];
+ }
+
+ var header = listView.Columns.Add(columnName);
+ header.Width = width == 120 ? -2 : width;
+ }
+ }
+
+ public static void AddOrUpdateListItem(ListView listView, List presets, Config config, T preset = null, ListViewItem specItem = null) where T : PresetBase
+ {
+ ListViewItem item = null;
+ if (preset == null)
+ {
+ item = listView.SelectedItems[0];
+ preset = (T)item.Tag;
+ }
+ else
+ {
+ item = specItem;
+ }
+
+ if (preset.id == 0)
+ {
+ preset.id = preset.GetHashCode();
+ }
+
+ var values = preset.GetDisplayValues(config);
+
+ if (item == null)
+ {
+ item = listView.Items.Add(values[0]);
+ item.Tag = preset;
+ for (var i = 1; i < values.Count; i++)
+ {
+ item.SubItems.Add(values[i]);
+ }
+ if (!presets.Any(x => x.id == preset.id))
+ {
+ presets.Add(preset);
+ }
+ }
+ else
+ {
+ item.Text = values[0];
+ for (var i = 1; i < values.Count; i++)
+ {
+ item.SubItems[i].Text = values[i];
+ }
+ }
+ }
+
+
}
}
diff --git a/ColorControl/WOL.cs b/ColorControl/WOL.cs
index 7f13185..030b904 100644
--- a/ColorControl/WOL.cs
+++ b/ColorControl/WOL.cs
@@ -17,48 +17,56 @@ namespace ColorControl
private const string ArgumentExceptionInvalidPasswordLength = "Invalid password length.";
private const int DefaultWolPort = 9;
- public static void WakeFunction(string macAddress, bool usePcap = false)
+ public static bool WakeFunction(string macAddress, bool usePcap = false)
{
if (usePcap)
{
- WakeFunctionPcap(macAddress);
- }
- else
- {
- WakeFunctionToAllNics(macAddress);
+ return WakeFunctionPcap(macAddress);
}
+
+ return WakeFunctionToAllNics(macAddress);
}
- public static void WakeFunctionToAllNics(string macAddress)
+ public static bool WakeFunctionToAllNics(string macAddress)
{
+ var result = false;
+
try
{
var address = PhysicalAddress.Parse(macAddress);
var addressBytes = address.GetAddressBytes();
var data = GetWolPacket(addressBytes);
- foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
+ var interfaces = NetworkInterface.GetAllNetworkInterfaces();
+
+ foreach (var ni in interfaces)
{
- Logger.Debug($"Found network: {ni.Name} ({ni.Description})");
+ if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback || ni.Name.Contains("VirtualBox"))
+ {
+ continue;
+ }
+ Logger.Debug($"Found network: {ni.Name} ({ni.Description}), type: {ni.NetworkInterfaceType}");
try
{
if (/*ni.OperationalStatus == OperationalStatus.Up &&*/ ni.SupportsMulticast && ni.GetIPProperties().GetIPv4Properties() != null)
{
- var id = ni.GetIPProperties().GetIPv4Properties().Index;
- if (NetworkInterface.LoopbackInterfaceIndex != id)
+ foreach (var uip in ni.GetIPProperties().UnicastAddresses)
{
- foreach (var uip in ni.GetIPProperties().UnicastAddresses)
+ if (uip.Address.ToString().StartsWith("169.254"))
{
- if (uip.Address.AddressFamily == AddressFamily.InterNetwork)
- {
- Logger.Debug($"Broadcast WOL in network: {ni.Name} ({ni.Description}), local address: {uip.Address}");
- var local = new IPEndPoint(uip.Address, 0);
- var udpc = new UdpClient(local);
- udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
- udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontRoute, 1);
- var target = new IPEndPoint(IPAddress.Broadcast, DefaultWolPort);
- udpc.Send(data, data.Length, target);
- }
+ continue;
+ }
+ if (uip.Address.AddressFamily == AddressFamily.InterNetwork)
+ {
+ Logger.Debug($"Broadcast WOL in network: {ni.Name} ({ni.Description}), local address: {uip.Address}");
+ var local = new IPEndPoint(uip.Address, 0);
+ var udpc = new UdpClient(local);
+ udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
+ udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontRoute, 1);
+ var target = new IPEndPoint(IPAddress.Broadcast, DefaultWolPort);
+ udpc.Send(data, data.Length, target);
+
+ result = true;
}
}
}
@@ -73,6 +81,8 @@ namespace ColorControl
{
Logger.Error($"WakeFunctionToAllNics: {ex.ToLogString()}");
}
+
+ return result;
}
/// is null.
@@ -110,7 +120,7 @@ namespace ColorControl
//You need SharpPcap for this to work
- private static void WakeFunctionPcap(string macAddress)
+ private static bool WakeFunctionPcap(string macAddress)
{
/* Retrieve the device list */
var devices = CaptureDeviceList.Instance;
@@ -121,7 +131,7 @@ namespace ColorControl
if (devices.Count < 1)
{
Logger.Debug("No network device found on this machine");
- return;
+ return false;
}
foreach (var device in devices)
@@ -169,6 +179,8 @@ namespace ColorControl
device.Close();
}
+
+ return true;
}
}
}
\ No newline at end of file
diff --git a/ColorControl/lgtv/LgTvApi.cs b/ColorControl/lgtv/LgTvApi.cs
index 8b3aefc..f59515a 100644
--- a/ColorControl/lgtv/LgTvApi.cs
+++ b/ColorControl/lgtv/LgTvApi.cs
@@ -297,6 +297,15 @@ namespace LgTv
return _appList.OrderBy(e => e.Title);
}
+ public async Task> GetServiceList()
+ {
+ var list = new List();
+ var requestMessage = new RequestMessage("channels", "ssap://api/getServiceList");
+ var command = _connection.SendCommandAsync(requestMessage);
+ var res = await command;
+ return list;
+ }
+
public async Task> GetApps(bool force = false)
{
var appList = new List();
diff --git a/ColorControl/lgtv/LgTvConnection.cs b/ColorControl/lgtv/LgTvConnection.cs
index ecfa61b..46f8ff2 100644
--- a/ColorControl/lgtv/LgTvConnection.cs
+++ b/ColorControl/lgtv/LgTvConnection.cs
@@ -77,7 +77,7 @@ namespace LgTv
_messageWriter.WriteString(message);
await _messageWriter.StoreAsync();
}
- catch (Exception e)
+ catch (Exception)
{
ConnectionClosed = true;
_messageWriter?.Dispose();