app: fix some stuff

This commit is contained in:
Nguyen Duy
2024-06-07 16:02:50 +07:00
parent 42cd69acac
commit 170b9b2fee
3 changed files with 35 additions and 12 deletions
+25 -7
View File
@@ -24,7 +24,13 @@ namespace ParsecVDisplay
public static bool Init()
{
return Device.OpenHandle(ADAPTER_GUID, out VddHandle);
if (Device.OpenHandle(ADAPTER_GUID, out VddHandle))
{
Ping();
return true;
}
return false;
}
public static void Uninit()
@@ -86,7 +92,7 @@ namespace ParsecVDisplay
var input = new byte[2];
input[1] = (byte)(index & 0xFF);
if (Core.IoControl(VddHandle, Core.IOCTL_REMOVE, input, out var _, 1000))
if (Core.IoControl(VddHandle, Core.IOCTL_REMOVE, input, 1000))
{
Ping();
return true;
@@ -97,7 +103,7 @@ namespace ParsecVDisplay
public static void Ping()
{
Core.IoControl(VddHandle, Core.IOCTL_UPDATE, null, out var _, 1000);
Core.IoControl(VddHandle, Core.IOCTL_UPDATE, null, 1000);
}
static unsafe class Core
@@ -112,11 +118,10 @@ namespace ParsecVDisplay
// but unused in Parsec app
public const uint IOCTL_UNKNOWN1 = 0x22A014;
public static bool IoControl(IntPtr handle, uint code, byte[] input, out int result, int timeout)
static bool IoControl(IntPtr handle, uint code, byte[] input, int* result, int timeout)
{
var InBuffer = new byte[32];
var Overlapped = new Native.OVERLAPPED();
int OutBuffer = 0;
if (input != null && input.Length > 0)
{
@@ -125,11 +130,12 @@ namespace ParsecVDisplay
fixed (byte* buffer = InBuffer)
{
int outputLength = result != null ? sizeof(int) : 0;
Overlapped.hEvent = Native.CreateEvent(null, false, false, null);
Native.DeviceIoControl(handle, code,
buffer, InBuffer.Length,
&OutBuffer, sizeof(uint),
result, outputLength,
null, ref Overlapped);
bool success = Native.GetOverlappedResultEx(handle, ref Overlapped,
@@ -138,10 +144,22 @@ namespace ParsecVDisplay
if (Overlapped.hEvent != IntPtr.Zero)
Native.CloseHandle(Overlapped.hEvent);
result = OutBuffer;
return success;
}
}
public static bool IoControl(IntPtr handle, uint code, byte[] input, int timeout)
{
return IoControl(handle, code, input, null, timeout);
}
public static bool IoControl(IntPtr handle, uint code, byte[] input, out int result, int timeout)
{
int output;
bool success = IoControl(handle, code, input, &output, timeout);
result = output;
return success;
}
}
public static IList<Display.Mode> GetCustomDisplayModes()
+2 -1
View File
@@ -5,7 +5,6 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2D44934F-B4CF-4F2C-BD03-AE60B71AD045}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ParsecVDisplay</RootNamespace>
<AssemblyName>ParsecVDisplay</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
@@ -16,6 +15,7 @@
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputType>Exe</OutputType>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@@ -28,6 +28,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputType>WinExe</OutputType>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
+8 -4
View File
@@ -115,6 +115,7 @@ namespace ParsecVDisplay
void RestoreDisplays()
{
ParsecVDD.Ping();
var savedCount = Config.DisplayCount;
if (savedCount > 0)
@@ -256,17 +257,20 @@ namespace ParsecVDisplay
void Exit(object sender, EventArgs e)
{
SystemEvents.SessionEnding -= SaveDisplayCount;
SystemEvents.SessionSwitch -= SaveDisplayCount;
SystemEvents.DisplaySettingsChanged -= SaveDisplayCount;
var displays = ParsecVDD.GetDisplays();
if (displays.Count > 0)
{
if (MessageBox.Show(Owner, App.GetTranslation("t_msg_prompt_leave_all"),
Program.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
return;
}
SystemEvents.SessionEnding -= SaveDisplayCount;
SystemEvents.SessionSwitch -= SaveDisplayCount;
SystemEvents.DisplaySettingsChanged -= SaveDisplayCount;
if (displays.Count > 0)
{
for (int i = displays.Count - 1; i >= 0; i--)
{
var index = displays[i].DisplayIndex;