Skip to content

Commit 5ae95d7

Browse files
authored
Allow creating new windows on another virtual desktop (#19458)
Whoops. Closes #18652 <DHowett> I chatted with Leonard to figure out why I kept misunderstanding this PR. The key is that **this function should not always return an existing window.** It's supposed to find an existing window on the current virtual desktop, not literally any window anywhere.
1 parent b357de9 commit 5ae95d7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/cascadia/WindowsTerminal/WindowEmperor.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ void WindowEmperor::_dispatchCommandlineCommon(winrt::array_view<const winrt::hs
670670
// This is an implementation-detail of _dispatchCommandline().
671671
safe_void_coroutine WindowEmperor::_dispatchCommandlineCurrentDesktop(winrt::TerminalApp::CommandlineArgs args)
672672
{
673-
std::weak_ptr<AppHost> mostRecentWeak;
673+
std::shared_ptr<AppHost> mostRecent;
674+
AppHost* window = nullptr;
674675

675676
if (winrt::guid currentDesktop; VirtualDesktopUtils::GetCurrentVirtualDesktopId(reinterpret_cast<GUID*>(&currentDesktop)))
676677
{
@@ -682,19 +683,18 @@ safe_void_coroutine WindowEmperor::_dispatchCommandlineCurrentDesktop(winrt::Ter
682683
if (desktopId == currentDesktop && lastActivatedTime > max)
683684
{
684685
max = lastActivatedTime;
685-
mostRecentWeak = w;
686+
mostRecent = w;
686687
}
687688
}
688-
}
689-
690-
// GetVirtualDesktopId(), as current implemented, should always return on the main thread.
691-
_assertIsMainThread();
692689

693-
const auto mostRecent = mostRecentWeak.lock();
694-
auto window = mostRecent.get();
695-
696-
if (!window)
690+
// GetVirtualDesktopId(), as current implemented, should always return on the main thread.
691+
_assertIsMainThread();
692+
window = mostRecent.get();
693+
}
694+
else
697695
{
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.
698698
window = _mostRecentWindow();
699699
}
700700

0 commit comments

Comments
 (0)