Skip to content

Commit

Permalink
Fix Windows Terminal hide/show functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangfire committed Dec 3, 2024
1 parent 08b7257 commit 3ec0eda
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
using Ryujinx.Common.Logging;
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Runtime.Versioning;

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 +55,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 3ec0eda

Please sign in to comment.