From 848682a27f2c763e82bb3bf703115c15c4a408ee Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 28 Jan 2021 16:56:19 -0600 Subject: [PATCH] Oh hey SetForegroundWindow might be the thing --- src/cascadia/WindowsTerminal/IslandWindow.cpp | 33 +++++++++++++++++-- src/cascadia/WindowsTerminal/IslandWindow.h | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index c8e2eb8c237..ea353deadea 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -373,8 +373,9 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize { // send focus to the child window SetFocus(_interopWindowHandle); - return 0; // eat the message + // return 0; // eat the message } + break; } case WM_ACTIVATE: { @@ -867,11 +868,37 @@ void IslandWindow::SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalCon } } -void IslandWindow::SummonWindow() +winrt::fire_and_forget IslandWindow::SummonWindow() { // A SC_HOTKEY WM_SYSCOMMAND that's _not_ processed my a wndproc will summon // the window exactly the way we want. So send that yo ourselves. - SendMessage(_window.get(), WM_SYSCOMMAND, SC_HOTKEY, (LPARAM)(_window.get())); + + // Does the mysterious "cursor starts blinking but doesn't accept keyboard focus" + // SendMessage(_window.get(), WM_SYSCOMMAND, SC_HOTKEY, (LPARAM)(_window.get())); + + // Does the mysterious "cursor starts blinking but doesn't accept keyboard focus" + // ShowWindow(_window.get(), SW_RESTORE); + // SetActiveWindow(_window.get()); + // SetFocus(_window.get()); + + // Does nothing at all + // ShowWindow(_window.get(), SW_SHOWNORMAL); + + // The co_await didn't help here + // co_await winrt::resume_foreground(_rootGrid.Dispatcher()); + // ShowWindow(_window.get(), SW_RESTORE); + // SetActiveWindow(_window.get()); + // SetFocus(_window.get()); + + co_await winrt::resume_foreground(_rootGrid.Dispatcher()); + SetWindowPos(_window.get(), + HWND_TOP, + 0, + 0, + 0, + 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + SetForegroundWindow(_window.get()); } DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>); diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index 8cfdc8f445b..4f91945953c 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -40,7 +40,7 @@ class IslandWindow : void SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalControl::KeyChord& hotkey); - void SummonWindow(); + winrt::fire_and_forget SummonWindow(); #pragma endregion