PersistentWindows/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/Models/DesktopDisplayMetrics.cs
Min Yong Kim 9409d20445 1. Modification to make the application run in the systray
2. Abstracting processor and winapi logic into common dll and entry points into separate dlls
3. Adding icons
4. Switching build platform to AnyCPU. Seems to work on x64, don't have a x86 platform to test on
2015-02-27 00:38:08 -05:00

76 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Ninjacrab.PersistentWindows.Common.WinApiBridge;
namespace Ninjacrab.PersistentWindows.Common.Models
{
public class DesktopDisplayMetrics
{
public static DesktopDisplayMetrics AcquireMetrics()
{
DesktopDisplayMetrics metrics = new DesktopDisplayMetrics();
var displays = Display.GetDisplays();
int displayId = 0;
foreach (var display in displays)
{
metrics.SetMonitor(displayId++, display);
}
return metrics;
}
private Dictionary<int, Display> monitorResolutions = new Dictionary<int, Display>();
public int NumberOfDisplays { get { return monitorResolutions.Count; } }
public void SetMonitor(int id, Display display)
{
if (!monitorResolutions.ContainsKey(id) ||
monitorResolutions[id].ScreenWidth != display.ScreenWidth ||
monitorResolutions[id].ScreenHeight != display.ScreenHeight)
{
monitorResolutions.Add(id, display);
BuildKey();
}
}
private void BuildKey()
{
List<string> keySegments = new List<string>();
foreach(var entry in monitorResolutions.OrderBy(row => row.Key))
{
keySegments.Add(string.Format("[Id:{0} Loc:{1}x{2} Res:{3}x{4}]", entry.Key, entry.Value.Left, entry.Value.Top, entry.Value.ScreenWidth, entry.Value.ScreenHeight));
}
key = string.Join(",", keySegments);
}
private string key;
public string Key
{
get
{
return key;
}
}
public override bool Equals(object obj)
{
var other = obj as DesktopDisplayMetrics;
if (other == null)
{
return false;
}
return this.Key == other.key;
}
public override int GetHashCode()
{
return key.GetHashCode();
}
public int GetHashCode(DesktopDisplayMetrics obj)
{
return obj.key.GetHashCode();
}
}
}