mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[FancyZones] Feature to create zone layouts spanning multiple monitors (#5289)
* Added the setting * Added a property to Editor Settings This will be used later * Fixed a bug in the previous commit * Simplified a method * Added snapping points to the editor * Simplified a method in ZoneSet * Updated ZoneSet testcases * Add a method to FancyZones / ZoneWindowHost * Almost works * The editor now launches, but FZ does not understand the results * Refactored some code * Snapping to a zone by dragging seems to work * Hotkeys seem to work * Refresh the work area handler after changing settings * Fixed zones not snapping to monitor edges when moved * Remove unused method in FancyZones.h * Fixed an issue with DPI awareness * Renamed setting to spanZonesAcrossMonitors * Renamed a function * Fixed a bug with the magnetic effect * Fix restoring window positions on layout changes
This commit is contained in:
@@ -116,6 +116,55 @@ inline BYTE OpacitySettingToAlpha(int opacity)
|
||||
return static_cast<BYTE>(opacity * 2.55);
|
||||
}
|
||||
|
||||
template<RECT MONITORINFO::*member>
|
||||
std::vector<std::pair<HMONITOR, RECT>> GetAllMonitorRects()
|
||||
{
|
||||
using result_t = std::vector<std::pair<HMONITOR, RECT>>;
|
||||
result_t result;
|
||||
|
||||
auto enumMonitors = [](HMONITOR monitor, HDC hdc, LPRECT pRect, LPARAM param) -> BOOL
|
||||
{
|
||||
MONITORINFOEX mi;
|
||||
mi.cbSize = sizeof(mi);
|
||||
result_t& result = *reinterpret_cast<result_t*>(param);
|
||||
if (GetMonitorInfo(monitor, &mi))
|
||||
{
|
||||
result.push_back({ monitor, mi.*member });
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
EnumDisplayMonitors(NULL, NULL, enumMonitors, reinterpret_cast<LPARAM>(&result));
|
||||
return result;
|
||||
}
|
||||
|
||||
template<RECT MONITORINFO::*member>
|
||||
RECT GetAllMonitorsCombinedRect()
|
||||
{
|
||||
auto allMonitors = GetAllMonitorRects<member>();
|
||||
bool empty = true;
|
||||
RECT result{ 0, 0, 0, 0 };
|
||||
|
||||
for (auto& [monitor, rect] : allMonitors)
|
||||
{
|
||||
if (empty)
|
||||
{
|
||||
empty = false;
|
||||
result = rect;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.left = min(result.left, rect.left);
|
||||
result.top = min(result.top, rect.top);
|
||||
result.right = max(result.right, rect.right);
|
||||
result.bottom = max(result.bottom, rect.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UINT GetDpiForMonitor(HMONITOR monitor) noexcept;
|
||||
void OrderMonitors(std::vector<std::pair<HMONITOR, RECT>>& monitorInfo);
|
||||
void SizeWindowToRect(HWND window, RECT rect) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user