Skip to content

Commit 62fca92

Browse files
Move registry margin adjustment to root Layout::Init method for better performance and code organization
Co-authored-by: yeelam-gordon <73506701+yeelam-gordon@users.noreply.github.com>
1 parent 4ddaf99 commit 62fca92

2 files changed

Lines changed: 26 additions & 31 deletions

File tree

src/modules/fancyzones/FancyZonesLib/Layout.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99

1010
#include <common/logger/logger.h>
1111

12+
namespace
13+
{
14+
int AdjustSpacingForRegistry(int originalSpacing)
15+
{
16+
// Check Windows DWM ColorPrevalence setting
17+
// When ColorPrevalence = 0 (accent color not shown), subtract 1 from spacing
18+
HKEY hKey;
19+
DWORD dwValue = 1; // Default to 1 (accent color shown)
20+
DWORD dwSize = sizeof(DWORD);
21+
22+
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
23+
{
24+
RegQueryValueExW(hKey, L"ColorPrevalence", nullptr, nullptr, reinterpret_cast<LPBYTE>(&dwValue), &dwSize);
25+
RegCloseKey(hKey);
26+
}
27+
28+
// Apply -1 margin when ColorPrevalence = 0 (accent color not shown)
29+
if (dwValue == 0)
30+
{
31+
return originalSpacing - 1;
32+
}
33+
return originalSpacing;
34+
}
35+
}
36+
1237
namespace ZoneSelectionAlgorithms
1338
{
1439
constexpr int OVERLAPPING_CENTERS_SENSITIVITY = 75;
@@ -128,6 +153,7 @@ bool Layout::Init(const FancyZonesUtils::Rect& workArea, HMONITOR monitor) noexc
128153
}
129154

130155
auto spacing = m_data.showSpacing ? m_data.spacing : 0;
156+
spacing = AdjustSpacingForRegistry(spacing);
131157

132158
switch (m_data.type)
133159
{

src/modules/fancyzones/FancyZonesLib/LayoutConfigurator.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,8 @@ bool AddZone(Zone zone, ZonesMap& zones) noexcept
104104
return true;
105105
}
106106

107-
int AdjustSpacingForRegistry(int originalSpacing)
108-
{
109-
// Check Windows DWM ColorPrevalence setting
110-
// When ColorPrevalence = 0 (accent color not shown), subtract 1 from spacing
111-
HKEY hKey;
112-
DWORD dwValue = 1; // Default to 1 (accent color shown)
113-
DWORD dwSize = sizeof(DWORD);
114-
115-
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
116-
{
117-
RegQueryValueExW(hKey, L"ColorPrevalence", nullptr, nullptr, reinterpret_cast<LPBYTE>(&dwValue), &dwSize);
118-
RegCloseKey(hKey);
119-
}
120-
121-
// Apply -1 margin when ColorPrevalence = 0 (accent color not shown)
122-
if (dwValue == 0)
123-
{
124-
return originalSpacing - 1;
125-
}
126-
return originalSpacing;
127-
}
128-
129107
ZonesMap CalculateGridZones(FancyZonesUtils::Rect workArea, FancyZonesDataTypes::GridLayoutInfo gridLayoutInfo, int spacing)
130108
{
131-
spacing = AdjustSpacingForRegistry(spacing);
132109
ZonesMap zones;
133110

134111
long totalWidth = workArea.width();
@@ -262,7 +239,6 @@ ZonesMap LayoutConfigurator::Rows(FancyZonesUtils::Rect workArea, int zoneCount,
262239
return {};
263240
}
264241

265-
spacing = AdjustSpacingForRegistry(spacing);
266242
ZonesMap zones;
267243

268244
long totalWidth = workArea.width() - (spacing * 2);
@@ -309,7 +285,6 @@ ZonesMap LayoutConfigurator::Columns(FancyZonesUtils::Rect workArea, int zoneCou
309285
return {};
310286
}
311287

312-
spacing = AdjustSpacingForRegistry(spacing);
313288
ZonesMap zones;
314289

315290
long totalWidth = workArea.width() - (spacing * (zoneCount + 1));
@@ -356,8 +331,6 @@ ZonesMap LayoutConfigurator::Grid(FancyZonesUtils::Rect workArea, int zoneCount,
356331
return {};
357332
}
358333

359-
spacing = AdjustSpacingForRegistry(spacing);
360-
361334
int rows = 1, columns = 1;
362335
while (zoneCount / rows >= rows)
363336
{
@@ -415,8 +388,6 @@ ZonesMap LayoutConfigurator::PriorityGrid(FancyZonesUtils::Rect workArea, int zo
415388
return {};
416389
}
417390

418-
spacing = AdjustSpacingForRegistry(spacing);
419-
420391
constexpr int predefinedLayoutsCount = sizeof(predefinedPriorityGridLayouts) / sizeof(FancyZonesDataTypes::GridLayoutInfo);
421392
if (zoneCount < predefinedLayoutsCount)
422393
{
@@ -428,8 +399,6 @@ ZonesMap LayoutConfigurator::PriorityGrid(FancyZonesUtils::Rect workArea, int zo
428399

429400
ZonesMap LayoutConfigurator::Custom(FancyZonesUtils::Rect workArea, HMONITOR monitor, const FancyZonesDataTypes::CustomLayoutData& zoneSet, int spacing) noexcept
430401
{
431-
spacing = AdjustSpacingForRegistry(spacing);
432-
433402
if (zoneSet.type == FancyZonesDataTypes::CustomLayoutType::Canvas && std::holds_alternative<FancyZonesDataTypes::CanvasLayoutInfo>(zoneSet.info))
434403
{
435404
ZonesMap zones;

0 commit comments

Comments
 (0)