Make WindowHelper::updateMargins multi-screen DPI aware
This commit is contained in:
parent
e66ad9c80c
commit
cbb9e0bbde
1 changed files with 26 additions and 2 deletions
|
|
@ -48,6 +48,13 @@ int(__stdcall *GetSystemMetricsForDpi)(
|
||||||
_In_ int nIndex,
|
_In_ int nIndex,
|
||||||
_In_ UINT dpi);
|
_In_ UINT dpi);
|
||||||
|
|
||||||
|
BOOL(__stdcall *AdjustWindowRectExForDpi)(
|
||||||
|
_Inout_ LPRECT lpRect,
|
||||||
|
_In_ DWORD dwStyle,
|
||||||
|
_In_ BOOL bMenu,
|
||||||
|
_In_ DWORD dwExStyle,
|
||||||
|
_In_ UINT dpi);
|
||||||
|
|
||||||
[[nodiscard]] bool GetDpiForWindowSupported() {
|
[[nodiscard]] bool GetDpiForWindowSupported() {
|
||||||
static const auto Result = [&] {
|
static const auto Result = [&] {
|
||||||
#define LOAD_SYMBOL(lib, name) base::Platform::LoadMethod(lib, #name, name)
|
#define LOAD_SYMBOL(lib, name) base::Platform::LoadMethod(lib, #name, name)
|
||||||
|
|
@ -68,6 +75,16 @@ int(__stdcall *GetSystemMetricsForDpi)(
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool AdjustWindowRectExForDpiSupported() {
|
||||||
|
static const auto Result = [&] {
|
||||||
|
#define LOAD_SYMBOL(lib, name) base::Platform::LoadMethod(lib, #name, name)
|
||||||
|
const auto user32 = base::Platform::SafeLoadLibrary(L"User32.dll");
|
||||||
|
return LOAD_SYMBOL(user32, AdjustWindowRectExForDpi);
|
||||||
|
#undef LOAD_SYMBOL
|
||||||
|
}();
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool IsCompositionEnabled() {
|
[[nodiscard]] bool IsCompositionEnabled() {
|
||||||
auto result = BOOL(FALSE);
|
auto result = BOOL(FALSE);
|
||||||
const auto success = (DwmIsCompositionEnabled(&result) == S_OK);
|
const auto success = (DwmIsCompositionEnabled(&result) == S_OK);
|
||||||
|
|
@ -416,7 +433,9 @@ void WindowHelper::init() {
|
||||||
}();
|
}();
|
||||||
}, window()->lifetime());
|
}, window()->lifetime());
|
||||||
|
|
||||||
updateMargins();
|
_dpi.value() | rpl::start_with_next([=](uint dpi) {
|
||||||
|
updateMargins();
|
||||||
|
}, window()->lifetime());
|
||||||
|
|
||||||
if (!::Platform::IsWindows11OrGreater()) {
|
if (!::Platform::IsWindows11OrGreater()) {
|
||||||
_shadow.emplace(window(), st::windowShadowFg->c);
|
_shadow.emplace(window(), st::windowShadowFg->c);
|
||||||
|
|
@ -854,7 +873,12 @@ void WindowHelper::updateMargins() {
|
||||||
RECT r{};
|
RECT r{};
|
||||||
const auto style = GetWindowLongPtr(_handle, GWL_STYLE);
|
const auto style = GetWindowLongPtr(_handle, GWL_STYLE);
|
||||||
const auto styleEx = GetWindowLongPtr(_handle, GWL_EXSTYLE);
|
const auto styleEx = GetWindowLongPtr(_handle, GWL_EXSTYLE);
|
||||||
AdjustWindowRectEx(&a, style, false, styleEx);
|
const auto dpi = _dpi.current();
|
||||||
|
if (AdjustWindowRectExForDpiSupported() && dpi) {
|
||||||
|
AdjustWindowRectExForDpi(&r, style, false, styleEx, dpi);
|
||||||
|
} else {
|
||||||
|
AdjustWindowRectEx(&r, style, false, styleEx);
|
||||||
|
}
|
||||||
auto margins = QMargins(r.left, r.top, -r.right, -r.bottom);
|
auto margins = QMargins(r.left, r.top, -r.right, -r.bottom);
|
||||||
if (style & WS_MAXIMIZE) {
|
if (style & WS_MAXIMIZE) {
|
||||||
RECT w, m;
|
RECT w, m;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue