diff --git a/DisplayMagicianShared/NVIDIA/NVAPI.cs b/DisplayMagicianShared/NVIDIA/NVAPI.cs index 093352b..a3502a7 100644 --- a/DisplayMagicianShared/NVIDIA/NVAPI.cs +++ b/DisplayMagicianShared/NVIDIA/NVAPI.cs @@ -630,6 +630,8 @@ namespace DisplayMagicianShared.NVIDIA { public IntPtr Ptr; + public override bool Equals(object obj) => obj is DisplayHandle other && this.Equals(other); + public bool Equals(DisplayHandle other) => Ptr == other.Ptr; @@ -637,6 +639,10 @@ namespace DisplayMagicianShared.NVIDIA { return (Ptr).GetHashCode(); } + + public static bool operator ==(DisplayHandle lhs, DisplayHandle rhs) => lhs.Equals(rhs); + + public static bool operator !=(DisplayHandle lhs, DisplayHandle rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -644,6 +650,8 @@ namespace DisplayMagicianShared.NVIDIA { public IntPtr Ptr; + public override bool Equals(object obj) => obj is UnAttachedDisplayHandle other && this.Equals(other); + public bool Equals(UnAttachedDisplayHandle other) => Ptr == other.Ptr; @@ -651,12 +659,19 @@ namespace DisplayMagicianShared.NVIDIA { return (Ptr).GetHashCode(); } + + public static bool operator ==(UnAttachedDisplayHandle lhs, UnAttachedDisplayHandle rhs) => lhs.Equals(rhs); + + public static bool operator !=(UnAttachedDisplayHandle lhs, UnAttachedDisplayHandle rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct PhysicalGpuHandle : IEquatable { public IntPtr Ptr; + + public override bool Equals(object obj) => obj is PhysicalGpuHandle other && this.Equals(other); + public bool Equals(PhysicalGpuHandle other) => Ptr == other.Ptr; @@ -664,6 +679,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Ptr).GetHashCode(); } + public static bool operator ==(PhysicalGpuHandle lhs, PhysicalGpuHandle rhs) => lhs.Equals(rhs); + + public static bool operator !=(PhysicalGpuHandle lhs, PhysicalGpuHandle rhs) => !(lhs == rhs); } @@ -671,6 +689,9 @@ namespace DisplayMagicianShared.NVIDIA public struct LogicalGpuHandle : IEquatable { public IntPtr Ptr; + + public override bool Equals(object obj) => obj is LogicalGpuHandle other && this.Equals(other); + public bool Equals(LogicalGpuHandle other) => Ptr == other.Ptr; @@ -678,6 +699,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Ptr).GetHashCode(); } + public static bool operator ==(LogicalGpuHandle lhs, LogicalGpuHandle rhs) => lhs.Equals(rhs); + + public static bool operator !=(LogicalGpuHandle lhs, LogicalGpuHandle rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -687,6 +711,8 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] BoardNum; //!< Board Serial Number [16] + public override bool Equals(object obj) => obj is NV_BOARD_INFO_V1 other && this.Equals(other); + public bool Equals(NV_BOARD_INFO_V1 other) => Version == other.Version && BoardNum.SequenceEqual(other.BoardNum); @@ -695,7 +721,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, BoardNum).GetHashCode(); } + public static bool operator ==(NV_BOARD_INFO_V1 lhs, NV_BOARD_INFO_V1 rhs) => lhs.Equals(rhs); + public static bool operator !=(NV_BOARD_INFO_V1 lhs, NV_BOARD_INFO_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -712,6 +740,8 @@ namespace DisplayMagicianShared.NVIDIA //!< If the read succeeds with edidSize > NV_EDID_DATA_SIZE, //!< call back again with offset+256 until we have read the entire buffer + public override bool Equals(object obj) => obj is NV_EDID_V3 other && this.Equals(other); + public bool Equals(NV_EDID_V3 other) => Version == other.Version && EDID_Data.SequenceEqual(other.EDID_Data) && @@ -723,11 +753,14 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, EDID_Data, SizeofEDID, EdidId, Offset).GetHashCode(); } + public static bool operator ==(NV_EDID_V3 lhs, NV_EDID_V3 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_EDID_V3 lhs, NV_EDID_V3 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] - public struct NV_TIMINGEXT : IEquatable + public struct NV_TIMINGEXT : IEquatable { public UInt32 Flag; //!< Reserved for NVIDIA hardware-based enhancement, such as double-scan. public ushort Rr; //!< Logical refresh rate to present @@ -738,6 +771,8 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (Int32)NVImport.NVAPI_UNICODE_STRING_MAX)] public string Name; //!< Timing name + public override bool Equals(object obj) => obj is NV_TIMINGEXT other && this.Equals(other); + public bool Equals(NV_TIMINGEXT other) => Flag == other.Flag && Rr == other.Rr && @@ -751,10 +786,13 @@ namespace DisplayMagicianShared.NVIDIA { return (Flag, Rr, Rrx1k, Aspect, Rep, Status, Name).GetHashCode(); } + public static bool operator ==(NV_TIMINGEXT lhs, NV_TIMINGEXT rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_TIMINGEXT lhs, NV_TIMINGEXT rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NV_TIMING : IEquatable + public struct NV_TIMING : IEquatable { // VESA scan out timing parameters: public ushort HVisible; //!< horizontal visible @@ -777,6 +815,8 @@ namespace DisplayMagicianShared.NVIDIA //other timing related extras NV_TIMINGEXT Etc; + public override bool Equals(object obj) => obj is NV_TIMING other && this.Equals(other); + public bool Equals(NV_TIMING other) => HVisible == other.HVisible && HBorder == other.HBorder && @@ -798,6 +838,9 @@ namespace DisplayMagicianShared.NVIDIA { return (HVisible, HBorder, HFrontPorch, HSyncWidth, HTotal, HSyncPol, VVisible, VBorder, VFrontPorch, VSyncWidth, VTotal, VSyncPol, Interlaced, Pclk, Etc).GetHashCode(); } + public static bool operator ==(NV_TIMING lhs, NV_TIMING rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_TIMING lhs, NV_TIMING rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -808,6 +851,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 Right; public UInt32 Bottom; + public override bool Equals(object obj) => obj is NV_RECT other && this.Equals(other); + public bool Equals(NV_RECT other) => Left == other.Left && Top == other.Top && @@ -818,6 +863,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Left, Top, Right, Bottom).GetHashCode(); } + public static bool operator ==(NV_RECT lhs, NV_RECT rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_RECT lhs, NV_RECT rhs) => !(lhs == rhs); } @@ -827,6 +875,8 @@ namespace DisplayMagicianShared.NVIDIA public Int32 X; public Int32 Y; + public override bool Equals(object obj) => obj is NV_POSITION other && this.Equals(other); + public bool Equals(NV_POSITION other) => X == other.X && Y == other.Y; @@ -835,6 +885,9 @@ namespace DisplayMagicianShared.NVIDIA { return (X, Y).GetHashCode(); } + public static bool operator ==(NV_POSITION lhs, NV_POSITION rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_POSITION lhs, NV_POSITION rhs) => !(lhs == rhs); } @@ -845,6 +898,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 Height; public UInt32 ColorDepth; + public override bool Equals(object obj) => obj is NV_RESOLUTION other && this.Equals(other); + public bool Equals(NV_RESOLUTION other) => Width == other.Width && Height == other.Height && @@ -854,16 +909,27 @@ namespace DisplayMagicianShared.NVIDIA { return (Width, Height, ColorDepth).GetHashCode(); } + public static bool operator ==(NV_RESOLUTION lhs, NV_RESOLUTION rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_RESOLUTION lhs, NV_RESOLUTION rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct NV_VIEWPORTF : IEquatable { - public float X; //!< x-coordinate of the viewport top-left poInt32 - public float Y; //!< y-coordinate of the viewport top-left poInt32 + public float X; //!< x-coordinate of the viewport top-left point + public float Y; //!< y-coordinate of the viewport top-left point public float W; //!< Width of the viewport public float H; //!< Height of the viewport + public override bool Equals(object obj) => obj is NV_VIEWPORTF other && this.Equals(other); + + // NOTE: Using Math.Round for equality testing between floats. + /*public bool Equals(NV_VIEWPORTF other) + => Math.Round(X, 5) == Math.Round(other.X, 5) && + Math.Round(Y, 5) == Math.Round(other.Y, 5) && + Math.Round(W, 5) == Math.Round(other.W, 5) && + Math.Round(H, 5) == Math.Round(other.H, 5);*/ public bool Equals(NV_VIEWPORTF other) => X == other.X && Y == other.Y && @@ -874,6 +940,9 @@ namespace DisplayMagicianShared.NVIDIA { return (X, Y, W, H).GetHashCode(); } + public static bool operator ==(NV_VIEWPORTF lhs, NV_VIEWPORTF rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_VIEWPORTF lhs, NV_VIEWPORTF rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -912,6 +981,8 @@ namespace DisplayMagicianShared.NVIDIA //!< The value NV_TIMING::NV_TIMINGEXT::rrx1k is obtained from the EDID. The driver may //!< tweak this value for HDTV, stereo, etc., before reporting it to the OS. + public override bool Equals(object obj) => obj is NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO other && this.Equals(other); + public bool Equals(NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO other) => Version == other.Version && Rotation == other.Rotation && @@ -926,24 +997,32 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Rotation, Scaling, RefreshRate1K, Connector, TvFormat, TimingOverride, Timing).GetHashCode(); } + public static bool operator ==(NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO lhs, NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO lhs, NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 : IEquatable { public UInt32 DisplayId; //!< Display ID - NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO[] Details; //!< May be NULL if no advanced settings are required + NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO Details; //!< May be NULL if no advanced settings are required public UInt32 TargetId; //!< Windows CCD target ID. Must be present only for non-NVIDIA adapter, for NVIDIA adapter this parameter is ignored. + public override bool Equals(object obj) => obj is NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 other && this.Equals(other); + public bool Equals(NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 other) => DisplayId == other.DisplayId && - Details.SequenceEqual(other.Details) && + Details.Equals(other.Details) && TargetId == other.TargetId; public override Int32 GetHashCode() { return (DisplayId, Details, TargetId).GetHashCode(); } + public static bool operator ==(NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 lhs, NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 lhs, NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -953,12 +1032,14 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 SourceId; //!< Identifies sourceId used by Windows CCD. This can be optionally set. public UInt32 TargetInfoCount; //!< Number of elements in targetInfo array - public NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2[] TargetInfo; - public NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1[] sourceModeInfo; //!< May be NULL if mode info is not important - //public UInt32 IsNonNVIDIAAdapter : 1; //!< True for non-NVIDIA adapter. - //public UInt32 reserved : 31; //!< Must be 0 - //public LUID pOSAdapterID; //!< Used by Non-NVIDIA adapter for poInt32er to OS Adapter of LUID - //!< type, type casted to void *. + public NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2 TargetInfo; + public NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 sourceModeInfo; //!< May be NULL if mode info is not important + //public UInt32 IsNonNVIDIAAdapter : 1; //!< True for non-NVIDIA adapter. + //public UInt32 reserved : 31; //!< Must be 0 + //public LUID pOSAdapterID; //!< Used by Non-NVIDIA adapter for poInt32er to OS Adapter of LUID + //!< type, type casted to void *. + + public override bool Equals(object obj) => obj is NV_DISPLAYCONFIG_PATH_INFO_V2 other && this.Equals(other); public bool Equals(NV_DISPLAYCONFIG_PATH_INFO_V2 other) => Version == other.Version && @@ -971,6 +1052,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, SourceId, TargetInfoCount, TargetInfo, sourceModeInfo).GetHashCode(); } + public static bool operator ==(NV_DISPLAYCONFIG_PATH_INFO_V2 lhs, NV_DISPLAYCONFIG_PATH_INFO_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_DISPLAYCONFIG_PATH_INFO_V2 lhs, NV_DISPLAYCONFIG_PATH_INFO_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -986,6 +1070,8 @@ namespace DisplayMagicianShared.NVIDIA //public UInt32 bSLIFocus : 1; //public UInt32 reserved : 30; //!< Must be 0 + public override bool Equals(object obj) => obj is NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 other && this.Equals(other); + public bool Equals(NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 other) => Resolution.Equals(other.Resolution) && ColorFormat == other.ColorFormat && @@ -995,6 +1081,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Resolution, ColorFormat, Position).GetHashCode(); } + public static bool operator ==(NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 lhs, NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 lhs, NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1 rhs) => !(lhs == rhs); } @@ -1002,18 +1091,23 @@ namespace DisplayMagicianShared.NVIDIA public struct NV_DISPLAYCONFIG_PATH_TARGET_INFO : IEquatable { public UInt32 DisplayId; //!< Display ID - public NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO[] Details; //!< May be NULL if no advanced settings are required + public NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO Details; //!< May be NULL if no advanced settings are required public UInt32 TargetId; //!< Windows CCD target ID. Must be present only for non-NVIDIA adapter, for NVIDIA adapter this parameter is ignored. + public override bool Equals(object obj) => obj is NV_DISPLAYCONFIG_PATH_TARGET_INFO other && this.Equals(other); + public bool Equals(NV_DISPLAYCONFIG_PATH_TARGET_INFO other) => DisplayId == other.DisplayId && - Details.SequenceEqual(other.Details) && + Details.Equals(other.Details) && TargetId == other.TargetId; public override Int32 GetHashCode() { return (DisplayId, Details, TargetId).GetHashCode(); } + public static bool operator ==(NV_DISPLAYCONFIG_PATH_TARGET_INFO lhs, NV_DISPLAYCONFIG_PATH_TARGET_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_DISPLAYCONFIG_PATH_TARGET_INFO lhs, NV_DISPLAYCONFIG_PATH_TARGET_INFO rhs) => !(lhs == rhs); } @@ -1025,6 +1119,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 Enabled; //!< 1 if topo is enabled, else 0 public UInt32 IsPossible; //!< 1 if topo *can* be enabled, else 0 + public override bool Equals(object obj) => obj is NV_MOSAIC_TOPO_BRIEF other && this.Equals(other); + public bool Equals(NV_MOSAIC_TOPO_BRIEF other) => Version == other.Version && Topo.Equals(other.Topo); @@ -1036,7 +1132,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Topo, Enabled, IsPossible).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_TOPO_BRIEF lhs, NV_MOSAIC_TOPO_BRIEF rhs) => lhs.Equals(rhs); + public static bool operator !=(NV_MOSAIC_TOPO_BRIEF lhs, NV_MOSAIC_TOPO_BRIEF rhs) => !(lhs == rhs); } // @@ -1065,6 +1163,8 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public NV_MOSAIC_TOPO_DETAILS[] Topos; //!< Topo Array with 1 or 2 entries in it + public override bool Equals(object obj) => obj is NV_MOSAIC_TOPO_GROUP other && this.Equals(other); + public bool Equals(NV_MOSAIC_TOPO_GROUP other) => Version == other.Version && Brief.Equals(other.Brief) && @@ -1075,7 +1175,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Brief, Count, Topos).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_TOPO_GROUP lhs, NV_MOSAIC_TOPO_GROUP rhs) => lhs.Equals(rhs); + public static bool operator !=(NV_MOSAIC_TOPO_GROUP lhs, NV_MOSAIC_TOPO_GROUP rhs) => !(lhs == rhs); } @@ -1121,7 +1223,7 @@ namespace DisplayMagicianShared.NVIDIA } } - + public override bool Equals(object obj) => obj is NV_MOSAIC_TOPO_DETAILS other && this.Equals(other); public bool Equals(NV_MOSAIC_TOPO_DETAILS other) => Version == other.Version && LogicalGPUHandle.Equals(other.LogicalGPUHandle) && @@ -1144,7 +1246,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, LogicalGPUHandle, ValidityMask, RowCount, ColCount, ValidityMask).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_TOPO_DETAILS lhs, NV_MOSAIC_TOPO_DETAILS rhs) => lhs.Equals(rhs); + public static bool operator !=(NV_MOSAIC_TOPO_DETAILS lhs, NV_MOSAIC_TOPO_DETAILS rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1155,6 +1259,8 @@ namespace DisplayMagicianShared.NVIDIA public Int32 OverlapX; //!< Pixels of overlap on left of target: (+overlap, -gap) size is 8 public Int32 OverlapY; //!< Pixels of overlap on top of target: (+overlap, -gap) size is 8 + public override bool Equals(object obj) => obj is NV_MOSAIC_TOPO_GPU_LAYOUT_CELL other && this.Equals(other); + public bool Equals(NV_MOSAIC_TOPO_GPU_LAYOUT_CELL other) => PhysicalGPUHandle.Equals(other.PhysicalGPUHandle) && DisplayOutputId == other.DisplayOutputId && @@ -1165,7 +1271,9 @@ namespace DisplayMagicianShared.NVIDIA { return (PhysicalGPUHandle, DisplayOutputId, OverlapX, OverlapY).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_TOPO_GPU_LAYOUT_CELL lhs, NV_MOSAIC_TOPO_GPU_LAYOUT_CELL rhs) => lhs.Equals(rhs); + public static bool operator !=(NV_MOSAIC_TOPO_GPU_LAYOUT_CELL lhs, NV_MOSAIC_TOPO_GPU_LAYOUT_CELL rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1177,6 +1285,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 Bpp; //!< Bits per pixel public UInt32 Freq; //!< Display frequency + public override bool Equals(object obj) => obj is NV_MOSAIC_DISPLAY_SETTING_V1 other && this.Equals(other); + public bool Equals(NV_MOSAIC_DISPLAY_SETTING_V1 other) => Version == other.Version && Width == other.Width && @@ -1188,6 +1298,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Width, Height, Bpp, Freq).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_DISPLAY_SETTING_V1 lhs, NV_MOSAIC_DISPLAY_SETTING_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_DISPLAY_SETTING_V1 lhs, NV_MOSAIC_DISPLAY_SETTING_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1200,6 +1313,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 Freq; //!< Display frequency public UInt32 Rrx1k; //!< Display frequency in x1k + public override bool Equals(object obj) => obj is NV_MOSAIC_DISPLAY_SETTING_V2 other && this.Equals(other); + public bool Equals(NV_MOSAIC_DISPLAY_SETTING_V2 other) => Version == other.Version && Width == other.Width && @@ -1212,6 +1327,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Width, Height, Bpp, Freq, Rrx1k).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_DISPLAY_SETTING_V2 lhs, NV_MOSAIC_DISPLAY_SETTING_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_DISPLAY_SETTING_V2 lhs, NV_MOSAIC_DISPLAY_SETTING_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1226,13 +1344,14 @@ namespace DisplayMagicianShared.NVIDIA public NV_MOSAIC_GRID_TOPO_DISPLAY_V1[] Displays; public NV_MOSAIC_DISPLAY_SETTING_V1 DisplaySettings; - public bool ApplyWithBezelCorrect => (Flags & 0x1) == 0x1; public bool ImmersiveGaming => (Flags & 0x2) == 0x2; public bool BaseMosaic => (Flags & 0x4) == 0x4; public bool DriverReloadAllowed => (Flags & 0x8) == 0x8; public bool AcceleratePrimaryDisplay => (Flags & 0x10) == 0x10; + public override bool Equals(object obj) => obj is NV_MOSAIC_GRID_TOPO_DISPLAY_V1 other && this.Equals(other); + public bool Equals(NV_MOSAIC_GRID_TOPO_V1 other) => Version == other.Version && Rows == other.Rows && @@ -1246,6 +1365,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Rows, Columns, DisplayCount, Flags, Displays, DisplaySettings).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_GRID_TOPO_V1 lhs, NV_MOSAIC_GRID_TOPO_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_GRID_TOPO_V1 lhs, NV_MOSAIC_GRID_TOPO_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1260,7 +1382,6 @@ namespace DisplayMagicianShared.NVIDIA public NV_MOSAIC_GRID_TOPO_DISPLAY_V2[] Displays; public NV_MOSAIC_DISPLAY_SETTING_V1 DisplaySettings; - public bool ApplyWithBezelCorrect => (Flags & 0x1) == 0x1; public bool ImmersiveGaming => (Flags & 0x2) == 0x2; public bool BaseMosaic => (Flags & 0x4) == 0x4; @@ -1268,6 +1389,8 @@ namespace DisplayMagicianShared.NVIDIA public bool AcceleratePrimaryDisplay => (Flags & 0x10) == 0x10; public bool PixelShift => (Flags & 0x20) == 0x20; + public override bool Equals(object obj) => obj is NV_MOSAIC_GRID_TOPO_V2 other && this.Equals(other); + public bool Equals(NV_MOSAIC_GRID_TOPO_V2 other) => Version == other.Version && Rows == other.Rows && @@ -1281,6 +1404,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Rows, Columns, DisplayCount, Flags, Displays, DisplaySettings).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_GRID_TOPO_V2 lhs, NV_MOSAIC_GRID_TOPO_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_GRID_TOPO_V2 lhs, NV_MOSAIC_GRID_TOPO_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1292,6 +1418,7 @@ namespace DisplayMagicianShared.NVIDIA public NV_ROTATE Rotation; //!< Rotation of display public UInt32 CloneGroup; //!< Reserved, must be 0 + public override bool Equals(object obj) => obj is NV_MOSAIC_GRID_TOPO_DISPLAY_V1 other && this.Equals(other); public bool Equals(NV_MOSAIC_GRID_TOPO_DISPLAY_V1 other) => DisplayId == other.DisplayId && OverlapX == other.OverlapX && @@ -1303,6 +1430,9 @@ namespace DisplayMagicianShared.NVIDIA { return (DisplayId, OverlapX, OverlapY, Rotation, CloneGroup).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_GRID_TOPO_DISPLAY_V1 lhs, NV_MOSAIC_GRID_TOPO_DISPLAY_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_GRID_TOPO_DISPLAY_V1 lhs, NV_MOSAIC_GRID_TOPO_DISPLAY_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1316,6 +1446,7 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 CloneGroup; //!< Reserved, must be 0 public NV_PIXEL_SHIFT_TYPE PixelShiftType; //!< Type of the pixel shift enabled display + public override bool Equals(object obj) => obj is NV_MOSAIC_GRID_TOPO_DISPLAY_V2 other && this.Equals(other); public bool Equals(NV_MOSAIC_GRID_TOPO_DISPLAY_V2 other) => Version == other.Version && DisplayId == other.DisplayId && @@ -1329,6 +1460,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, DisplayId, OverlapX, OverlapY, Rotation, CloneGroup, PixelShiftType).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_GRID_TOPO_DISPLAY_V2 lhs, NV_MOSAIC_GRID_TOPO_DISPLAY_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_GRID_TOPO_DISPLAY_V2 lhs, NV_MOSAIC_GRID_TOPO_DISPLAY_V2 rhs) => !(lhs == rhs); } @@ -1343,6 +1477,8 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValArray, SizeConst = (Int32)NVImport.NV_MOSAIC_DISPLAY_SETTINGS_MAX)] public NV_MOSAIC_DISPLAY_SETTING_V1[] DisplaySettings; //!< List of per display settings possible + public override bool Equals(object obj) => obj is NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 other && this.Equals(other); + public bool Equals(NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 other) => Version == other.Version && TopoBriefsCount == other.TopoBriefsCount && @@ -1354,6 +1490,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, TopoBriefsCount, TopoBriefs, DisplaySettingsCount, DisplaySettings).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 lhs, NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 lhs, NV_MOSAIC_SUPPORTED_TOPO_INFO_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1367,6 +1506,7 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValArray, SizeConst = (Int32)NVImport.NV_MOSAIC_DISPLAY_SETTINGS_MAX)] public NV_MOSAIC_DISPLAY_SETTING_V2[] DisplaySettings; //!< List of per display settings possible + public override bool Equals(object obj) => obj is NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 other && this.Equals(other); public bool Equals(NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 other) => Version == other.Version && TopoBriefsCount == other.TopoBriefsCount && @@ -1378,6 +1518,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, TopoBriefsCount, TopoBriefs, DisplaySettingsCount, DisplaySettings).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 lhs, NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 lhs, NV_MOSAIC_SUPPORTED_TOPO_INFO_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1389,6 +1532,8 @@ namespace DisplayMagicianShared.NVIDIA public UInt32 DisplayId; //!< this is a unique identifier for each device public UInt32 Flags; + public override bool Equals(object obj) => obj is NV_GPU_DISPLAYIDS_V2 other && this.Equals(other); + public bool Equals(NV_GPU_DISPLAYIDS_V2 other) => Version == other.Version && ConnectorType == other.ConnectorType && @@ -1410,6 +1555,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, ConnectorType, DisplayId, Flags).GetHashCode(); } + public static bool operator ==(NV_GPU_DISPLAYIDS_V2 lhs, NV_GPU_DISPLAYIDS_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_GPU_DISPLAYIDS_V2 lhs, NV_GPU_DISPLAYIDS_V2 rhs) => !(lhs == rhs); } @@ -1423,6 +1571,8 @@ namespace DisplayMagicianShared.NVIDIA [MarshalAs(UnmanagedType.ByValArray, SizeConst = (Int32)NVImport.NV_MAX_DISPLAYS)] public NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY[] Displays; // displays[NV_MAX_DISPLAYS] array + public override bool Equals(object obj) => obj is NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 other && this.Equals(other); + public bool Equals(NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 other) => Version == other.Version && ErrorFlags == other.ErrorFlags && @@ -1434,6 +1584,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, ErrorFlags, WarningFlags, DisplayCount, Displays).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 lhs, NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 lhs, NV_MOSAIC_DISPLAY_TOPO_STATUS_V1 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1443,9 +1596,10 @@ namespace DisplayMagicianShared.NVIDIA public NV_MOSAIC_DISPLAYCAPS_PROBLEM_FLAGS ErrorFlags; //!< (OUT) Any of the NV_MOSAIC_DISPLAYCAPS_PROBLEM_* flags. public NV_MOSAIC_DISPLAYTOPO_WARNING_FLAGS WarningFlags; //!< (OUT) Any of the NV_MOSAIC_DISPLAYTOPO_WARNING_* flags. public UInt32 GeneralFlags; - public bool SupportsRotation => (GeneralFlags & 0x1) == 0x1; //!< (OUT) This display can be rotated + public override bool Equals(object obj) => obj is NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY other && this.Equals(other); + public bool Equals(NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY other) => DisplayId == other.DisplayId && ErrorFlags == other.ErrorFlags && @@ -1456,6 +1610,9 @@ namespace DisplayMagicianShared.NVIDIA { return (DisplayId, ErrorFlags, WarningFlags, GeneralFlags).GetHashCode(); } + public static bool operator ==(NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY lhs, NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY lhs, NV_MOSAIC_DISPLAY_TOPO_STATUS_DISPLAY rhs) => !(lhs == rhs); } @@ -1475,6 +1632,7 @@ namespace DisplayMagicianShared.NVIDIA public bool IsTraditionalHdrGammaSupported => SupportFlags.HasFlag(NV_HDR_CAPABILITIES_V2_FLAGS.IsTraditionalHdrGammaSupported); public bool IsTraditionalSdrGammaSupported => SupportFlags.HasFlag(NV_HDR_CAPABILITIES_V2_FLAGS.IsTraditionalSdrGammaSupported); + public override bool Equals(object obj) => obj is NV_HDR_CAPABILITIES_V2 other && this.Equals(other); public bool Equals(NV_HDR_CAPABILITIES_V2 other) => Version == other.Version && @@ -1487,6 +1645,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, SupportFlags, StaticMetadataDescriptorId, DisplayData, DvStaticMetadata).GetHashCode(); } + public static bool operator ==(NV_HDR_CAPABILITIES_V2 lhs, NV_HDR_CAPABILITIES_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_HDR_CAPABILITIES_V2 lhs, NV_HDR_CAPABILITIES_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1504,6 +1665,7 @@ namespace DisplayMagicianShared.NVIDIA public UInt16 CCWhiteX; public UInt16 CCWhiteY; + public override bool Equals(object obj) => obj is NV_HDR_DV_STATIC_METADATA other && this.Equals(other); public bool Equals(NV_HDR_DV_STATIC_METADATA other) => Flags == other.Flags && TargetMinLuminance == other.TargetMinLuminance && @@ -1522,6 +1684,9 @@ namespace DisplayMagicianShared.NVIDIA return (Flags, TargetMinLuminance, TargetMaxLuminance, CCRedX, CCRedY, CCGreenX, CCGreenY, CCBlueX, CCBlueY, CCWhiteX, CCWhiteY).GetHashCode(); } + public static bool operator ==(NV_HDR_DV_STATIC_METADATA lhs, NV_HDR_DV_STATIC_METADATA rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_HDR_DV_STATIC_METADATA lhs, NV_HDR_DV_STATIC_METADATA rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1539,6 +1704,7 @@ namespace DisplayMagicianShared.NVIDIA public UInt16 DesiredContentMinLuminance; public UInt16 DesiredContentMaxFrameAverageLuminance; + public override bool Equals(object obj) => obj is NV_HDR_CAPABILITIES_DISPLAY_DATA other && this.Equals(other); public bool Equals(NV_HDR_CAPABILITIES_DISPLAY_DATA other) => DisplayPrimaryX0 == other.DisplayPrimaryX0 && DisplayPrimaryY0 == other.DisplayPrimaryY0 && @@ -1557,6 +1723,9 @@ namespace DisplayMagicianShared.NVIDIA return (DisplayPrimaryX0, DisplayPrimaryY0, DisplayPrimaryX1, DisplayPrimaryY1, DisplayPrimaryX2, DisplayPrimaryY2, DisplayWhitePointX, DisplayWhitePointY, DisplayWhitePointX, DisplayWhitePointY, DesiredContentMaxLuminance, DesiredContentMinLuminance, DesiredContentMaxFrameAverageLuminance).GetHashCode(); } + public static bool operator ==(NV_HDR_CAPABILITIES_DISPLAY_DATA lhs, NV_HDR_CAPABILITIES_DISPLAY_DATA rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_HDR_CAPABILITIES_DISPLAY_DATA lhs, NV_HDR_CAPABILITIES_DISPLAY_DATA rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1574,6 +1743,7 @@ namespace DisplayMagicianShared.NVIDIA //!< If invalid or no combination is passed driver will force default combination of RGB format + full range + 8bpc. //!< HDR mode: These fields are ignored in hdr mode + public override bool Equals(object obj) => obj is NV_HDR_COLOR_DATA_V2 other && this.Equals(other); public bool Equals(NV_HDR_COLOR_DATA_V2 other) => Version == other.Version && Cmd == other.Cmd && @@ -1588,6 +1758,9 @@ namespace DisplayMagicianShared.NVIDIA { return (Version, Cmd, HdrMode, StaticMetadataDescriptorId, MasteringDisplayData, HdrColorFormat, HdrDynamicRange, HdrBpc).GetHashCode(); } + public static bool operator ==(NV_HDR_COLOR_DATA_V2 lhs, NV_HDR_COLOR_DATA_V2 rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_HDR_COLOR_DATA_V2 lhs, NV_HDR_COLOR_DATA_V2 rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, Pack = 8)] @@ -1606,6 +1779,7 @@ namespace DisplayMagicianShared.NVIDIA public UInt16 MaxContentLightLevel; public UInt16 MaxFrameAverageLightLevel; + public override bool Equals(object obj) => obj is NV_HDR_COLOR_DISPLAY_DATA other && this.Equals(other); public bool Equals(NV_HDR_COLOR_DISPLAY_DATA other) => DisplayPrimaryX0 == other.DisplayPrimaryX0 && DisplayPrimaryY0 == other.DisplayPrimaryY0 && @@ -1625,6 +1799,9 @@ namespace DisplayMagicianShared.NVIDIA return (DisplayPrimaryX0, DisplayPrimaryY0, DisplayPrimaryX1, DisplayPrimaryY1, DisplayPrimaryX2, DisplayPrimaryY2, DisplayWhitePointX, DisplayWhitePointY, DisplayWhitePointX, DisplayWhitePointY, MaxDisplayMasteringLuminance, MinDisplayMasteringLuminance, MaxContentLightLevel, MaxFrameAverageLightLevel).GetHashCode(); } + public static bool operator ==(NV_HDR_COLOR_DISPLAY_DATA lhs, NV_HDR_COLOR_DISPLAY_DATA rhs) => lhs.Equals(rhs); + + public static bool operator !=(NV_HDR_COLOR_DISPLAY_DATA lhs, NV_HDR_COLOR_DISPLAY_DATA rhs) => !(lhs == rhs); } // ================================== diff --git a/DisplayMagicianShared/NVIDIA/NVIDIALibrary.cs b/DisplayMagicianShared/NVIDIA/NVIDIALibrary.cs index 92863c4..4e45082 100644 --- a/DisplayMagicianShared/NVIDIA/NVIDIALibrary.cs +++ b/DisplayMagicianShared/NVIDIA/NVIDIALibrary.cs @@ -22,9 +22,12 @@ namespace DisplayMagicianShared.NVIDIA public Int32 OverlapY; public NV_MOSAIC_GRID_TOPO_V2[] MosaicGridTopos; public UInt32 MosaicGridCount; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = (Int32)NVImport.NV_MOSAIC_MAX_DISPLAYS)] public List MosaicViewports; public UInt32 PrimaryDisplayId; + public override bool Equals(object obj) => obj is NVIDIA_MOSAIC_CONFIG other && this.Equals(other); + public bool Equals(NVIDIA_MOSAIC_CONFIG other) => IsMosaicEnabled == other.IsMosaicEnabled && MosaicTopologyBrief.Equals(other.MosaicTopologyBrief) && @@ -33,13 +36,16 @@ namespace DisplayMagicianShared.NVIDIA OverlapY == other.OverlapY && MosaicGridTopos.SequenceEqual(other.MosaicGridTopos) && MosaicGridCount == other.MosaicGridCount && - MosaicViewports.SequenceEqual(other.MosaicViewports) && + NVIDIALibrary.ListOfArraysEqual(MosaicViewports, other.MosaicViewports) && PrimaryDisplayId == other.PrimaryDisplayId; public override int GetHashCode() { return (IsMosaicEnabled, MosaicTopologyBrief, MosaicDisplaySettings, OverlapX, OverlapY, MosaicGridTopos, MosaicGridCount, MosaicViewports, PrimaryDisplayId).GetHashCode(); } + public static bool operator ==(NVIDIA_MOSAIC_CONFIG lhs, NVIDIA_MOSAIC_CONFIG rhs) => lhs.Equals(rhs); + + public static bool operator !=(NVIDIA_MOSAIC_CONFIG lhs, NVIDIA_MOSAIC_CONFIG rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -49,6 +55,7 @@ namespace DisplayMagicianShared.NVIDIA public Dictionary HdrColorData; public bool IsNvHdrEnabled; + public override bool Equals(object obj) => obj is NVIDIA_HDR_CONFIG other && this.Equals(other); public bool Equals(NVIDIA_HDR_CONFIG other) => HdrCapabilities.SequenceEqual(other.HdrCapabilities) && HdrColorData.SequenceEqual(other.HdrColorData) && @@ -58,6 +65,9 @@ namespace DisplayMagicianShared.NVIDIA { return (HdrCapabilities, HdrColorData, IsNvHdrEnabled).GetHashCode(); } + public static bool operator ==(NVIDIA_HDR_CONFIG lhs, NVIDIA_HDR_CONFIG rhs) => lhs.Equals(rhs); + + public static bool operator !=(NVIDIA_HDR_CONFIG lhs, NVIDIA_HDR_CONFIG rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -67,6 +77,7 @@ namespace DisplayMagicianShared.NVIDIA public NVIDIA_HDR_CONFIG HdrConfig; public List DisplayIdentifiers; + public override bool Equals(object obj) => obj is NVIDIA_DISPLAY_CONFIG other && this.Equals(other); public bool Equals(NVIDIA_DISPLAY_CONFIG other) => MosaicConfig.Equals(other.MosaicConfig) && HdrConfig.Equals(other.HdrConfig) && @@ -76,6 +87,9 @@ namespace DisplayMagicianShared.NVIDIA { return (MosaicConfig, HdrConfig, DisplayIdentifiers).GetHashCode(); } + public static bool operator ==(NVIDIA_DISPLAY_CONFIG lhs, NVIDIA_DISPLAY_CONFIG rhs) => lhs.Equals(rhs); + + public static bool operator !=(NVIDIA_DISPLAY_CONFIG lhs, NVIDIA_DISPLAY_CONFIG rhs) => !(lhs == rhs); } public class NVIDIALibrary : IDisposable @@ -428,7 +442,7 @@ namespace DisplayMagicianShared.NVIDIA myDisplayConfig.MosaicConfig.MosaicGridTopos = mosaicGridTopos; myDisplayConfig.MosaicConfig.MosaicGridCount = mosaicGridCount; - List allViewports = new List { }; + List allViewports = new List(); foreach (NV_MOSAIC_GRID_TOPO_V2 gridTopo in mosaicGridTopos) { // Get Current Mosaic Grid settings using the Grid topologies numbers we got before @@ -1382,6 +1396,47 @@ namespace DisplayMagicianShared.NVIDIA } + public bool IsEquivalentConfig(NVIDIA_DISPLAY_CONFIG displayConfig, NVIDIA_DISPLAY_CONFIG otherDisplayConfig) + { + // We want to check if the NVIDIA configurations are the equiavalent of each other + // IMPORTANT: This function differs from Equals in that Equivalent allows some fields to differ in order to still match. + // The goal is to identify when two display configurations would be the same if they were applied. + + SharedLogger.logger.Trace($"NVIDIALibrary/IsEquivalentConfig: Testing whether the NVIDIA display configuration is equivalent to another"); + if (_initialised) + { + NVAPI_STATUS NVStatus = NVAPI_STATUS.NVAPI_ERROR; + + // Check that displayConfig DisplayIdentifiers match + if (!displayConfig.DisplayIdentifiers.All(value => otherDisplayConfig.DisplayIdentifiers.Contains(value))) + { + SharedLogger.logger.Trace($"NVIDIALibrary/IsEquivalentConfig: Uh oh! The NVIDIA display identifiers don't match so NVIDIA Config is not equivalent to the other one."); + return false; + } + + // Check that displayConfig Mosaic Configs match + if (!displayConfig.MosaicConfig.Equals(otherDisplayConfig.MosaicConfig)) + { + SharedLogger.logger.Trace($"NVIDIALibrary/IsEquivalentConfig: Uh oh! The NVIDIA Mosaic Configs don't match so NVIDIA Config is not equivalent to the other one."); + return false; + } + + // Check that displayConfig Hdr Configs match + if (!displayConfig.HdrConfig.Equals(otherDisplayConfig.HdrConfig)) + { + SharedLogger.logger.Trace($"NVIDIALibrary/IsEquivalentConfig: Uh oh! The NVIDIA Hdr Configs don't match so NVIDIA Config is not equivalent to the other one."); + return false; + } + + SharedLogger.logger.Trace($"NVIDIALibrary/IsEquivalentConfig: Success! The NVIDIA display configuration is possible to be used now"); + return true; + } + else + { + return false; + } + } + public List GetCurrentDisplayIdentifiers() { SharedLogger.logger.Error($"NVIDIALibrary/GetCurrentDisplayIdentifiers: Getting the current display identifiers for the displays in use now"); @@ -1768,6 +1823,55 @@ namespace DisplayMagicianShared.NVIDIA return displayIdentifiers; } + public static bool ListOfArraysEqual(List a1, List a2) + { + if (a1.Count == a2.Count) + { + for (int i = 0; i < a1.Count; i++) + { + if (a1[i].Length == a2[i].Length) + { + for (int j = 0; j < a1[i].Length; j++) + { + if (a1[i][j] != a2[i][j]) + { + return false; + } + } + } + } + return true; + } + else + { + return false; + } + } + + public static bool Arrays2DEqual(int[][] a1, int[][] a2) + { + if (a1.Length == a2.Length) + { + for (int i = 0; i < a1.Length; i++) + { + if (a1[i].Length == a2[i].Length) + { + for (int j = 0; j < a1[i].Length; j++) + { + if (a1[i][j] != a2[i][j]) + { + return false; + } + } + } + } + return true; + } + else + { + return false; + } + } } diff --git a/DisplayMagicianShared/Windows/CCD.cs b/DisplayMagicianShared/Windows/CCD.cs index a3a7bed..4946671 100644 --- a/DisplayMagicianShared/Windows/CCD.cs +++ b/DisplayMagicianShared/Windows/CCD.cs @@ -262,6 +262,8 @@ namespace DisplayMagicianShared.Windows public LUID AdapterId; public uint Id; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_DEVICE_INFO_HEADER other && this.Equals(other); + public bool Equals(DISPLAYCONFIG_DEVICE_INFO_HEADER other) => Type == other.Type && Size == other.Size && @@ -273,7 +275,9 @@ namespace DisplayMagicianShared.Windows return (Type, Size, AdapterId, Id).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_DEVICE_INFO_HEADER lhs, DISPLAYCONFIG_DEVICE_INFO_HEADER rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_DEVICE_INFO_HEADER lhs, DISPLAYCONFIG_DEVICE_INFO_HEADER rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -291,6 +295,8 @@ namespace DisplayMagicianShared.Windows public bool WideColorEnforced => (Value & 0x4) == 0x4; public bool AdvancedColorForceDisabled => (Value & 0x8) == 0x8; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO other && this.Equals(other); + public bool Equals(DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO other) => Header.Equals(other.Header) && Value == other.Value && @@ -302,7 +308,9 @@ namespace DisplayMagicianShared.Windows return (Header, Value, ColorEncoding, BitsPerColorChannel).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO lhs, DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO lhs, DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -311,6 +319,7 @@ namespace DisplayMagicianShared.Windows public int X; public int Y; + public override bool Equals(object obj) => obj is POINTL other && this.Equals(other); public bool Equals(POINTL other) => X == other.X && Y == other.Y; @@ -320,7 +329,9 @@ namespace DisplayMagicianShared.Windows return (X, Y).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(POINTL lhs, POINTL rhs) => lhs.Equals(rhs); + + public static bool operator !=(POINTL lhs, POINTL rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -331,6 +342,7 @@ namespace DisplayMagicianShared.Windows public ulong Value => ((ulong)HighPart << 32) | LowPart; + public override bool Equals(object obj) => obj is LUID other && this.Equals(other); public bool Equals(LUID other) => LowPart == other.LowPart && HighPart == other.HighPart; @@ -340,6 +352,10 @@ namespace DisplayMagicianShared.Windows return (LowPart, HighPart).GetHashCode(); } + public static bool operator ==(LUID lhs, LUID rhs) => lhs.Equals(rhs); + + public static bool operator !=(LUID lhs, LUID rhs) => !(lhs == rhs); + public override string ToString() => Value.ToString(); } @@ -351,6 +367,7 @@ namespace DisplayMagicianShared.Windows public DISPLAYCONFIG_PIXELFORMAT PixelFormat; public POINTL Position; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SOURCE_MODE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SOURCE_MODE other) => Width == other.Width && Height == other.Height && @@ -361,6 +378,9 @@ namespace DisplayMagicianShared.Windows { return (Width, Height, PixelFormat, Position).GetHashCode(); } + public static bool operator ==(DISPLAYCONFIG_SOURCE_MODE lhs, DISPLAYCONFIG_SOURCE_MODE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SOURCE_MODE lhs, DISPLAYCONFIG_SOURCE_MODE rhs) => !(lhs == rhs); } @@ -370,6 +390,7 @@ namespace DisplayMagicianShared.Windows public uint Numerator; public uint Denominator; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_RATIONAL other && this.Equals(other); public bool Equals(DISPLAYCONFIG_RATIONAL other) => Numerator == other.Numerator && Denominator == other.Denominator; @@ -378,6 +399,9 @@ namespace DisplayMagicianShared.Windows { return (Numerator, Denominator).GetHashCode(); } + public static bool operator ==(DISPLAYCONFIG_RATIONAL lhs, DISPLAYCONFIG_RATIONAL rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_RATIONAL lhs, DISPLAYCONFIG_RATIONAL rhs) => !(lhs == rhs); public override string ToString() => Numerator + " / " + Denominator; } @@ -388,6 +412,7 @@ namespace DisplayMagicianShared.Windows public uint Cx; public uint Cy; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_2DREGION other && this.Equals(other); public bool Equals(DISPLAYCONFIG_2DREGION other) => Cx == other.Cx && Cy == other.Cy; @@ -397,7 +422,9 @@ namespace DisplayMagicianShared.Windows return (Cx, Cy).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_2DREGION lhs, DISPLAYCONFIG_2DREGION rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_2DREGION lhs, DISPLAYCONFIG_2DREGION rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -407,6 +434,7 @@ namespace DisplayMagicianShared.Windows public RECTL DesktopImageRegion; public RECTL DesktopImageClip; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_DESKTOP_IMAGE_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_DESKTOP_IMAGE_INFO other) => PathSourceSize.Equals(other.PathSourceSize) && DesktopImageRegion.Equals(other.DesktopImageRegion) && @@ -417,7 +445,9 @@ namespace DisplayMagicianShared.Windows return (PathSourceSize, DesktopImageRegion, DesktopImageClip).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_DESKTOP_IMAGE_INFO lhs, DISPLAYCONFIG_DESKTOP_IMAGE_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_DESKTOP_IMAGE_INFO lhs, DISPLAYCONFIG_DESKTOP_IMAGE_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -431,6 +461,7 @@ namespace DisplayMagicianShared.Windows public D3D_VIDEO_SIGNAL_STANDARD VideoStandard; public DISPLAYCONFIG_SCANLINE_ORDERING ScanLineOrdering; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_VIDEO_SIGNAL_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_VIDEO_SIGNAL_INFO other) => PixelRate == other.PixelRate && HSyncFreq.Equals(other.HSyncFreq) && @@ -445,7 +476,9 @@ namespace DisplayMagicianShared.Windows return (PixelRate, HSyncFreq, VSyncFreq, ActiveSize, TotalSize, VideoStandard, ScanLineOrdering).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_VIDEO_SIGNAL_INFO lhs, DISPLAYCONFIG_VIDEO_SIGNAL_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_VIDEO_SIGNAL_INFO lhs, DISPLAYCONFIG_VIDEO_SIGNAL_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -453,6 +486,7 @@ namespace DisplayMagicianShared.Windows { public DISPLAYCONFIG_VIDEO_SIGNAL_INFO TargetVideoSignalInfo; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_TARGET_MODE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_TARGET_MODE other) => TargetVideoSignalInfo.Equals(other.TargetVideoSignalInfo); @@ -461,7 +495,9 @@ namespace DisplayMagicianShared.Windows return (TargetVideoSignalInfo).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_TARGET_MODE lhs, DISPLAYCONFIG_TARGET_MODE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_TARGET_MODE lhs, DISPLAYCONFIG_TARGET_MODE rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Explicit)] @@ -480,6 +516,7 @@ namespace DisplayMagicianShared.Windows [FieldOffset(16)] public DISPLAYCONFIG_SOURCE_FLAGS StatusFlags; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_PATH_SOURCE_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_PATH_SOURCE_INFO other) => // AdapterId.Equals(other.AdapterId) && // Removed the AdapterId from the Equals, as it changes after a reboot. Id == other.Id && @@ -492,7 +529,9 @@ namespace DisplayMagicianShared.Windows return (ModeInfoIdx, Id, StatusFlags).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_PATH_SOURCE_INFO lhs, DISPLAYCONFIG_PATH_SOURCE_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_PATH_SOURCE_INFO lhs, DISPLAYCONFIG_PATH_SOURCE_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -523,6 +562,7 @@ namespace DisplayMagicianShared.Windows DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_PATH = 0x00000008, DISPLAYCONFIG_TARGET_FORCED_AVAILABILITY_SYSTEM = 0x00000010, DISPLAYCONFIG_TARGET_IS_HMD = 0x00000020,*/ + public override bool Equals(object obj) => obj is DISPLAYCONFIG_PATH_TARGET_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_PATH_TARGET_INFO other) => // AdapterId.Equals(other.AdapterId) && // Removed the AdapterId from the Equals, as it changes after reboot. @@ -541,7 +581,9 @@ namespace DisplayMagicianShared.Windows return (AdapterId, Id, ModeInfoIdx, OutputTechnology, Rotation, Scaling, RefreshRate, ScanLineOrdering, TargetAvailable, StatusFlags).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_PATH_TARGET_INFO lhs, DISPLAYCONFIG_PATH_TARGET_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_PATH_TARGET_INFO lhs, DISPLAYCONFIG_PATH_TARGET_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -551,6 +593,7 @@ namespace DisplayMagicianShared.Windows public DISPLAYCONFIG_PATH_TARGET_INFO TargetInfo; public uint Flags; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_PATH_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_PATH_INFO other) => SourceInfo.Equals(other.SourceInfo) && TargetInfo.Equals(other.TargetInfo) && @@ -561,7 +604,9 @@ namespace DisplayMagicianShared.Windows return (SourceInfo, TargetInfo, Flags).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_PATH_INFO lhs, DISPLAYCONFIG_PATH_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_PATH_INFO lhs, DISPLAYCONFIG_PATH_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Explicit)] @@ -586,6 +631,7 @@ namespace DisplayMagicianShared.Windows [FieldOffset(16)] public DISPLAYCONFIG_DESKTOP_IMAGE_INFO DesktopImageInfo; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_MODE_INFO other && this.Equals(other); public bool Equals(DISPLAYCONFIG_MODE_INFO other) { if (InfoType != other.InfoType) @@ -625,7 +671,9 @@ namespace DisplayMagicianShared.Windows return (InfoType, Id, TargetMode, SourceMode, DesktopImageInfo).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_MODE_INFO lhs, DISPLAYCONFIG_MODE_INFO rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_MODE_INFO lhs, DISPLAYCONFIG_MODE_INFO rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -635,6 +683,7 @@ namespace DisplayMagicianShared.Windows [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string ViewGdiDeviceName; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SOURCE_DEVICE_NAME other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SOURCE_DEVICE_NAME other) => Header.Equals(other.Header) && ViewGdiDeviceName == other.ViewGdiDeviceName; @@ -644,7 +693,9 @@ namespace DisplayMagicianShared.Windows return (Header, ViewGdiDeviceName).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_SOURCE_DEVICE_NAME lhs, DISPLAYCONFIG_SOURCE_DEVICE_NAME rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SOURCE_DEVICE_NAME lhs, DISPLAYCONFIG_SOURCE_DEVICE_NAME rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -652,6 +703,7 @@ namespace DisplayMagicianShared.Windows { public uint Value; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS other && this.Equals(other); public bool Equals(DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS other) => Value == other.Value; @@ -664,7 +716,9 @@ namespace DisplayMagicianShared.Windows return Value.GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS lhs, DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS lhs, DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -681,6 +735,7 @@ namespace DisplayMagicianShared.Windows [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string MonitorDevicePath; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_TARGET_DEVICE_NAME other && this.Equals(other); public bool Equals(DISPLAYCONFIG_TARGET_DEVICE_NAME other) => Header.Equals(other.Header) && Flags.Equals(other.Flags) && @@ -696,7 +751,9 @@ namespace DisplayMagicianShared.Windows return (Header, Flags, OutputTechnology, EdidManufactureId, EdidProductCodeId, ConnectorInstance, MonitorFriendlyDeviceName, MonitorDevicePath).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_TARGET_DEVICE_NAME lhs, DISPLAYCONFIG_TARGET_DEVICE_NAME rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_TARGET_DEVICE_NAME lhs, DISPLAYCONFIG_TARGET_DEVICE_NAME rhs) => !(lhs == rhs); } @@ -708,6 +765,7 @@ namespace DisplayMagicianShared.Windows public uint Height; public DISPLAYCONFIG_TARGET_MODE TargetMode; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_TARGET_PREFERRED_MODE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_TARGET_PREFERRED_MODE other) => Header.Equals(other.Header) && Width == other.Width && @@ -719,7 +777,9 @@ namespace DisplayMagicianShared.Windows return (Header, Width, Height, TargetMode).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_TARGET_PREFERRED_MODE lhs, DISPLAYCONFIG_TARGET_PREFERRED_MODE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_TARGET_PREFERRED_MODE lhs, DISPLAYCONFIG_TARGET_PREFERRED_MODE rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -729,6 +789,7 @@ namespace DisplayMagicianShared.Windows [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string AdapterDevicePath; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_ADAPTER_NAME other && this.Equals(other); public bool Equals(DISPLAYCONFIG_ADAPTER_NAME other) => Header.Equals(other.Header) && AdapterDevicePath == other.AdapterDevicePath; @@ -738,7 +799,9 @@ namespace DisplayMagicianShared.Windows return (Header, AdapterDevicePath).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_ADAPTER_NAME lhs, DISPLAYCONFIG_ADAPTER_NAME rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_ADAPTER_NAME lhs, DISPLAYCONFIG_ADAPTER_NAME rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -752,6 +815,7 @@ namespace DisplayMagicianShared.Windows get => (Value & 0x1) == 0x1; } + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION other) => Header.Equals(other.Header) && Value == other.Value; @@ -761,7 +825,9 @@ namespace DisplayMagicianShared.Windows return (Header, Value).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION lhs, DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION lhs, DISPLAYCONFIG_SUPPORT_VIRTUAL_RESOLUTION rhs) => !(lhs == rhs); } @@ -776,6 +842,7 @@ namespace DisplayMagicianShared.Windows get => (Value & 0x1) == 0x1; } + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SET_TARGET_PERSISTENCE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SET_TARGET_PERSISTENCE other) => Header.Equals(other.Header) && Value == other.Value; @@ -785,7 +852,9 @@ namespace DisplayMagicianShared.Windows return (Header, Value).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_SET_TARGET_PERSISTENCE lhs, DISPLAYCONFIG_SET_TARGET_PERSISTENCE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SET_TARGET_PERSISTENCE lhs, DISPLAYCONFIG_SET_TARGET_PERSISTENCE rhs) => !(lhs == rhs); } @@ -796,6 +865,7 @@ namespace DisplayMagicianShared.Windows //[MarshalAs(UnmanagedType.U4)] public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY BaseOutputTechnology; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_TARGET_BASE_TYPE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_TARGET_BASE_TYPE other) => Header.Equals(other.Header) && BaseOutputTechnology == other.BaseOutputTechnology; @@ -805,7 +875,9 @@ namespace DisplayMagicianShared.Windows return (Header, BaseOutputTechnology).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_TARGET_BASE_TYPE lhs, DISPLAYCONFIG_TARGET_BASE_TYPE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_TARGET_BASE_TYPE lhs, DISPLAYCONFIG_TARGET_BASE_TYPE rhs) => !(lhs == rhs); } @@ -831,6 +903,7 @@ namespace DisplayMagicianShared.Windows } } + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE other) => Header.Equals(other.Header) && Value == other.Value; @@ -840,7 +913,9 @@ namespace DisplayMagicianShared.Windows return (Header, Value).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE lhs, DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE lhs, DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -855,6 +930,7 @@ namespace DisplayMagicianShared.Windows // where it actually returns a uint! So had to engineer in a bug :( public uint SDRWhiteLevel; + public override bool Equals(object obj) => obj is DISPLAYCONFIG_SDR_WHITE_LEVEL other && this.Equals(other); public bool Equals(DISPLAYCONFIG_SDR_WHITE_LEVEL other) => Header.Equals(other.Header) && SDRWhiteLevel == other.SDRWhiteLevel; @@ -865,7 +941,9 @@ namespace DisplayMagicianShared.Windows return (Header, SDRWhiteLevel).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(DISPLAYCONFIG_SDR_WHITE_LEVEL lhs, DISPLAYCONFIG_SDR_WHITE_LEVEL rhs) => lhs.Equals(rhs); + + public static bool operator !=(DISPLAYCONFIG_SDR_WHITE_LEVEL lhs, DISPLAYCONFIG_SDR_WHITE_LEVEL rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -876,6 +954,7 @@ namespace DisplayMagicianShared.Windows public int Right; public int Bottom; + public override bool Equals(object obj) => obj is RECTL other && this.Equals(other); public bool Equals(RECTL other) => Left == other.Left && Top == other.Top && @@ -887,7 +966,9 @@ namespace DisplayMagicianShared.Windows return (Left, Top, Right, Bottom).GetHashCode(); } - //public override string ToString() => $"{type.ToString("G")}"; + public static bool operator ==(RECTL lhs, RECTL rhs) => lhs.Equals(rhs); + + public static bool operator !=(RECTL lhs, RECTL rhs) => !(lhs == rhs); } diff --git a/DisplayMagicianShared/Windows/WinLibrary.cs b/DisplayMagicianShared/Windows/WinLibrary.cs index b15e4d1..939ae5b 100644 --- a/DisplayMagicianShared/Windows/WinLibrary.cs +++ b/DisplayMagicianShared/Windows/WinLibrary.cs @@ -18,6 +18,7 @@ namespace DisplayMagicianShared.Windows public DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO AdvancedColorInfo; public DISPLAYCONFIG_SDR_WHITE_LEVEL SDRWhiteLevel; + public override bool Equals(object obj) => obj is ADVANCED_HDR_INFO_PER_PATH other && this.Equals(other); public bool Equals(ADVANCED_HDR_INFO_PER_PATH other) => // AdapterId.Equals(other.AdapterId) && // Removed the AdapterId from the Equals, as it changes after reboot. Id == other.Id && @@ -27,6 +28,10 @@ namespace DisplayMagicianShared.Windows { return (Id, AdvancedColorInfo, SDRWhiteLevel).GetHashCode(); } + + public static bool operator ==(ADVANCED_HDR_INFO_PER_PATH lhs, ADVANCED_HDR_INFO_PER_PATH rhs) => lhs.Equals(rhs); + + public static bool operator !=(ADVANCED_HDR_INFO_PER_PATH lhs, ADVANCED_HDR_INFO_PER_PATH rhs) => !(lhs == rhs); } [StructLayout(LayoutKind.Sequential)] @@ -38,6 +43,7 @@ namespace DisplayMagicianShared.Windows public ADVANCED_HDR_INFO_PER_PATH[] DisplayHDRStates; public List DisplayIdentifiers; + public override bool Equals(object obj) => obj is WINDOWS_DISPLAY_CONFIG other && this.Equals(other); public bool Equals(WINDOWS_DISPLAY_CONFIG other) => DisplayConfigPaths.SequenceEqual(other.DisplayConfigPaths) && DisplayConfigModes.SequenceEqual(other.DisplayConfigModes) && @@ -47,6 +53,9 @@ namespace DisplayMagicianShared.Windows { return (DisplayConfigPaths, DisplayConfigModes, DisplayHDRStates).GetHashCode(); } + public static bool operator ==(WINDOWS_DISPLAY_CONFIG lhs, WINDOWS_DISPLAY_CONFIG rhs) => lhs.Equals(rhs); + + public static bool operator !=(WINDOWS_DISPLAY_CONFIG lhs, WINDOWS_DISPLAY_CONFIG rhs) => !(lhs == rhs); } public class WinLibrary : IDisposable