Skip to content

Commit 83dadd1

Browse files
committed
Fix multiple regressions since #18215
1 parent 1e0bd85 commit 83dadd1

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::Control::MouseButtonState
5757
// the current foreground window, but still on top of another Terminal window in the background.
5858
static void hideCursorUntilMoved()
5959
{
60-
static CoreCursor previousCursor{ nullptr };
60+
static bool cursorIsHidden;
6161
static const auto shouldVanish = []() {
6262
BOOL shouldVanish = TRUE;
6363
SystemParametersInfoW(SPI_GETMOUSEVANISH, 0, &shouldVanish, 0);
@@ -68,16 +68,16 @@ static void hideCursorUntilMoved()
6868

6969
const auto window = CoreWindow::GetForCurrentThread();
7070
static constexpr auto releaseCapture = [](CoreWindow window, PointerEventArgs) {
71-
if (previousCursor)
71+
if (cursorIsHidden)
7272
{
7373
window.ReleasePointerCapture();
7474
}
7575
};
7676
static constexpr auto restoreCursor = [](CoreWindow window, PointerEventArgs) {
77-
if (previousCursor)
77+
if (cursorIsHidden)
7878
{
79-
window.PointerCursor(previousCursor);
80-
previousCursor = nullptr;
79+
cursorIsHidden = false;
80+
window.PointerCursor(CoreCursor{ CoreCursorType::Arrow, 0 });
8181
}
8282
};
8383

@@ -90,20 +90,14 @@ static void hideCursorUntilMoved()
9090
return true;
9191
}();
9292

93-
if (shouldVanish && !previousCursor)
93+
if (shouldVanish && !cursorIsHidden)
9494
{
9595
try
9696
{
9797
const auto window = CoreWindow::GetForCurrentThread();
98-
99-
previousCursor = window.PointerCursor();
100-
if (!previousCursor)
101-
{
102-
return;
103-
}
104-
10598
window.PointerCursor(nullptr);
10699
window.SetPointerCapture();
100+
cursorIsHidden = true;
107101
}
108102
catch (...)
109103
{

src/cascadia/WindowsTerminal/AppHost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void AppHost::_WindowActivated(bool activated)
815815
{
816816
_windowLogic.WindowActivated(activated);
817817

818-
if (activated && _isWindowInitialized != WindowInitializedState::NotInitialized)
818+
if (activated)
819819
{
820820
QueryPerformanceCounter(&_lastActivatedTime);
821821
_virtualDesktopId = {};

src/cascadia/WindowsTerminal/WindowEmperor.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,8 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
413413
// It almost seems like there's a pattern here...
414414
(msg.wParam == VK_SPACE && msg.message == WM_SYSKEYDOWN))
415415
{
416-
if (const auto w = _mostRecentWindow())
417-
{
418-
const auto vkey = gsl::narrow_cast<uint32_t>(msg.wParam);
419-
const auto scanCode = gsl::narrow_cast<uint8_t>(msg.lParam >> 16);
420-
w->OnDirectKeyEvent(vkey, scanCode, keyDown);
421-
continue;
422-
}
416+
_dispatchSpecialKey(msg);
417+
continue;
423418
}
424419
}
425420

@@ -442,6 +437,36 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
442437
__assume(false);
443438
}
444439

440+
void WindowEmperor::_dispatchSpecialKey(MSG& msg) const
441+
{
442+
const auto hwnd = msg.hwnd;
443+
AppHost* window = nullptr;
444+
445+
for (const auto& h : _windows)
446+
{
447+
const auto w = h->GetWindow();
448+
if (w && w->GetHandle() == hwnd)
449+
{
450+
window = h.get();
451+
break;
452+
}
453+
}
454+
455+
if (!window)
456+
{
457+
window = _mostRecentWindow();
458+
if (!window)
459+
{
460+
return;
461+
}
462+
}
463+
464+
const auto vkey = gsl::narrow_cast<uint32_t>(msg.wParam);
465+
const auto scanCode = gsl::narrow_cast<uint8_t>(msg.lParam >> 16);
466+
const bool keyDown = msg.message & 1;
467+
window->OnDirectKeyEvent(vkey, scanCode, keyDown);
468+
}
469+
445470
void WindowEmperor::_dispatchCommandline(winrt::TerminalApp::CommandlineArgs args)
446471
{
447472
const auto exitCode = args.ExitCode();
@@ -826,14 +851,10 @@ LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM c
826851
case WM_QUERYENDSESSION:
827852
// For WM_QUERYENDSESSION and WM_ENDSESSION, refer to:
828853
// https://docs.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications
829-
if (lParam == ENDSESSION_CLOSEAPP)
830-
{
831-
// ENDSESSION_CLOSEAPP: The application is using a file that must be replaced,
832-
// the system is being serviced, or system resources are exhausted.
833-
RegisterApplicationRestart(nullptr, RESTART_NO_CRASH | RESTART_NO_HANG);
834-
return TRUE;
835-
}
836-
return FALSE;
854+
// ENDSESSION_CLOSEAPP: The application is using a file that must be replaced,
855+
// the system is being serviced, or system resources are exhausted.
856+
RegisterApplicationRestart(nullptr, RESTART_NO_CRASH | RESTART_NO_HANG);
857+
return TRUE;
837858
case WM_ENDSESSION:
838859
_forcePersistence = true;
839860
PostQuitMessage(0);

src/cascadia/WindowsTerminal/WindowEmperor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class WindowEmperor
5050
AppHost* _mostRecentWindow() const noexcept;
5151
bool _summonWindow(const SummonWindowSelectionArgs& args) const;
5252
void _summonAllWindows() const;
53+
void _dispatchSpecialKey(MSG& msg) const;
5354
void _dispatchCommandline(winrt::TerminalApp::CommandlineArgs args);
5455
safe_void_coroutine _dispatchCommandlineCurrentDesktop(winrt::TerminalApp::CommandlineArgs args);
5556
LRESULT _messageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam) noexcept;

0 commit comments

Comments
 (0)