mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Gamma Init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553913(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfig2DRegion : IEquatable<DisplayConfig2DRegion>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
|
||||
public DisplayConfig2DRegion(uint width, uint height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfig2DRegion other)
|
||||
{
|
||||
return Width == other.Width && Height == other.Height;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfig2DRegion region && Equals(region);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) Width * 397) ^ (int) Height;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfig2DRegion left, DisplayConfig2DRegion right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfig2DRegion left, DisplayConfig2DRegion right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553915(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigAdapterName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string AdapterDevicePath;
|
||||
|
||||
public DisplayConfigAdapterName(LUID adapter) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/mt622102(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigDesktopImageInfo : IEquatable<DisplayConfigDesktopImageInfo>
|
||||
{
|
||||
public const ushort InvalidDesktopImageModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly PointL PathSourceSize;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly RectangleL DesktopImageRegion;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly RectangleL DesktopImageClip;
|
||||
|
||||
public DisplayConfigDesktopImageInfo(
|
||||
PointL pathSourceSize,
|
||||
RectangleL desktopImageRegion,
|
||||
RectangleL desktopImageClip)
|
||||
{
|
||||
PathSourceSize = pathSourceSize;
|
||||
DesktopImageRegion = desktopImageRegion;
|
||||
DesktopImageClip = desktopImageClip;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigDesktopImageInfo other)
|
||||
{
|
||||
return PathSourceSize == other.PathSourceSize &&
|
||||
DesktopImageRegion == other.DesktopImageRegion &&
|
||||
DesktopImageClip == other.DesktopImageClip;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigDesktopImageInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = PathSourceSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ DesktopImageRegion.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ DesktopImageClip.GetHashCode();
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigDesktopImageInfo left, DisplayConfigDesktopImageInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigDesktopImageInfo left, DisplayConfigDesktopImageInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553920(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigDeviceInfoHeader
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigDeviceInfoType Type;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Size;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Id;
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(LUID adapterId, Type requestType) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Size = (uint) Marshal.SizeOf(requestType);
|
||||
|
||||
if (requestType == typeof(DisplayConfigSourceDeviceName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetSourceName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetDeviceName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetPreferredMode))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetPreferredMode;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigAdapterName))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetAdapterName;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSetTargetPersistence))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.SetTargetPersistence;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigTargetBaseType))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetTargetBaseType;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigGetSourceDPIScale))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.GetSourceDPIScale;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSetSourceDPIScale))
|
||||
{
|
||||
Type = DisplayConfigDeviceInfoType.SetSourceDPIScale;
|
||||
}
|
||||
else if (requestType == typeof(DisplayConfigSupportVirtualResolution))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// throw exception?
|
||||
}
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(LUID adapterId, uint id, Type requestType) : this(adapterId, requestType)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public DisplayConfigDeviceInfoHeader(
|
||||
LUID adapterId,
|
||||
uint id,
|
||||
Type requestType,
|
||||
DisplayConfigDeviceInfoType request)
|
||||
: this(adapterId, id, requestType)
|
||||
{
|
||||
Type = request;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// Internal undocumented structure
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigGetSourceDPIScale
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int MinimumScaleSteps { get; }
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int CurrentScaleSteps { get; }
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int MaximumScaleSteps { get; }
|
||||
|
||||
public DisplayConfigGetSourceDPIScale(LUID adapter, uint sourceId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553933(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Explicit)] // Size = 64
|
||||
internal struct DisplayConfigModeInfo : IEquatable<DisplayConfigModeInfo>
|
||||
{
|
||||
public const uint InvalidModeIndex = 0xffffffff;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(0)]
|
||||
public readonly DisplayConfigModeInfoType InfoType;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)] [FieldOffset(4)]
|
||||
public readonly uint Id;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(8)]
|
||||
public readonly LUID AdapterId;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigTargetMode TargetMode;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigSourceMode SourceMode;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(16)]
|
||||
public readonly DisplayConfigDesktopImageInfo
|
||||
DesktopImageInfo;
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigTargetMode targetMode) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
TargetMode = targetMode;
|
||||
InfoType = DisplayConfigModeInfoType.Target;
|
||||
}
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigSourceMode sourceMode) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
SourceMode = sourceMode;
|
||||
InfoType = DisplayConfigModeInfoType.Source;
|
||||
}
|
||||
|
||||
public DisplayConfigModeInfo(LUID adapterId, uint id, DisplayConfigDesktopImageInfo desktopImageInfo) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
Id = id;
|
||||
DesktopImageInfo = desktopImageInfo;
|
||||
InfoType = DisplayConfigModeInfoType.DesktopImage;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigModeInfo other)
|
||||
{
|
||||
return InfoType == other.InfoType &&
|
||||
Id == other.Id &&
|
||||
AdapterId == other.AdapterId &&
|
||||
(InfoType == DisplayConfigModeInfoType.Source && SourceMode == other.SourceMode ||
|
||||
InfoType == DisplayConfigModeInfoType.Target && TargetMode == other.TargetMode ||
|
||||
InfoType == DisplayConfigModeInfoType.DesktopImage &&
|
||||
DesktopImageInfo == other.DesktopImageInfo);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigModeInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (int) InfoType;
|
||||
hashCode = (hashCode * 397) ^ (int) Id;
|
||||
hashCode = (hashCode * 397) ^ AdapterId.GetHashCode();
|
||||
|
||||
switch (InfoType)
|
||||
{
|
||||
case DisplayConfigModeInfoType.Source:
|
||||
hashCode = (hashCode * 397) ^ SourceMode.GetHashCode();
|
||||
|
||||
break;
|
||||
case DisplayConfigModeInfoType.Target:
|
||||
hashCode = (hashCode * 397) ^ TargetMode.GetHashCode();
|
||||
|
||||
break;
|
||||
case DisplayConfigModeInfoType.DesktopImage:
|
||||
hashCode = (hashCode * 397) ^ DesktopImageInfo.GetHashCode();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigModeInfo left, DisplayConfigModeInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigModeInfo left, DisplayConfigModeInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553945(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigPathSourceInfo SourceInfo;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigPathTargetInfo TargetInfo;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathInfoFlags Flags;
|
||||
|
||||
public DisplayConfigPathInfo(
|
||||
DisplayConfigPathSourceInfo sourceInfo,
|
||||
DisplayConfigPathTargetInfo targetInfo,
|
||||
DisplayConfigPathInfoFlags flags)
|
||||
{
|
||||
SourceInfo = sourceInfo;
|
||||
TargetInfo = targetInfo;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
public DisplayConfigPathInfo(DisplayConfigPathSourceInfo sourceInfo, DisplayConfigPathInfoFlags flags)
|
||||
{
|
||||
SourceInfo = sourceInfo;
|
||||
Flags = flags;
|
||||
TargetInfo = new DisplayConfigPathTargetInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553951(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathSourceInfo
|
||||
{
|
||||
public const ushort InvalidCloneGroupId = 0xffff;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint SourceId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ModeInfoIndex;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathSourceInfoFlags StatusFlags;
|
||||
|
||||
public ushort SourceModeInfoIndex
|
||||
{
|
||||
get => (ushort) ((ModeInfoIndex << 16) >> 16);
|
||||
}
|
||||
|
||||
public ushort CloneGroupId
|
||||
{
|
||||
get => (ushort) (ModeInfoIndex >> 16);
|
||||
}
|
||||
|
||||
public DisplayConfigPathSourceInfo(LUID adapterId, uint sourceId, uint modeInfoIndex) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
SourceId = sourceId;
|
||||
ModeInfoIndex = modeInfoIndex;
|
||||
}
|
||||
|
||||
public DisplayConfigPathSourceInfo(
|
||||
LUID adapterId,
|
||||
uint sourceId,
|
||||
ushort sourceModeInfoIndex,
|
||||
ushort cloneGroupId) : this(adapterId, sourceId, 0)
|
||||
{
|
||||
ModeInfoIndex = (uint) (sourceModeInfoIndex + (cloneGroupId << 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553954(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigPathTargetInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly LUID AdapterId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint TargetId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ModeInfoIndex;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology OutputTechnology;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigRotation Rotation;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScaling Scaling;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational RefreshRate;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScanLineOrdering ScanLineOrdering;
|
||||
[MarshalAs(UnmanagedType.Bool)] public readonly bool TargetAvailable;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPathTargetInfoFlags StatusFlags;
|
||||
|
||||
public ushort TargetModeInfoIndex
|
||||
{
|
||||
get => (ushort) ((ModeInfoIndex << 16) >> 16);
|
||||
}
|
||||
|
||||
public ushort DesktopModeInfoIndex
|
||||
{
|
||||
get => (ushort) (ModeInfoIndex >> 16);
|
||||
}
|
||||
|
||||
public DisplayConfigPathTargetInfo(
|
||||
LUID adapterId,
|
||||
uint targetId,
|
||||
uint modeInfoIndex,
|
||||
DisplayConfigVideoOutputTechnology outputTechnology,
|
||||
DisplayConfigRotation rotation,
|
||||
DisplayConfigScaling scaling,
|
||||
DisplayConfigRational refreshRate,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering,
|
||||
bool targetAvailable) : this()
|
||||
{
|
||||
AdapterId = adapterId;
|
||||
TargetId = targetId;
|
||||
ModeInfoIndex = modeInfoIndex;
|
||||
OutputTechnology = outputTechnology;
|
||||
Rotation = rotation;
|
||||
Scaling = scaling;
|
||||
RefreshRate = refreshRate;
|
||||
ScanLineOrdering = scanLineOrdering;
|
||||
TargetAvailable = targetAvailable;
|
||||
}
|
||||
|
||||
public DisplayConfigPathTargetInfo(
|
||||
LUID adapterId,
|
||||
uint targetId,
|
||||
ushort targetModeInfoIndex,
|
||||
ushort desktopModeInfoIndex,
|
||||
DisplayConfigVideoOutputTechnology outputTechnology,
|
||||
DisplayConfigRotation rotation,
|
||||
DisplayConfigScaling scaling,
|
||||
DisplayConfigRational refreshRate,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering,
|
||||
bool targetAvailable)
|
||||
: this(
|
||||
adapterId, targetId, 0, outputTechnology, rotation, scaling, refreshRate, scanLineOrdering,
|
||||
targetAvailable)
|
||||
{
|
||||
ModeInfoIndex = (uint) (targetModeInfoIndex + (desktopModeInfoIndex << 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553968(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigRational : IEquatable<DisplayConfigRational>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Numerator;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Denominator;
|
||||
|
||||
public DisplayConfigRational(uint numerator, uint denominator, bool simplify)
|
||||
: this((ulong) numerator, denominator, simplify)
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayConfigRational(ulong numerator, ulong denominator, bool simplify)
|
||||
{
|
||||
var gcm = simplify & (numerator != 0) ? Euclidean(numerator, denominator) : 1;
|
||||
Numerator = (uint) (numerator / gcm);
|
||||
Denominator = (uint) (denominator / gcm);
|
||||
}
|
||||
|
||||
private static ulong Euclidean(ulong a, ulong b)
|
||||
{
|
||||
while (a != 0 && b != 0)
|
||||
{
|
||||
if (a > b)
|
||||
{
|
||||
a %= b;
|
||||
}
|
||||
else
|
||||
{
|
||||
b %= a;
|
||||
}
|
||||
}
|
||||
|
||||
return a == 0 ? b : a;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public ulong ToValue(ulong multiplier = 1)
|
||||
{
|
||||
if (Numerator == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Numerator * multiplier / Denominator;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigRational other)
|
||||
{
|
||||
if (Numerator == other.Numerator && Denominator == other.Denominator)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var left = Numerator / (double) Denominator;
|
||||
var right = other.Numerator / (double) other.Denominator;
|
||||
|
||||
return Math.Abs(left - right) <= Math.Max(Math.Abs(left), Math.Abs(right)) * 1E-15;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigRational rational && Equals(rational);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) Numerator * 397) ^ (int) Denominator;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigRational left, DisplayConfigRational right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigRational left, DisplayConfigRational right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// Internal undocumented structure
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSetSourceDPIScale
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[field: MarshalAs(UnmanagedType.U4)]
|
||||
public int ScaleSteps { get; }
|
||||
|
||||
public DisplayConfigSetSourceDPIScale(LUID adapter, uint sourceId, int scaleSteps) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
ScaleSteps = scaleSteps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553981(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSetTargetPersistence
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] private readonly uint _BootPersistenceOn;
|
||||
|
||||
public bool BootPersistence
|
||||
{
|
||||
get => _BootPersistenceOn > 0;
|
||||
}
|
||||
|
||||
public DisplayConfigSetTargetPersistence(LUID adapter, uint targetId, bool bootPersistence) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
_BootPersistenceOn = bootPersistence ? 1u : 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553983(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigSourceDeviceName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public readonly string DeviceName;
|
||||
|
||||
public DisplayConfigSourceDeviceName(LUID adapter, uint sourceId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, sourceId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553986(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigSourceMode : IEquatable<DisplayConfigSourceMode>
|
||||
{
|
||||
public const ushort InvalidSourceModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigPixelFormat PixelFormat;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly PointL Position;
|
||||
|
||||
public DisplayConfigSourceMode(uint width, uint height, DisplayConfigPixelFormat pixelFormat, PointL position)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
PixelFormat = pixelFormat;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigSourceMode other)
|
||||
{
|
||||
return Width == other.Width &&
|
||||
Height == other.Height &&
|
||||
PixelFormat == other.PixelFormat &&
|
||||
Position == other.Position;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigSourceMode mode && Equals(mode);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (int) Width;
|
||||
hashCode = (hashCode * 397) ^ (int) Height;
|
||||
hashCode = (hashCode * 397) ^ (int) PixelFormat;
|
||||
hashCode = (hashCode * 397) ^ Position.GetHashCode();
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigSourceMode left, DisplayConfigSourceMode right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigSourceMode left, DisplayConfigSourceMode right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/mt622103(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigSupportVirtualResolution
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] private readonly int _DisableMonitorVirtualResolution;
|
||||
|
||||
public bool DisableMonitorVirtualResolution
|
||||
{
|
||||
get => _DisableMonitorVirtualResolution > 0;
|
||||
}
|
||||
|
||||
public DisplayConfigSupportVirtualResolution(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType(),
|
||||
DisplayConfigDeviceInfoType.GetSupportVirtualResolution);
|
||||
}
|
||||
|
||||
public DisplayConfigSupportVirtualResolution(LUID adapter, uint targetId, bool disableMonitorVirtualResolution)
|
||||
: this()
|
||||
{
|
||||
_DisableMonitorVirtualResolution = disableMonitorVirtualResolution ? 1 : 0;
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType(),
|
||||
DisplayConfigDeviceInfoType.SetSupportVirtualResolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dn362043(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetBaseType
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology BaseOutputTechnology;
|
||||
|
||||
public DisplayConfigTargetBaseType(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553989(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DisplayConfigTargetDeviceName
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigTargetDeviceNameFlags Flags;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigVideoOutputTechnology OutputTechnology;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort EDIDManufactureId;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort EDIDProductCodeId;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint ConnectorInstance;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
||||
public readonly string MonitorFriendlyDeviceName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public readonly string MonitorDevicePath;
|
||||
|
||||
|
||||
public DisplayConfigTargetDeviceName(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553993(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetMode : IEquatable<DisplayConfigTargetMode>
|
||||
{
|
||||
public const ushort InvalidTargetModeIndex = 0xffff;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigVideoSignalInfo TargetVideoSignalInfo;
|
||||
|
||||
public DisplayConfigTargetMode(DisplayConfigVideoSignalInfo targetVideoSignalInfo)
|
||||
{
|
||||
TargetVideoSignalInfo = targetVideoSignalInfo;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigTargetMode other)
|
||||
{
|
||||
return TargetVideoSignalInfo == other.TargetVideoSignalInfo;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigTargetMode mode && Equals(mode);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return TargetVideoSignalInfo.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigTargetMode left, DisplayConfigTargetMode right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigTargetMode left, DisplayConfigTargetMode right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using WindowsDisplayAPI.Native.Structures;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/ff553996(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigTargetPreferredMode
|
||||
{
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
[MarshalAs(UnmanagedType.Struct)] private readonly DisplayConfigDeviceInfoHeader _Header;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Width;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly uint Height;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigTargetMode TargetMode;
|
||||
|
||||
public DisplayConfigTargetPreferredMode(LUID adapter, uint targetId) : this()
|
||||
{
|
||||
_Header = new DisplayConfigDeviceInfoHeader(adapter, targetId, GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DisplayConfig.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff554007(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DisplayConfigVideoSignalInfo : IEquatable<DisplayConfigVideoSignalInfo>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U8)] public readonly ulong PixelRate;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational HorizontalSyncFrequency;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfigRational VerticalSyncFrequency;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfig2DRegion ActiveSize;
|
||||
[MarshalAs(UnmanagedType.Struct)] public readonly DisplayConfig2DRegion TotalSize;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly VideoSignalStandard VideoStandard;
|
||||
[MarshalAs(UnmanagedType.U2)] public readonly ushort VerticalSyncFrequencyDivider;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly DisplayConfigScanLineOrdering ScanLineOrdering;
|
||||
|
||||
public DisplayConfigVideoSignalInfo(
|
||||
ulong pixelRate,
|
||||
DisplayConfigRational horizontalSyncFrequency,
|
||||
DisplayConfigRational verticalSyncFrequency,
|
||||
DisplayConfig2DRegion activeSize,
|
||||
DisplayConfig2DRegion totalSize,
|
||||
VideoSignalStandard videoStandard,
|
||||
ushort verticalSyncFrequencyDivider,
|
||||
DisplayConfigScanLineOrdering scanLineOrdering)
|
||||
{
|
||||
PixelRate = pixelRate;
|
||||
HorizontalSyncFrequency = horizontalSyncFrequency;
|
||||
VerticalSyncFrequency = verticalSyncFrequency;
|
||||
ActiveSize = activeSize;
|
||||
TotalSize = totalSize;
|
||||
VideoStandard = videoStandard;
|
||||
VerticalSyncFrequencyDivider = verticalSyncFrequencyDivider;
|
||||
ScanLineOrdering = scanLineOrdering;
|
||||
}
|
||||
|
||||
public bool Equals(DisplayConfigVideoSignalInfo other)
|
||||
{
|
||||
return PixelRate == other.PixelRate &&
|
||||
HorizontalSyncFrequency == other.HorizontalSyncFrequency &&
|
||||
VerticalSyncFrequency == other.VerticalSyncFrequency &&
|
||||
ActiveSize == other.ActiveSize &&
|
||||
TotalSize == other.TotalSize &&
|
||||
VideoStandard == other.VideoStandard &&
|
||||
VerticalSyncFrequencyDivider == other.VerticalSyncFrequencyDivider &&
|
||||
ScanLineOrdering == other.ScanLineOrdering;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is DisplayConfigVideoSignalInfo info && Equals(info);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = PixelRate.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ HorizontalSyncFrequency.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ VerticalSyncFrequency.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ ActiveSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ TotalSize.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int) VideoStandard;
|
||||
hashCode = (hashCode * 397) ^ VerticalSyncFrequencyDivider.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int) ScanLineOrdering;
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DisplayConfigVideoSignalInfo left, DisplayConfigVideoSignalInfo right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DisplayConfigVideoSignalInfo left, DisplayConfigVideoSignalInfo right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user