Only move the window to the current desktop when it isn't on that one already (#10025)

## Summary of the Pull Request

This is to mitigate MSFT:33035972. If you call `MoveWindowToDesktop` while an app is set to "Show windows from this app on all desktops", the OS will clear that "Show windows from this app on all desktops" state. But it _won't_ clear that state from the task view, so it'll just plain look broken.

We can mitigate this just by checking if we're already on the current desktop first. "Show windows from this app on all desktops" windows will _always_ be on every desktop, so that API will return true, and we can avoid tearing the state.

## References
* added in #9954 

## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-60325102
* [x] I work here
* [ ] Tests aren't possible
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* it works again
This commit is contained in:
Mike Griese 2021-05-04 16:20:01 -05:00 committed by GitHub
parent 31414aa364
commit 7d71b4b9ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -781,13 +781,28 @@ void AppHost::_HandleSummon(const winrt::Windows::Foundation::IInspectable& /*se
{
if (_LazyLoadDesktopManager())
{
GUID currentlyActiveDesktop{ 0 };
if (VirtualDesktopUtils::GetCurrentVirtualDesktopId(&currentlyActiveDesktop))
// First thing - make sure that we're not on the current desktop. If
// we are, then don't call MoveWindowToDesktop. This is to mitigate
// MSFT:33035972
BOOL onCurrentDesktop{ false };
if (SUCCEEDED(_desktopManager->IsWindowOnCurrentVirtualDesktop(_window->GetHandle(), &onCurrentDesktop)) && onCurrentDesktop)
{
LOG_IF_FAILED(_desktopManager->MoveWindowToDesktop(_window->GetHandle(), currentlyActiveDesktop));
// If we succeeded, and the window was on the current desktop, then do nothing.
}
else
{
// Here, we either failed to check if the window is on the
// current desktop, or it wasn't on that desktop. In both those
// cases, just move the window.
GUID currentlyActiveDesktop{ 0 };
if (VirtualDesktopUtils::GetCurrentVirtualDesktopId(&currentlyActiveDesktop))
{
LOG_IF_FAILED(_desktopManager->MoveWindowToDesktop(_window->GetHandle(), currentlyActiveDesktop));
}
// If GetCurrentVirtualDesktopId failed, then just leave the window
// where it is. Nothing else to be done :/
}
// If GetCurrentVirtualDesktopId failed, then just leave the window
// where it is. Nothing else to be done :/
}
}
}
@ -802,7 +817,6 @@ void AppHost::_HandleSummon(const winrt::Windows::Foundation::IInspectable& /*se
GUID AppHost::_CurrentDesktopGuid()
{
GUID currentDesktopGuid{ 0 };
const auto manager = winrt::create_instance<IVirtualDesktopManager>(__uuidof(VirtualDesktopManager));
if (_LazyLoadDesktopManager())
{
LOG_IF_FAILED(_desktopManager->GetWindowDesktopId(_window->GetHandle(), &currentDesktopGuid));