using System;
using System.Linq;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display.Structures;
namespace NvAPIWrapper.Display
{
///
/// Represents an unattached display
///
public class UnAttachedDisplay : IEquatable
{
///
/// Creates a new UnAttachedDisplay
///
/// Handle of the unattached display device
public UnAttachedDisplay(UnAttachedDisplayHandle handle)
{
Handle = handle;
}
///
/// Creates a new UnAttachedDisplay
///
/// Name of the unattached display device
public UnAttachedDisplay(string displayName)
{
Handle = DisplayApi.GetAssociatedUnAttachedNvidiaDisplayHandle(displayName);
}
///
/// Gets display handle
///
public UnAttachedDisplayHandle Handle { get; }
///
/// Gets display name
///
public string Name
{
get => DisplayApi.GetUnAttachedAssociatedDisplayName(Handle);
}
///
/// Gets corresponding physical GPU
///
public PhysicalGPU PhysicalGPU
{
get => new PhysicalGPU(GPUApi.GetPhysicalGPUFromUnAttachedDisplay(Handle));
}
///
/// Checks for equality with a UnAttachedDisplay instance
///
/// The Display object to check with
/// true if both objects are equal, otherwise false
public bool Equals(UnAttachedDisplay other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Handle.Equals(other.Handle);
}
///
/// This function returns all unattached NVIDIA displays
/// Note: Display handles can get invalidated on a modeset.
///
/// An array of Display objects
public static UnAttachedDisplay[] GetUnAttachedDisplays()
{
return
DisplayApi.EnumNvidiaUnAttachedDisplayHandle().Select(handle => new UnAttachedDisplay(handle))
.ToArray();
}
///
/// Checks for equality between two objects of same type
///
/// The first object
/// The second object
/// true, if both objects are equal, otherwise false
public static bool operator ==(UnAttachedDisplay left, UnAttachedDisplay right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
///
/// Checks for inequality between two objects of same type
///
/// The first object
/// The second object
/// true, if both objects are not equal, otherwise false
public static bool operator !=(UnAttachedDisplay left, UnAttachedDisplay right)
{
return !(left == right);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((UnAttachedDisplay) obj);
}
///
public override int GetHashCode()
{
return Handle.GetHashCode();
}
///
public override string ToString()
{
return Name;
}
///
/// Creates a new active attached display from this unattached display
/// At least one GPU must be present in the system and running an NVIDIA display driver.
///
/// An active attached display
public Display CreateDisplay()
{
return new Display(DisplayApi.CreateDisplayFromUnAttachedDisplay(Handle));
}
}
}