@@ -194,6 +194,22 @@ static wil::unique_mutex acquireMutexOrAttemptHandoff(const wchar_t* className,
194194 return {};
195195}
196196
197+ static constexpr bool IsInputKey (WORD vkey) noexcept
198+ {
199+ return vkey != VK_CONTROL &&
200+ vkey != VK_LCONTROL &&
201+ vkey != VK_RCONTROL &&
202+ vkey != VK_MENU &&
203+ vkey != VK_LMENU &&
204+ vkey != VK_RMENU &&
205+ vkey != VK_SHIFT &&
206+ vkey != VK_LSHIFT &&
207+ vkey != VK_RSHIFT &&
208+ vkey != VK_LWIN &&
209+ vkey != VK_RWIN &&
210+ vkey != VK_SNAPSHOT;
211+ }
212+
197213HWND WindowEmperor::GetMainWindow () const noexcept
198214{
199215 _assertIsMainThread ();
@@ -486,7 +502,13 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
486502
487503 if (msg.message == WM_KEYDOWN)
488504 {
489- IslandWindow::HideCursor ();
505+ const auto vkey = static_cast <WORD>(msg.wParam );
506+
507+ // Hide the cursor only when the key pressed is an input key (ignore modifier keys).
508+ if (IsInputKey (vkey))
509+ {
510+ IslandWindow::HideCursor ();
511+ }
490512 }
491513 }
492514
@@ -648,7 +670,8 @@ void WindowEmperor::_dispatchCommandlineCommon(winrt::array_view<const winrt::hs
648670// This is an implementation-detail of _dispatchCommandline().
649671safe_void_coroutine WindowEmperor::_dispatchCommandlineCurrentDesktop (winrt::TerminalApp::CommandlineArgs args)
650672{
651- std::weak_ptr<AppHost> mostRecentWeak;
673+ std::shared_ptr<AppHost> mostRecent;
674+ AppHost* window = nullptr ;
652675
653676 if (winrt::guid currentDesktop; VirtualDesktopUtils::GetCurrentVirtualDesktopId (reinterpret_cast <GUID*>(¤tDesktop)))
654677 {
@@ -660,19 +683,18 @@ safe_void_coroutine WindowEmperor::_dispatchCommandlineCurrentDesktop(winrt::Ter
660683 if (desktopId == currentDesktop && lastActivatedTime > max)
661684 {
662685 max = lastActivatedTime;
663- mostRecentWeak = w;
686+ mostRecent = w;
664687 }
665688 }
666- }
667-
668- // GetVirtualDesktopId(), as current implemented, should always return on the main thread.
669- _assertIsMainThread ();
670-
671- const auto mostRecent = mostRecentWeak.lock ();
672- auto window = mostRecent.get ();
673689
674- if (!window)
690+ // GetVirtualDesktopId(), as current implemented, should always return on the main thread.
691+ _assertIsMainThread ();
692+ window = mostRecent.get ();
693+ }
694+ else
675695 {
696+ // If virtual desktops have never been used, and in turn Explorer never set them up,
697+ // GetCurrentVirtualDesktopId will return false. In this case just use the current (only) desktop.
676698 window = _mostRecentWindow ();
677699 }
678700
0 commit comments