[FancyZones] Outlook new message restore placement bug (#2534)

This commit is contained in:
PrzemyslawTusinski
2020-05-27 16:52:59 +02:00
committed by GitHub
parent 3265549911
commit 3d619f1670
3 changed files with 131 additions and 17 deletions

View File

@@ -382,6 +382,51 @@ namespace JSONHelpers
SaveFancyZonesData();
}
bool FancyZonesData::IsAnotherWindowOfApplicationInstanceZoned(HWND window) const
{
std::scoped_lock lock{ dataLock };
auto processPath = get_process_path(window);
if (!processPath.empty())
{
auto history = appZoneHistoryMap.find(processPath);
if (history != appZoneHistoryMap.end())
{
DWORD processId = 0;
GetWindowThreadProcessId(window, &processId);
auto processIdIt = history->second.processIdToHandleMap.find(processId);
if (processIdIt == history->second.processIdToHandleMap.end())
{
return false;
}
else if (processIdIt->second != window && IsWindow(processIdIt->second))
{
return true;
}
}
}
return false;
}
void FancyZonesData::UpdateProcessIdToHandleMap(HWND window)
{
std::scoped_lock lock{ dataLock };
auto processPath = get_process_path(window);
if (!processPath.empty())
{
auto history = appZoneHistoryMap.find(processPath);
if (history != appZoneHistoryMap.end())
{
DWORD processId = 0;
GetWindowThreadProcessId(window, &processId);
history->second.processIdToHandleMap[processId] = window;
}
}
}
std::vector<int> FancyZonesData::GetAppLastZoneIndexSet(HWND window, const std::wstring_view& deviceId, const std::wstring_view& zoneSetId) const
{
std::scoped_lock lock{ dataLock };
@@ -411,9 +456,26 @@ namespace JSONHelpers
auto history = appZoneHistoryMap.find(processPath);
if (history != appZoneHistoryMap.end())
{
const auto& data = history->second;
auto& data = history->second;
if (data.zoneSetUuid == zoneSetId && data.deviceId == deviceId)
{
if (!IsAnotherWindowOfApplicationInstanceZoned(window))
{
DWORD processId = 0;
GetWindowThreadProcessId(window, &processId);
data.processIdToHandleMap.erase(processId);
}
// if there is another instance placed don't erase history
for (auto placedWindow : data.processIdToHandleMap)
{
if (IsWindow(placedWindow.second))
{
return false;
}
}
appZoneHistoryMap.erase(processPath);
SaveFancyZonesData();
return true;
@@ -427,13 +489,39 @@ namespace JSONHelpers
bool FancyZonesData::SetAppLastZones(HWND window, const std::wstring& deviceId, const std::wstring& zoneSetId, const std::vector<int>& zoneIndexSet)
{
std::scoped_lock lock{ dataLock };
if (IsAnotherWindowOfApplicationInstanceZoned(window))
{
return false;
}
auto processPath = get_process_path(window);
if (processPath.empty())
{
return false;
}
appZoneHistoryMap[processPath] = AppZoneHistoryData{ .zoneSetUuid = zoneSetId, .deviceId = deviceId, .zoneIndexSet = zoneIndexSet };
DWORD processId = 0;
GetWindowThreadProcessId(window, &processId);
auto history = appZoneHistoryMap.find(processPath);
if (history != appZoneHistoryMap.end())
{
auto& data = history->second;
for (auto placedWindow : data.processIdToHandleMap)
{
if (IsWindow(placedWindow.second) && processId != placedWindow.first)
{
return false;
}
}
}
auto windowMap = appZoneHistoryMap[processPath].processIdToHandleMap;
windowMap[processId] = window;
appZoneHistoryMap[processPath] = AppZoneHistoryData{ .processIdToHandleMap = windowMap, .zoneSetUuid = zoneSetId, .deviceId = deviceId, .zoneIndexSet = zoneIndexSet };
SaveFancyZonesData();
return true;
}
@@ -735,18 +823,19 @@ namespace JSONHelpers
switch (zoneSetData.type)
{
case CustomLayoutType::Grid: {
case CustomLayoutType::Grid:
{
int j = 5;
GridLayoutInfo zoneSetInfo(GridLayoutInfo::Minimal{ .rows = data[j++], .columns = data[j++] });
for (int row = 0; row < zoneSetInfo.rows(); row++, j+=2)
for (int row = 0; row < zoneSetInfo.rows(); row++, j += 2)
{
zoneSetInfo.rowsPercents()[row] = data[j] * 256 + data[j+1];
zoneSetInfo.rowsPercents()[row] = data[j] * 256 + data[j + 1];
}
for (int col = 0; col < zoneSetInfo.columns(); col++, j+=2)
for (int col = 0; col < zoneSetInfo.columns(); col++, j += 2)
{
zoneSetInfo.columnsPercents()[col] = data[j] * 256 + data[j+1];
zoneSetInfo.columnsPercents()[col] = data[j] * 256 + data[j + 1];
}
for (int row = 0; row < zoneSetInfo.rows(); row++)
@@ -759,7 +848,8 @@ namespace JSONHelpers
zoneSetData.info = zoneSetInfo;
break;
}
case CustomLayoutType::Canvas: {
case CustomLayoutType::Canvas:
{
CanvasLayoutInfo info;
int j = 5;
@@ -1071,7 +1161,8 @@ namespace JSONHelpers
result.SetNamedValue(L"name", json::value(customZoneSet.data.name));
switch (customZoneSet.data.type)
{
case CustomLayoutType::Canvas: {
case CustomLayoutType::Canvas:
{
result.SetNamedValue(L"type", json::value(L"canvas"));
CanvasLayoutInfo info = std::get<CanvasLayoutInfo>(customZoneSet.data.info);
@@ -1079,7 +1170,8 @@ namespace JSONHelpers
break;
}
case CustomLayoutType::Grid: {
case CustomLayoutType::Grid:
{
result.SetNamedValue(L"type", json::value(L"grid"));
GridLayoutInfo gridInfo = std::get<GridLayoutInfo>(customZoneSet.data.info);
@@ -1103,7 +1195,7 @@ namespace JSONHelpers
{
return std::nullopt;
}
result.data.name = customZoneSet.GetNamedString(L"name");
json::JsonObject infoJson = customZoneSet.GetNamedObject(L"info");