diff --git a/src/modules/fancyzones/lib/JsonHelpers.cpp b/src/modules/fancyzones/lib/JsonHelpers.cpp index 776a3b6140..5bd3d32554 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.cpp +++ b/src/modules/fancyzones/lib/JsonHelpers.cpp @@ -2,6 +2,7 @@ #include "JsonHelpers.h" #include "ZoneSet.h" #include "trace.h" +#include "Settings.h" #include @@ -464,10 +465,12 @@ namespace JSONHelpers data->processIdToHandleMap.erase(processId); } - // if there is another instance placed don't erase history + // if there is another instance of same application placed in the same zone don't erase history + size_t windowZoneStamp = reinterpret_cast(::GetProp(window, MULTI_ZONE_STAMP)); for (auto placedWindow : data->processIdToHandleMap) { - if (IsWindow(placedWindow.second)) + size_t placedWindowZoneStamp = reinterpret_cast(::GetProp(placedWindow.second, MULTI_ZONE_STAMP)); + if (IsWindow(placedWindow.second) && (windowZoneStamp == placedWindowZoneStamp)) { return false; } @@ -518,14 +521,7 @@ namespace JSONHelpers { if (data.deviceId == deviceId) { - for (auto placedWindow : data.processIdToHandleMap) - { - if (IsWindow(placedWindow.second) && processId != placedWindow.first) - { - return false; - } - } - // application already has history on this desktop, but zone (or zone layout) has changed + // application already has history on this work area, update it with new window position data.processIdToHandleMap[processId] = window; data.zoneSetUuid = zoneSetId; data.zoneIndexSet = zoneIndexSet; @@ -535,7 +531,7 @@ namespace JSONHelpers } } - std::map processIdToHandleMap{}; + std::unordered_map processIdToHandleMap{}; processIdToHandleMap[processId] = window; AppZoneHistoryData data{ .processIdToHandleMap = processIdToHandleMap, .zoneSetUuid = zoneSetId, diff --git a/src/modules/fancyzones/lib/JsonHelpers.h b/src/modules/fancyzones/lib/JsonHelpers.h index 57668db0e8..1b66ce3f26 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.h +++ b/src/modules/fancyzones/lib/JsonHelpers.h @@ -133,7 +133,7 @@ namespace JSONHelpers struct AppZoneHistoryData { - std::map processIdToHandleMap; // Maps process id(DWORD) of application to zoned window handle(HWND) + std::unordered_map processIdToHandleMap; // Maps process id(DWORD) of application to zoned window handle(HWND) std::wstring zoneSetUuid; std::wstring deviceId; diff --git a/src/modules/fancyzones/lib/WindowMoveHandler.cpp b/src/modules/fancyzones/lib/WindowMoveHandler.cpp index f0c2b928b2..f190c007c3 100644 --- a/src/modules/fancyzones/lib/WindowMoveHandler.cpp +++ b/src/modules/fancyzones/lib/WindowMoveHandler.cpp @@ -293,8 +293,6 @@ void WindowMoveHandlerPrivate::MoveSizeEnd(HWND window, POINT const& ptScreen, c } else { - ::RemoveProp(window, MULTI_ZONE_STAMP); - if (m_settings->GetSettings()->restoreSize) { if (WindowMoveHandlerUtils::IsCursorTypeIndicatingSizeEvent()) @@ -325,6 +323,7 @@ void WindowMoveHandlerPrivate::MoveSizeEnd(HWND window, POINT const& ptScreen, c } } } + ::RemoveProp(window, MULTI_ZONE_STAMP); } // Also, hide all windows (regardless of settings)