Skip to content

Commit

Permalink
Fix Windows Terminal hide/show functions (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
bangfire authored Dec 7, 2024
1 parent 06abba2 commit 8ae72c1
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ namespace Ryujinx.UI.Common.Helper
{
public static partial class ConsoleHelper
{
[SupportedOSPlatform("windows")]
[LibraryImport("kernel32")]
private static partial nint GetConsoleWindow();

[SupportedOSPlatform("windows")]
[LibraryImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool ShowWindow(nint hWnd, int nCmdShow);

[SupportedOSPlatform("windows")]
[LibraryImport("user32")]
private static partial nint GetForegroundWindow();

[SupportedOSPlatform("windows")]
[LibraryImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool SetForegroundWindow(nint hWnd);

public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows();

public static void SetConsoleWindowState(bool show)
Expand Down Expand Up @@ -35,16 +53,11 @@ private static void SetConsoleWindowStateWindows(bool show)
return;
}

ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
}
SetForegroundWindow(hWnd);

[SupportedOSPlatform("windows")]
[LibraryImport("kernel32")]
private static partial nint GetConsoleWindow();
hWnd = GetForegroundWindow();

[SupportedOSPlatform("windows")]
[LibraryImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool ShowWindow(nint hWnd, int nCmdShow);
ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
}
}
}

0 comments on commit 8ae72c1

Please sign in to comment.