[FancyZones] Update app zone history on window removal (#4696)

* Update app zone history on every new window assignment to zone

* Compare window positions with already placed windows

* Remove window property only after processing window removal from zone
This commit is contained in:
vldmr11080 2020-07-08 16:59:36 +02:00 committed by GitHub
parent 106c316442
commit ac5a3e7a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 14 deletions

View File

@ -2,6 +2,7 @@
#include "JsonHelpers.h"
#include "ZoneSet.h"
#include "trace.h"
#include "Settings.h"
#include <common/common.h>
@ -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<size_t>(::GetProp(window, MULTI_ZONE_STAMP));
for (auto placedWindow : data->processIdToHandleMap)
{
if (IsWindow(placedWindow.second))
size_t placedWindowZoneStamp = reinterpret_cast<size_t>(::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<DWORD, HWND> processIdToHandleMap{};
std::unordered_map<DWORD, HWND> processIdToHandleMap{};
processIdToHandleMap[processId] = window;
AppZoneHistoryData data{ .processIdToHandleMap = processIdToHandleMap,
.zoneSetUuid = zoneSetId,

View File

@ -133,7 +133,7 @@ namespace JSONHelpers
struct AppZoneHistoryData
{
std::map<DWORD, HWND> processIdToHandleMap; // Maps process id(DWORD) of application to zoned window handle(HWND)
std::unordered_map<DWORD, HWND> processIdToHandleMap; // Maps process id(DWORD) of application to zoned window handle(HWND)
std::wstring zoneSetUuid;
std::wstring deviceId;

View File

@ -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)