diff --git a/src/common/monitors.cpp b/src/common/monitors.cpp index e3b4f766d81d..c96a78c86e4a 100644 --- a/src/common/monitors.cpp +++ b/src/common/monitors.cpp @@ -38,6 +38,11 @@ std::vector MonitorInfo::GetMonitors(bool include_toolbar) return monitors; } +int MonitorInfo::GetMonitorsCount() +{ + return GetMonitors(true).size(); +} + static BOOL CALLBACK get_primary_display_enum_cb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) { MONITORINFOEX monitor_info; diff --git a/src/common/monitors.h b/src/common/monitors.h index 616656e737d5..ebe77fabd2c5 100644 --- a/src/common/monitors.h +++ b/src/common/monitors.h @@ -32,6 +32,7 @@ struct MonitorInfo : ScreenSize // Returns monitor rects ordered from left to right static std::vector GetMonitors(bool include_toolbar); + static int GetMonitorsCount(); // Return primary display static MonitorInfo GetPrimaryMonitor(); // Return monitor on which hwnd window is displayed diff --git a/src/modules/fancyzones/lib/Zone.cpp b/src/modules/fancyzones/lib/Zone.cpp index 6b3347f390e7..4e9305f03462 100644 --- a/src/modules/fancyzones/lib/Zone.cpp +++ b/src/modules/fancyzones/lib/Zone.cpp @@ -5,6 +5,8 @@ #include "Zone.h" #include "Settings.h" +#include "common/monitors.h" + struct Zone : winrt::implements { public: @@ -77,14 +79,15 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept 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)))) { - const auto left_margin = frameRect.left - windowRect.left; - const auto right_margin = frameRect.right - windowRect.right; - const auto bottom_margin = frameRect.bottom - windowRect.bottom; - newWindowRect.left -= left_margin; - newWindowRect.right -= right_margin; - newWindowRect.bottom -= bottom_margin; + LONG leftMargin = frameRect.left - windowRect.left; + LONG rightMargin = frameRect.right - windowRect.right; + LONG bottomMargin = frameRect.bottom - windowRect.bottom; + newWindowRect.left -= leftMargin; + newWindowRect.right -= rightMargin; + newWindowRect.bottom -= bottomMargin; } // Map to screen coords @@ -96,7 +99,8 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept 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(&newWindowRect, -taskbar_left_size, -taskbar_top_size); - if (accountForUnawareness) + + if (accountForUnawareness && MonitorInfo::GetMonitorsCount() > 1) { newWindowRect.left = max(mi.rcMonitor.left, newWindowRect.left); newWindowRect.right = min(mi.rcMonitor.right - taskbar_left_size, newWindowRect.right);