Skip to content

Commit

Permalink
Oh hey SetForegroundWindow might be the thing
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jan 28, 2021
1 parent 91b52d4 commit 848682a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down Expand Up @@ -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<>);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IslandWindow :

void SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalControl::KeyChord& hotkey);

void SummonWindow();
winrt::fire_and_forget SummonWindow();

#pragma endregion

Expand Down

0 comments on commit 848682a

Please sign in to comment.