diff --git a/FluentTerminal.App.Services/Implementation/KeyboardCommandService.cs b/FluentTerminal.App.Services/Implementation/KeyboardCommandService.cs index 31b9b3a..894c9cf 100644 --- a/FluentTerminal.App.Services/Implementation/KeyboardCommandService.cs +++ b/FluentTerminal.App.Services/Implementation/KeyboardCommandService.cs @@ -25,6 +25,13 @@ namespace FluentTerminal.App.Services.Implementation handler.Invoke(); return; } + + // already registered by SystemTray's ToggleWindowService + if (command == Command.ToggleWindow) + { + return; + } + throw new KeyNotFoundException($"No handler registered for command: {command}"); } } diff --git a/FluentTerminal.SystemTray/Services/ToggleWindowService.cs b/FluentTerminal.SystemTray/Services/ToggleWindowService.cs index ac2aee9..45ccec5 100644 --- a/FluentTerminal.SystemTray/Services/ToggleWindowService.cs +++ b/FluentTerminal.SystemTray/Services/ToggleWindowService.cs @@ -22,6 +22,8 @@ namespace FluentTerminal.SystemTray.Services private bool _disposedValue; private List _hotKeys; + private const int SW_MINIMIZE = 6; + public ToggleWindowService(Dispatcher dispatcher, HotKeyManager hotKeyManager, NotificationService notificationService) { _dispatcher = dispatcher; @@ -103,6 +105,9 @@ namespace FluentTerminal.SystemTray.Services [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); + [DllImport("user32.dll")] + private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + private static string GetKeyBindingRepresentation(KeyBinding keyBinding) { var keys = new List(); @@ -145,8 +150,9 @@ namespace FluentTerminal.SystemTray.Services private async void OnKeyPressed(object sender, KeyPressedEventArgs e) { if (GetActiveProcessFileName() == "Fluent Terminal") - { - SendKeys.Send("%{Tab}"); + { + var hwnd = GetForegroundWindow(); + ShowWindow(hwnd, SW_MINIMIZE); } else {