Skip to content

Commit

Permalink
[FancyZones] Align zone numbers between Editor and FancyZonesLib (#7387)
Browse files Browse the repository at this point in the history
* Align zone numbers between Editor and FancyZonesLib
Use zoneId on win+arrow

* Update tests

* Fix crash

* ZoneId starts from 0

* Define ZonesMap type

IFACEMETHOD_ macro is having trouble processing
std::map template when expanding, so return type needs
to be predefined

* Address PR comment

* Address more PR comments

* Handle .at
  • Loading branch information
stefansjfw committed Oct 26, 2020
1 parent 8ef91a5 commit e6a5b58
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ private void UpdateLayoutModels()
_gridModel.ColumnPercents.Add(((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols));
}

int index = ZoneCount - 1;
for (int col = cols - 1; col >= 0; col--)
int index = 0;
for (int row = 0; row < rows; row++)
{
for (int row = rows - 1; row >= 0; row--)
for (int col = 0; col < cols; col++)
{
_gridModel.CellChildMap[row, col] = index--;
if (index < 0)
_gridModel.CellChildMap[row, col] = index++;
if (index == ZoneCount)
{
index = 0;
index--;
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/modules/fancyzones/lib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,9 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
auto zoneSet = workArea->ActiveZoneSet();
if (zoneSet)
{
auto zones = zoneSet->GetZones();
for (size_t i = 0; i < zones.size(); i++)
const auto zones = zoneSet->GetZones();
for (const auto& [zoneId, zone] : zones)
{
const auto& zone = zones[i];
RECT zoneRect = zone->GetZoneRect();

zoneRect.left += monitorRect.left;
Expand All @@ -1195,7 +1194,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
zoneRect.bottom += monitorRect.top;

zoneRects.emplace_back(zoneRect);
zoneRectsInfo.emplace_back(i, workArea);
zoneRectsInfo.emplace_back(zoneId, workArea);
}
}
}
Expand Down Expand Up @@ -1228,10 +1227,9 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
auto zoneSet = workArea->ActiveZoneSet();
if (zoneSet)
{
auto zones = zoneSet->GetZones();
for (size_t i = 0; i < zones.size(); i++)
const auto zones = zoneSet->GetZones();
for (const auto& [zoneId, zone] : zones)
{
const auto& zone = zones[i];
RECT zoneRect = zone->GetZoneRect();

zoneRect.left += currentMonitorRect.left;
Expand All @@ -1240,7 +1238,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
zoneRect.bottom += currentMonitorRect.top;

zoneRects.emplace_back(zoneRect);
zoneRectsInfo.emplace_back(i, workArea);
zoneRectsInfo.emplace_back(zoneId, workArea);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/lib/Zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ RECT Zone::ComputeActualZoneRect(HWND window, HWND zoneWindow) const noexcept

winrt::com_ptr<IZone> MakeZone(const RECT& zoneRect, const size_t zoneId) noexcept
{
if (ValidateZoneRect(zoneRect) && zoneId > 0)
if (ValidateZoneRect(zoneRect) && zoneId >= 0)
{
return winrt::make_self<Zone>(zoneRect, zoneId);
}
Expand Down

0 comments on commit e6a5b58

Please sign in to comment.