fancyzones: restrict dpi unaware windows horizontally to the current display to avoid unwanted resize
This commit is contained in:
parent
0fd0a8b7cc
commit
48b89609e2
|
@ -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<AWARENESS_LEVEL>(i);
|
||||
return static_cast<AwarnessLevel>(i);
|
||||
}
|
||||
}
|
||||
return AWARENESS_LEVEL::UNAWARE;
|
||||
return AwarnessLevel::UNAWARE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include <common/dpi_aware.h>
|
||||
#include <common/monitors.h>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue