Handle DPI change on Windows to avoid the window be resized by Qt
This commit is contained in:
parent
e72706f249
commit
cdfa6ea2bf
2 changed files with 23 additions and 1 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#include "ui/inactive_press.h"
|
||||
#include "ui/platform/win/ui_window_title_win.h"
|
||||
#include "ui/widgets/rp_window.h"
|
||||
#include "base/platform/win/base_windows_safe_library.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/integration.h"
|
||||
#include "base/debug_log.h"
|
||||
|
|
@ -36,6 +37,18 @@ constexpr auto kDWMWA_WINDOW_CORNER_PREFERENCE = DWORD(33);
|
|||
constexpr auto kDWMWA_CAPTION_COLOR = DWORD(35);
|
||||
constexpr auto kDWMWA_TEXT_COLOR = DWORD(36);
|
||||
|
||||
UINT(__stdcall *GetDpiForWindow)(_In_ HWND hwnd);
|
||||
|
||||
[[nodiscard]] bool GetDpiForWindowSupported() {
|
||||
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, GetDpiForWindow);
|
||||
#undef LOAD_SYMBOL
|
||||
}();
|
||||
return Result;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsCompositionEnabled() {
|
||||
auto result = BOOL(FALSE);
|
||||
const auto success = (DwmIsCompositionEnabled(&result) == S_OK);
|
||||
|
|
@ -163,7 +176,8 @@ WindowHelper::WindowHelper(not_null<RpWidget*> window)
|
|||
, _handle(ResolveWindowHandle(window))
|
||||
, _title(Ui::CreateChild<TitleWidget>(window.get()))
|
||||
, _body(Ui::CreateChild<RpWidget>(window.get()))
|
||||
, _shadow(std::in_place, window, st::windowShadowFg->c) {
|
||||
, _shadow(std::in_place, window, st::windowShadowFg->c)
|
||||
, _dpi(GetDpiForWindowSupported() ? GetDpiForWindow(_handle) : 0) {
|
||||
Expects(_handle != nullptr);
|
||||
|
||||
init();
|
||||
|
|
@ -595,6 +609,13 @@ bool WindowHelper::handleNativeEvent(
|
|||
}
|
||||
} return true;
|
||||
|
||||
// should return true for Qt not to change window size
|
||||
// when moving the window between screens
|
||||
// change to false once runtime scale change would be supported
|
||||
case WM_DPICHANGED: {
|
||||
_dpi = LOWORD(wParam);
|
||||
} return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ private:
|
|||
rpl::event_stream<HitTestResult> _systemButtonOver;
|
||||
rpl::event_stream<HitTestResult> _systemButtonDown;
|
||||
std::optional<WindowShadow> _shadow;
|
||||
rpl::variable<uint> _dpi;
|
||||
QMargins _marginsDelta;
|
||||
HMENU _menu = nullptr;
|
||||
bool _updatingMargins = false;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue