diff --git a/DisplayMagicianShared/Windows/CCD.cs b/DisplayMagicianShared/Windows/CCD.cs index 47a5a13..6ad13b8 100644 --- a/DisplayMagicianShared/Windows/CCD.cs +++ b/DisplayMagicianShared/Windows/CCD.cs @@ -639,7 +639,7 @@ namespace DisplayMagicianShared.Windows // This happens when it is a target mode info block if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET && - Id == other.Id && + Id == other.Id && // Disabling this check as as the Display ID it maps to will change after a switch from clone to non-clone profile, ruining the equality match TargetMode.Equals(other.TargetMode)) return true; @@ -652,13 +652,13 @@ namespace DisplayMagicianShared.Windows // This happens when it is a desktop image mode info block if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE && - Id == other.Id && + Id == other.Id && // Disabling this check as as the Display ID it maps to will change after a switch from clone to non-clone profile, ruining the equality match DesktopImageInfo.Equals(other.DesktopImageInfo)) return true; // This happens when it is a clone - there is an extra entry with all zeros in it! if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.Zero && - Id == other.Id && + //Id == other.Id && // Disabling this check as as the Display ID it maps to will change after a switch from clone to non-clone profile, ruining the equality match DesktopImageInfo.Equals(other.DesktopImageInfo) && TargetMode.Equals(other.TargetMode) && SourceMode.Equals(other.SourceMode)) @@ -672,15 +672,20 @@ namespace DisplayMagicianShared.Windows { if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) return (InfoType, Id, TargetMode).GetHashCode(); + //return (InfoType, TargetMode).GetHashCode(); if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) - return (InfoType, Id, SourceMode).GetHashCode(); + //return (InfoType, Id, SourceMode).GetHashCode(); + return (InfoType, SourceMode).GetHashCode(); + if (InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE) return (InfoType, Id, DesktopImageInfo).GetHashCode(); + //return (InfoType, DesktopImageInfo).GetHashCode(); // otherwise we return everything return (InfoType, Id, TargetMode, SourceMode, DesktopImageInfo).GetHashCode(); + //return (InfoType, TargetMode, SourceMode, DesktopImageInfo).GetHashCode(); } public static bool operator ==(DISPLAYCONFIG_MODE_INFO lhs, DISPLAYCONFIG_MODE_INFO rhs) => lhs.Equals(rhs); diff --git a/DisplayMagicianShared/Windows/GDI.cs b/DisplayMagicianShared/Windows/GDI.cs index 95d0057..2c51295 100644 --- a/DisplayMagicianShared/Windows/GDI.cs +++ b/DisplayMagicianShared/Windows/GDI.cs @@ -364,12 +364,12 @@ namespace DisplayMagicianShared.Windows public bool Equals(DEVICE_MODE other) => //DeviceName.Equals(other.DeviceName) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching - //SpecificationVersion == other.SpecificationVersion && - //DriverVersion.Equals(other.DriverVersion) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching - //Size.Equals(other.Size) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching - //DriverExtra.Equals(other.DriverExtra) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching - //Fields.Equals(other.Fields) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching - //Position.Equals(other.Position) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching + //SpecificationVersion == other.SpecificationVersion && + //DriverVersion.Equals(other.DriverVersion) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching + //Size.Equals(other.Size) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching + //DriverExtra.Equals(other.DriverExtra) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching + //Fields.Equals(other.Fields) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching + //Position.Equals(other.Position) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching DisplayOrientation.Equals(other.DisplayOrientation) && //DisplayFixedOutput.Equals(other.DisplayFixedOutput) && //Color.Equals(other.Color) && // Removed specifically for DisplayMagician matching. Remove if you need true equality matching @@ -425,13 +425,14 @@ namespace DisplayMagicianShared.Windows => Size == other.Size && // DeviceName == other.DeviceName && // Had to remove this as the device name often changes after a reboot! DeviceString == other.DeviceString && - StateFlags == other.StateFlags && - DeviceId == other.DeviceId && - DeviceKey == other.DeviceKey; + //StateFlags == other.StateFlags && + DeviceId == other.DeviceId; + //DeviceKey == other.DeviceKey; public override int GetHashCode() { - return (Size, DeviceName, DeviceString, StateFlags, DeviceId, DeviceKey).GetHashCode(); + //return (Size, DeviceName, DeviceString, StateFlags, DeviceId, DeviceKey).GetHashCode(); + return (Size, DeviceString, DeviceId).GetHashCode(); } public static bool operator ==(DISPLAY_DEVICE lhs, DISPLAY_DEVICE rhs) => lhs.Equals(rhs); @@ -511,13 +512,14 @@ namespace DisplayMagicianShared.Windows public bool Equals(GDI_DISPLAY_SETTING other) => IsEnabled == other.IsEnabled && - IsPrimary == other.IsPrimary && + //IsPrimary == other.IsPrimary && Device.Equals(other.Device) && DeviceMode.Equals(other.DeviceMode); public override int GetHashCode() { - return (IsEnabled, IsPrimary, Device, DeviceMode).GetHashCode(); + //return (IsEnabled, IsPrimary, Device, DeviceMode).GetHashCode(); + return (IsEnabled, Device, DeviceMode).GetHashCode(); } public static bool operator ==(GDI_DISPLAY_SETTING lhs, GDI_DISPLAY_SETTING rhs) => lhs.Equals(rhs); diff --git a/DisplayMagicianShared/Windows/WinLibrary.cs b/DisplayMagicianShared/Windows/WinLibrary.cs index 74548db..e75e794 100644 --- a/DisplayMagicianShared/Windows/WinLibrary.cs +++ b/DisplayMagicianShared/Windows/WinLibrary.cs @@ -56,12 +56,16 @@ namespace DisplayMagicianShared.Windows DisplayConfigPaths.SequenceEqual(other.DisplayConfigPaths) && DisplayConfigModes.SequenceEqual(other.DisplayConfigModes) && DisplayHDRStates.SequenceEqual(other.DisplayHDRStates) && - GdiDisplaySettings.SequenceEqual(other.GdiDisplaySettings) && + // 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. + GdiDisplaySettings.Values.SequenceEqual(other.GdiDisplaySettings.Values) && DisplayIdentifiers.SequenceEqual(other.DisplayIdentifiers); public override int GetHashCode() { - return (DisplayConfigPaths, DisplayConfigModes, DisplayHDRStates, GdiDisplaySettings, IsCloned, DisplayIdentifiers).GetHashCode(); + //return (DisplayConfigPaths, DisplayConfigModes, DisplayHDRStates, GdiDisplaySettings.Values, IsCloned, DisplayIdentifiers).GetHashCode(); + return (DisplayConfigPaths, DisplayConfigModes, DisplayHDRStates, IsCloned, DisplayIdentifiers).GetHashCode(); } public static bool operator ==(WINDOWS_DISPLAY_CONFIG lhs, WINDOWS_DISPLAY_CONFIG rhs) => lhs.Equals(rhs); @@ -1566,6 +1570,25 @@ namespace DisplayMagicianShared.Windows } + public static bool GDISettingsEqual(Dictionary gdi1, Dictionary gdi2) + { + if (gdi1.Count == gdi2.Count) + { + for (int i = 0; i < gdi1.Count; i++) + { + if (gdi1.Values.ToList()[i] != gdi2.Values.ToList()[i]) + { + return false; + } + } + return true; + } + else + { + return false; + } + } + } [global::System.Serializable]