diff --git a/src/common/dpi_aware.cpp b/src/common/dpi_aware.cpp index 7b9366d40..4d0315a81 100644 --- a/src/common/dpi_aware.cpp +++ b/src/common/dpi_aware.cpp @@ -56,7 +56,7 @@ namespace DPIAware SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); } - AWARENESS_LEVEL GetAwarenessLevel(DPI_AWARENESS_CONTEXT system_returned_value) + AwarnessLevel GetAwarenessLevel(DPI_AWARENESS_CONTEXT system_returned_value) { const std::array levels{ DPI_AWARENESS_CONTEXT_UNAWARE, DPI_AWARENESS_CONTEXT_SYSTEM_AWARE, @@ -67,9 +67,9 @@ namespace DPIAware { if (AreDpiAwarenessContextsEqual(levels[i], system_returned_value)) { - return static_cast(i); + return static_cast(i); } } - return AWARENESS_LEVEL::UNAWARE; + return AwarnessLevel::UNAWARE; } } diff --git a/src/common/dpi_aware.h b/src/common/dpi_aware.h index bc8806f33..d750b2eec 100644 --- a/src/common/dpi_aware.h +++ b/src/common/dpi_aware.h @@ -10,7 +10,7 @@ namespace DPIAware void Convert(HMONITOR monitor_handle, int& width, int& height); void EnableDPIAwarenessForThisProcess(); - enum AWARENESS_LEVEL + enum AwarnessLevel { UNAWARE, SYSTEM_AWARE, @@ -18,5 +18,5 @@ namespace DPIAware PER_MONITOR_AWARE_V2, UNAWARE_GDISCALED }; - AWARENESS_LEVEL GetAwarenessLevel(DPI_AWARENESS_CONTEXT system_returned_value); + AwarnessLevel GetAwarenessLevel(DPI_AWARENESS_CONTEXT system_returned_value); }; diff --git a/src/modules/fancyzones/lib/Zone.cpp b/src/modules/fancyzones/lib/Zone.cpp index 6326bacbb..9cbd7fcfb 100644 --- a/src/modules/fancyzones/lib/Zone.cpp +++ b/src/modules/fancyzones/lib/Zone.cpp @@ -1,5 +1,7 @@ #include "pch.h" +#include +#include #include "Zone.h" #include "Settings.h" @@ -66,12 +68,17 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept ::GetWindowRect(window, &windowRect); RECT frameRect{}; - // Failure is expected on down level systems. + + const auto level = DPIAware::GetAwarenessLevel(GetWindowDpiAwarenessContext(window)); + const bool accountForUnawareness = level < DPIAware::PER_MONITOR_AWARE; if (SUCCEEDED(DwmGetWindowAttribute(window, DWMWA_EXTENDED_FRAME_BOUNDS, &frameRect, sizeof(frameRect)))) { - zoneRect.bottom -= (frameRect.bottom - windowRect.bottom); - zoneRect.right -= (frameRect.right - windowRect.right); - zoneRect.left -= (frameRect.left - windowRect.left); + const auto left_margin = frameRect.left - windowRect.left; + const auto right_margin = frameRect.right - windowRect.right; + const auto bottom_margin = frameRect.bottom - windowRect.bottom; + zoneRect.left -= left_margin; + zoneRect.right -= right_margin; + zoneRect.bottom -= bottom_margin; } // Map to screen coords @@ -80,7 +87,16 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept MONITORINFO mi{sizeof(mi)}; if (GetMonitorInfoW(MonitorFromWindow(zoneWindow, MONITOR_DEFAULTTONEAREST), &mi)) { - OffsetRect(&zoneRect, mi.rcMonitor.left - mi.rcWork.left, mi.rcMonitor.top - mi.rcWork.top); + const auto taskbar_left_size = std::abs(mi.rcMonitor.left - mi.rcWork.left); + const auto taskbar_top_size = std::abs(mi.rcMonitor.top - mi.rcWork.top); + OffsetRect(&zoneRect, -taskbar_left_size, -taskbar_top_size); + if (accountForUnawareness) + { + zoneRect.left = max(mi.rcMonitor.left, zoneRect.left); + zoneRect.right = min(mi.rcMonitor.right - taskbar_left_size, zoneRect.right); + zoneRect.top = max(mi.rcMonitor.top, zoneRect.top); + zoneRect.bottom = min(mi.rcMonitor.bottom - taskbar_top_size, zoneRect.bottom); + } } WINDOWPLACEMENT placement; @@ -106,4 +122,4 @@ void Zone::StampZone(HWND window, bool stamp) noexcept winrt::com_ptr MakeZone(RECT zoneRect) noexcept { return winrt::make_self(zoneRect); -} \ No newline at end of file +}