PowerControl: Tweaks and fixes (#29)

* Fix context menu, add osd toggle
* Update values on number of displays change
* Check display info in DeviceManager
* Refactor OSD toggle
* Isolate display context setup
* Move more context stuff to the display initialize method
This commit is contained in:
maniman303 2022-12-19 21:36:58 +01:00 committed by Kamil Trzciński
parent 1074143a6e
commit 64f4050de5
3 changed files with 119 additions and 2 deletions

View file

@ -11,6 +11,30 @@ namespace PowerControl.Helpers
{
internal class DeviceManager
{
private static Screen[] screens = new Screen[0];
public static int NumberOfDisplays
{
get { return screens.Length; }
}
public static void LoadDisplays()
{
screens = Screen.AllScreens;
}
public static bool RefreshDisplays()
{
var newScreens = Screen.AllScreens;
if (HaveScreensChanged(newScreens))
{
screens = newScreens;
return true;
}
return false;
}
public static string[]? GetDevices(Guid? classGuid)
{
string? filter = null;
@ -126,6 +150,25 @@ namespace PowerControl.Helpers
}
}
private static bool HaveScreensChanged(Screen[] newScreens)
{
if (screens.Length != newScreens.Length)
{
return true;
}
for (int i = 0; i < screens.Length; i++)
{
if (screens[i].DeviceName != newScreens[i].DeviceName ||
screens[i].Primary != newScreens[i].Primary)
{
return true;
}
}
return false;
}
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern int CM_Locate_DevNode(out IntPtr pdnDevInst, string pDeviceID, int ulFlags);