mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-11 12:14:53 +08:00
Dpi unaware placement bug (#2121)
Fix for bug when placing dpi unaware window such as Notepad++ in left of right part of monitor. In that application gap of about 7px was left or right. This fixes only single-monitor scenario It skips correction for dpi unaware window that leaves a gap
This commit is contained in:
parent
87fb6fc3d1
commit
2077cd4864
@ -38,6 +38,11 @@ std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool include_toolbar)
|
|||||||
return monitors;
|
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)
|
static BOOL CALLBACK get_primary_display_enum_cb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
|
||||||
{
|
{
|
||||||
MONITORINFOEX monitor_info;
|
MONITORINFOEX monitor_info;
|
||||||
|
@ -32,6 +32,7 @@ struct MonitorInfo : ScreenSize
|
|||||||
|
|
||||||
// Returns monitor rects ordered from left to right
|
// Returns monitor rects ordered from left to right
|
||||||
static std::vector<MonitorInfo> GetMonitors(bool include_toolbar);
|
static std::vector<MonitorInfo> GetMonitors(bool include_toolbar);
|
||||||
|
static int GetMonitorsCount();
|
||||||
// Return primary display
|
// Return primary display
|
||||||
static MonitorInfo GetPrimaryMonitor();
|
static MonitorInfo GetPrimaryMonitor();
|
||||||
// Return monitor on which hwnd window is displayed
|
// Return monitor on which hwnd window is displayed
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#include "common/monitors.h"
|
||||||
|
|
||||||
struct Zone : winrt::implements<Zone, IZone>
|
struct Zone : winrt::implements<Zone, IZone>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -78,14 +80,15 @@ RECT Zone::ComputeActualZoneRect(HWND window, HWND zoneWindow) noexcept
|
|||||||
|
|
||||||
const auto level = DPIAware::GetAwarenessLevel(GetWindowDpiAwarenessContext(window));
|
const auto level = DPIAware::GetAwarenessLevel(GetWindowDpiAwarenessContext(window));
|
||||||
const bool accountForUnawareness = level < DPIAware::PER_MONITOR_AWARE;
|
const bool accountForUnawareness = level < DPIAware::PER_MONITOR_AWARE;
|
||||||
|
|
||||||
if (SUCCEEDED(DwmGetWindowAttribute(window, DWMWA_EXTENDED_FRAME_BOUNDS, &frameRect, sizeof(frameRect))))
|
if (SUCCEEDED(DwmGetWindowAttribute(window, DWMWA_EXTENDED_FRAME_BOUNDS, &frameRect, sizeof(frameRect))))
|
||||||
{
|
{
|
||||||
const auto left_margin = frameRect.left - windowRect.left;
|
LONG leftMargin = frameRect.left - windowRect.left;
|
||||||
const auto right_margin = frameRect.right - windowRect.right;
|
LONG rightMargin = frameRect.right - windowRect.right;
|
||||||
const auto bottom_margin = frameRect.bottom - windowRect.bottom;
|
LONG bottomMargin = frameRect.bottom - windowRect.bottom;
|
||||||
newWindowRect.left -= left_margin;
|
newWindowRect.left -= leftMargin;
|
||||||
newWindowRect.right -= right_margin;
|
newWindowRect.right -= rightMargin;
|
||||||
newWindowRect.bottom -= bottom_margin;
|
newWindowRect.bottom -= bottomMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map to screen coords
|
// Map to screen coords
|
||||||
@ -97,7 +100,8 @@ RECT Zone::ComputeActualZoneRect(HWND window, HWND zoneWindow) noexcept
|
|||||||
const auto taskbar_left_size = std::abs(mi.rcMonitor.left - mi.rcWork.left);
|
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);
|
const auto taskbar_top_size = std::abs(mi.rcMonitor.top - mi.rcWork.top);
|
||||||
OffsetRect(&newWindowRect, -taskbar_left_size, -taskbar_top_size);
|
OffsetRect(&newWindowRect, -taskbar_left_size, -taskbar_top_size);
|
||||||
if (accountForUnawareness)
|
|
||||||
|
if (accountForUnawareness && MonitorInfo::GetMonitorsCount() > 1)
|
||||||
{
|
{
|
||||||
newWindowRect.left = max(mi.rcMonitor.left, newWindowRect.left);
|
newWindowRect.left = max(mi.rcMonitor.left, newWindowRect.left);
|
||||||
newWindowRect.right = min(mi.rcMonitor.right - taskbar_left_size, newWindowRect.right);
|
newWindowRect.right = min(mi.rcMonitor.right - taskbar_left_size, newWindowRect.right);
|
||||||
|
Loading…
Reference in New Issue
Block a user