diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index d0db9f6e61..820a53ef54 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -1236,7 +1236,7 @@ bool FancyZones::ShouldProcessSnapHotkey(DWORD vkCode) noexcept return false; } - if (layout->Type() != FancyZonesDataTypes::ZoneSetLayoutType::Blank) + if (layout->Zones().size() > 0) { if (vkCode == VK_UP || vkCode == VK_DOWN) { diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZonesDataTypes.h b/src/modules/fancyzones/FancyZonesLib/FancyZonesDataTypes.h index a2e4939e2e..1770f0f646 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZonesDataTypes.h +++ b/src/modules/fancyzones/FancyZonesLib/FancyZonesDataTypes.h @@ -16,7 +16,7 @@ namespace FancyZonesDataTypes { enum class ZoneSetLayoutType : int { - Blank = -1, + Blank, Focus, Columns, Rows, diff --git a/src/modules/fancyzones/FancyZonesLib/Layout.cpp b/src/modules/fancyzones/FancyZonesLib/Layout.cpp index 7fcc33c0b0..a9f7d476a8 100644 --- a/src/modules/fancyzones/FancyZonesLib/Layout.cpp +++ b/src/modules/fancyzones/FancyZonesLib/Layout.cpp @@ -108,15 +108,20 @@ Layout::Layout(const LayoutData& data) : bool Layout::Init(const FancyZonesUtils::Rect& workArea, HMONITOR monitor) noexcept { - //invalid work area + // invalid work area if (workArea.width() == 0 || workArea.height() == 0) { Logger::error(L"Layout initialization: invalid work area"); return false; } - //invalid zoneCount, may cause division by zero - if (m_data.zoneCount <= 0 && m_data.type != FancyZonesDataTypes::ZoneSetLayoutType::Custom) + // invalid zoneCount, may cause division by zero + bool isGridType = m_data.type == FancyZonesDataTypes::ZoneSetLayoutType::Columns + || m_data.type == FancyZonesDataTypes::ZoneSetLayoutType::Rows + || m_data.type == FancyZonesDataTypes::ZoneSetLayoutType::Grid + || m_data.type == FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid; + + if (m_data.zoneCount < 0 || (m_data.zoneCount == 0 && isGridType)) { Logger::error(L"Layout initialization: invalid zone count"); return false; @@ -126,6 +131,9 @@ bool Layout::Init(const FancyZonesUtils::Rect& workArea, HMONITOR monitor) noexc switch (m_data.type) { + case FancyZonesDataTypes::ZoneSetLayoutType::Blank: + m_zones = {}; + break; case FancyZonesDataTypes::ZoneSetLayoutType::Focus: m_zones = LayoutConfigurator::Focus(workArea, m_data.zoneCount); break; diff --git a/src/modules/fancyzones/FancyZonesLib/LayoutConfigurator.cpp b/src/modules/fancyzones/FancyZonesLib/LayoutConfigurator.cpp index 9585e358c9..4756fbd921 100644 --- a/src/modules/fancyzones/FancyZonesLib/LayoutConfigurator.cpp +++ b/src/modules/fancyzones/FancyZonesLib/LayoutConfigurator.cpp @@ -234,6 +234,11 @@ ZonesMap LayoutConfigurator::Focus(FancyZonesUtils::Rect workArea, int zoneCount ZonesMap LayoutConfigurator::Rows(FancyZonesUtils::Rect workArea, int zoneCount, int spacing) noexcept { + if (zoneCount == 0) + { + return {}; + } + ZonesMap zones; long totalWidth = workArea.width() - (spacing * 2); @@ -275,6 +280,11 @@ ZonesMap LayoutConfigurator::Rows(FancyZonesUtils::Rect workArea, int zoneCount, ZonesMap LayoutConfigurator::Columns(FancyZonesUtils::Rect workArea, int zoneCount, int spacing) noexcept { + if (zoneCount == 0) + { + return {}; + } + ZonesMap zones; long totalWidth = workArea.width() - (spacing * (zoneCount + 1)); @@ -316,6 +326,11 @@ ZonesMap LayoutConfigurator::Columns(FancyZonesUtils::Rect workArea, int zoneCou ZonesMap LayoutConfigurator::Grid(FancyZonesUtils::Rect workArea, int zoneCount, int spacing) noexcept { + if (zoneCount == 0) + { + return {}; + } + int rows = 1, columns = 1; while (zoneCount / rows >= rows) { diff --git a/src/modules/fancyzones/FancyZonesTests/UnitTests/JsonHelpers.Tests.cpp b/src/modules/fancyzones/FancyZonesTests/UnitTests/JsonHelpers.Tests.cpp index f644e04d1b..ebbdcd5df4 100644 --- a/src/modules/fancyzones/FancyZonesTests/UnitTests/JsonHelpers.Tests.cpp +++ b/src/modules/fancyzones/FancyZonesTests/UnitTests/JsonHelpers.Tests.cpp @@ -112,15 +112,15 @@ namespace FancyZonesUnitTests TEST_METHOD (ZoneSetLayoutTypeToString) { std::map expectedMap = { - std::make_pair(-2, L"TypeToString_ERROR"), - std::make_pair(-1, L"blank"), - std::make_pair(0, L"focus"), - std::make_pair(1, L"columns"), - std::make_pair(2, L"rows"), - std::make_pair(3, L"grid"), - std::make_pair(4, L"priority-grid"), - std::make_pair(5, L"custom"), - std::make_pair(6, L"TypeToString_ERROR"), + std::make_pair(-1, L"TypeToString_ERROR"), + std::make_pair(0, L"blank"), + std::make_pair(1, L"focus"), + std::make_pair(2, L"columns"), + std::make_pair(3, L"rows"), + std::make_pair(4, L"grid"), + std::make_pair(5, L"priority-grid"), + std::make_pair(6, L"custom"), + std::make_pair(7, L"TypeToString_ERROR"), }; for (const auto& expected : expectedMap) diff --git a/src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp b/src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp index 4fbd9c163a..fe3c262415 100644 --- a/src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp +++ b/src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp @@ -382,7 +382,7 @@ namespace FancyZonesUnitTests TEST_METHOD (ZeroZoneCount) { - for (int type = static_cast(ZoneSetLayoutType::Focus); type < static_cast(ZoneSetLayoutType::Custom); type++) + for (int type = static_cast(ZoneSetLayoutType::Columns); type < static_cast(ZoneSetLayoutType::Custom); type++) { LayoutData data = m_data; data.type = static_cast(type); @@ -395,6 +395,32 @@ namespace FancyZonesUnitTests Assert::IsFalse(result); } } + + { + LayoutData data = m_data; + data.type = static_cast(ZoneSetLayoutType::Blank); + data.zoneCount = 0; + auto layout = std::make_unique(data); + + for (const auto& rect : m_workAreaRects) + { + auto result = layout->Init(rect, Mocks::Monitor()); + Assert::IsTrue(result); + } + } + + { + LayoutData data = m_data; + data.type = static_cast(ZoneSetLayoutType::Focus); + data.zoneCount = 0; + auto layout = std::make_unique(data); + + for (const auto& rect : m_workAreaRects) + { + auto result = layout->Init(rect, Mocks::Monitor()); + Assert::IsTrue(result); + } + } } TEST_METHOD (BigZoneCount)