mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Screen detection fix
This commit is contained in:
@@ -1,10 +1,27 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
using static GHelper.Display.ScreenInterrogatory;
|
using static GHelper.Display.ScreenInterrogatory;
|
||||||
|
|
||||||
namespace GHelper.Display
|
namespace GHelper.Display
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class DeviceComparer : IComparer
|
||||||
|
{
|
||||||
|
public int Compare(object x, object y)
|
||||||
|
{
|
||||||
|
uint displayX = ((DISPLAYCONFIG_TARGET_DEVICE_NAME)x).connectorInstance;
|
||||||
|
uint displayY = ((DISPLAYCONFIG_TARGET_DEVICE_NAME)y).connectorInstance;
|
||||||
|
|
||||||
|
if (displayX > displayY)
|
||||||
|
return 1;
|
||||||
|
if (displayX < displayY)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ScreenComparer : IComparer
|
class ScreenComparer : IComparer
|
||||||
{
|
{
|
||||||
public int Compare(object x, object y)
|
public int Compare(object x, object y)
|
||||||
@@ -129,38 +146,19 @@ namespace GHelper.Display
|
|||||||
public const int ENUM_CURRENT_SETTINGS = -1;
|
public const int ENUM_CURRENT_SETTINGS = -1;
|
||||||
public const string defaultDevice = @"\\.\DISPLAY1";
|
public const string defaultDevice = @"\\.\DISPLAY1";
|
||||||
|
|
||||||
static bool? _ultimate = null;
|
|
||||||
|
|
||||||
static bool isUltimate
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_ultimate is null) _ultimate = (Program.acpi.DeviceGet(AsusACPI.GPUMux) == 0);
|
|
||||||
return (bool)_ultimate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string? FindLaptopScreen(bool log = false)
|
public static string? FindLaptopScreen(bool log = false)
|
||||||
{
|
{
|
||||||
string? laptopScreen = null;
|
string? laptopScreen = null;
|
||||||
var screens = Screen.AllScreens;
|
var screens = Screen.AllScreens;
|
||||||
|
|
||||||
/*
|
|
||||||
if (!isUltimate)
|
|
||||||
{
|
|
||||||
foreach (var screen in screens )
|
|
||||||
{
|
|
||||||
if (log) Logger.WriteLine(screen.DeviceName);
|
|
||||||
if (screen.DeviceName == defaultDevice) return defaultDevice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var devices = GetAllDevices().ToArray();
|
var devices = GetAllDevices().ToArray();
|
||||||
|
|
||||||
int count = 0, displayNum = -1;
|
Array.Sort(devices, new DeviceComparer());
|
||||||
|
Array.Sort(screens, new ScreenComparer());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
string internalName = AppConfig.GetString("internal_display");
|
string internalName = AppConfig.GetString("internal_display");
|
||||||
|
|
||||||
@@ -170,23 +168,23 @@ namespace GHelper.Display
|
|||||||
device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
|
device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
|
||||||
device.monitorFriendlyDeviceName == internalName)
|
device.monitorFriendlyDeviceName == internalName)
|
||||||
{
|
{
|
||||||
displayNum = count;
|
|
||||||
AppConfig.Set("internal_display", device.monitorFriendlyDeviceName);
|
AppConfig.Set("internal_display", device.monitorFriendlyDeviceName);
|
||||||
|
|
||||||
|
if (count < screens.Length)
|
||||||
|
{
|
||||||
|
laptopScreen = screens[count].DeviceName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
laptopScreen = defaultDevice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (log) Logger.WriteLine(device.monitorFriendlyDeviceName + ":" + device.outputTechnology.ToString() + ": " + ((count < screens.Length) ? screens[count].DeviceName : ""));
|
|
||||||
|
|
||||||
|
if (log) Logger.WriteLine(device.monitorFriendlyDeviceName + ":" + device.outputTechnology.ToString() + device.connectorInstance.ToString() + ": " + ((count < screens.Length) ? screens[count].DeviceName : ""));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.Sort(screens, new ScreenComparer());
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
foreach (var screen in screens)
|
|
||||||
{
|
|
||||||
if (count == displayNum) laptopScreen = screen.DeviceName;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayNum > 0 && count == 0) laptopScreen = defaultDevice;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user