Order resolutions

This commit is contained in:
Kamil Trzciński 2022-11-19 09:19:57 +01:00
parent e5fd135b30
commit b94719adb0

View file

@ -1,6 +1,7 @@
using Microsoft.VisualBasic.Logging;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@ -200,7 +201,7 @@ namespace PowerControl.Helpers
UpdateMonitors();
}
public struct DisplayResolution
public struct DisplayResolution : IComparable<DisplayResolution>
{
public int Width { get; set; }
public int Height { get; set; }
@ -218,6 +219,13 @@ namespace PowerControl.Helpers
public override readonly int GetHashCode() => HashCode.Combine(Width, Height);
public int CompareTo(DisplayResolution other)
{
var index = Width.CompareTo(other.Width);
if (index == 0) index = Height.CompareTo(other.Height);
return index;
}
public override string ToString()
{
return String.Format("{0}x{1}", Width, Height);
@ -254,7 +262,7 @@ namespace PowerControl.Helpers
{
return FindAllDisplaySettings()
.Select((dm) => new DisplayResolution(dm.dmPelsWidth, dm.dmPelsHeight))
.ToHashSet()
.ToImmutableSortedSet()
.ToArray();
}