Skip to content

Commit

Permalink
Fixed issue with cloned displays and WinLibrary
Browse files Browse the repository at this point in the history
Also updated version to v1.7.8
  • Loading branch information
terrymacdonald committed Jun 3, 2022
1 parent 6581088 commit e0e9748
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
4 changes: 2 additions & 2 deletions AMDInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static void Main(string[] args)
NLog.LogManager.Configuration = config;

// Start the Log file
SharedLogger.logger.Info($"AMDInfo/Main: Starting AMDInfo v1.7.7");
SharedLogger.logger.Info($"AMDInfo/Main: Starting AMDInfo v1.7.8");


Console.WriteLine($"\nAMDInfo v1.7.7");
Console.WriteLine($"\nAMDInfo v1.7.8");
Console.WriteLine($"==============");
Console.WriteLine($"By Terry MacDonald 2022\n");

Expand Down
4 changes: 2 additions & 2 deletions AMDInfo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.7.7.0")]
[assembly: AssemblyFileVersion("1.7.7.0")]
[assembly: AssemblyVersion("1.7.8.0")]
[assembly: AssemblyFileVersion("1.7.8.0")]
62 changes: 57 additions & 5 deletions AMDInfo/WinLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public struct DISPLAY_SOURCE : IEquatable<DISPLAY_SOURCE>

public override bool Equals(object obj) => obj is DISPLAY_SOURCE other && this.Equals(other);
public bool Equals(DISPLAY_SOURCE other)
=> SourceId.Equals(other.SourceId) &&
TargetId.Equals(other.TargetId) &&
=> //SourceId.Equals(other.SourceId) && // Source ID needs to be ignored in this case, as windows moves the source ids around :(
TargetId.Equals(other.TargetId) &&
DevicePath.Equals(other.DevicePath) &&
SourceDpiScalingRel.Equals(other.SourceDpiScalingRel);
//=> true;
public override int GetHashCode()
{
//return 300;
return (SourceId, TargetId, DevicePath, SourceDpiScalingRel).GetHashCode();
//return (SourceId, TargetId, DevicePath, SourceDpiScalingRel).GetHashCode(); // Source ID needs to be ignored in this case, as windows moves the source ids around :(
return (TargetId, DevicePath, SourceDpiScalingRel).GetHashCode();
}

public static bool operator ==(DISPLAY_SOURCE lhs, DISPLAY_SOURCE rhs) => lhs.Equals(rhs);
Expand Down Expand Up @@ -91,7 +91,6 @@ public bool Equals(WINDOWS_DISPLAY_CONFIG other)
if (!(IsCloned == other.IsCloned &&
DisplayConfigPaths.SequenceEqual(other.DisplayConfigPaths) &&
DisplayConfigModes.SequenceEqual(other.DisplayConfigModes) &&
DisplayHDRStates.SequenceEqual(other.DisplayHDRStates) &&
// The dictionary keys sometimes change after returning from NVIDIA Surround, so we need to only focus on comparing the values of the GDISettings.
// Additionally, we had to disable the DEviceKey from the equality testing within the GDI library itself as that waould also change after changing back from NVIDIA surround
// This still allows us to detect when refresh rates change, which will allow DisplayMagician to detect profile differences.
Expand All @@ -101,6 +100,12 @@ public bool Equals(WINDOWS_DISPLAY_CONFIG other)
return false;
}

// Now we need to go through the HDR states comparing vaues, as the order changes if there is a cloned display
if (!WinLibrary.EqualButDifferentOrder<ADVANCED_HDR_INFO_PER_PATH>(DisplayHDRStates, other.DisplayHDRStates))
{
return false;
}

// Now we need to go through the values to make sure they are the same, but ignore the keys (as they change after each reboot!)
for (int i = 0; i < DisplaySources.Count; i++)
{
Expand Down Expand Up @@ -2361,6 +2366,53 @@ private static void RefreshTrayArea(IntPtr windowHandle)
Utils.SendMessage(windowHandle, Utils.WM_MOUSEMOVE, 0, (y << 16) + x);
}

public static bool EqualButDifferentOrder<T>(IList<T> list1, IList<T> list2)
{

if (list1.Count != list2.Count)
{
return false;
}

// Now we need to go through the list1, checking that all it's items are in list2
foreach (T item1 in list1)
{
bool foundIt = false;
foreach (T item2 in list2)
{
if (item1.Equals(item2))
{
foundIt = true;
break;
}
}
if (!foundIt)
{
return false;
}
}

// Now we need to go through the list2, checking that all it's items are in list1
foreach (T item2 in list2)
{
bool foundIt = false;
foreach (T item1 in list1)
{
if (item1.Equals(item2))
{
foundIt = true;
break;
}
}
if (!foundIt)
{
return false;
}
}

return true;
}

}

[global::System.Serializable]
Expand Down

0 comments on commit e0e9748

Please sign in to comment.