Compare window desktop id with currently active work area desktop id. (#2110)

* Compare window desktop id with currently active work area desktop id.

* Improve error handling and conform to coding guidelines.

* Move virtual desktop helper functions to ZoneWindowUtils namespace.

* Ensure thread safety when creating instance of VirtualDesktopManager.

* Remove static qualifier from ServiceProvider.

* Return instead of break, as there is no need to check for other monitors, virtual desktop is the same for all.

* Move virtual desktop related helper functions to separate files.

* Skip comparing desktop ids if zone window has empty GUID for desktop id.

* Add comment describion scenario for which we need this fix.
This commit is contained in:
vldmr11080
2020-04-21 19:57:21 +02:00
committed by GitHub
parent b5dfe6320d
commit 5ac7eddd03
6 changed files with 80 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
#include "lib/JsonHelpers.h"
#include "lib/ZoneSet.h"
#include "trace.h"
#include "VirtualDesktopUtils.h"
#include <functional>
#include <common/common.h>
@@ -349,17 +350,28 @@ FancyZones::VirtualDesktopInitialize() noexcept
IFACEMETHODIMP_(void)
FancyZones::WindowCreated(HWND window) noexcept
{
std::shared_lock readLock(m_lock);
if (m_settings->GetSettings()->appLastZone_moveWindows && IsInterestingWindow(window))
{
for (const auto& [monitor, zoneWindow] : m_zoneWindowMap)
{
// WindowCreated is also invoked when a virtual desktop switch occurs, we need a way
// to figure out when that happens to avoid moving windows that should not be moved.
GUID windowDesktopId{};
GUID zoneWindowDesktopId{};
if (VirtualDesktopUtils::GetWindowDesktopId(window, &windowDesktopId) &&
VirtualDesktopUtils::GetZoneWindowDesktopId(zoneWindow.get(), &zoneWindowDesktopId) &&
(windowDesktopId != zoneWindowDesktopId))
{
return;
}
const auto activeZoneSet = zoneWindow->ActiveZoneSet();
if (activeZoneSet)
{
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
wil::unique_cotaskmem_string guidString;
if (SUCCEEDED_LOG(StringFromCLSID(activeZoneSet->Id(), &guidString)))
if (SUCCEEDED(StringFromCLSID(activeZoneSet->Id(), &guidString)))
{
int zoneIndex = fancyZonesData.GetAppLastZoneIndex(window, zoneWindow->UniqueId(), guidString.get());
if (zoneIndex != -1)