Windows QPA: Fix restore geometry after dragging from maximised - Fix
Small adjustment made to previous patch to fix the following issues: - restoreGeometry not being updated after moving the window from one screen to the other with keyboard shortcuts. - restoreGeometry's size not being changed when moving screens if WM_GETDPISCALEDSIZE isn't sent. Task-number: QTBUG-112814 Change-Id: I9dd2340137ce57a731f8881d476e902323887e62 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 245c2b621f5942861b7f827bfc8a859b9efb9b72) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
78760fd3d8
commit
4139b6d029
@ -1954,6 +1954,12 @@ void QWindowsWindow::handleCompositionSettingsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
qreal QWindowsWindow::dpiRelativeScale(const UINT dpi) const
|
||||
{
|
||||
return QHighDpiScaling::roundScaleFactor(qreal(dpi) / QWindowsScreen::baseDpi) /
|
||||
QHighDpiScaling::roundScaleFactor(qreal(savedDpi()) / QWindowsScreen::baseDpi);
|
||||
}
|
||||
|
||||
void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result)
|
||||
{
|
||||
// We want to keep QWindow's device independent size constant across the
|
||||
@ -1961,9 +1967,8 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *
|
||||
// by the change of DPI (e.g. 120 -> 144 = 1.2), also taking any scale
|
||||
// factor rounding into account. The win32 window size includes the margins;
|
||||
// add the margins for the new DPI to the window size.
|
||||
const int dpi = int(wParam);
|
||||
const qreal scale = QHighDpiScaling::roundScaleFactor(qreal(dpi) / QWindowsScreen::baseDpi) /
|
||||
QHighDpiScaling::roundScaleFactor(qreal(savedDpi()) / QWindowsScreen::baseDpi);
|
||||
const UINT dpi = UINT(wParam);
|
||||
const qreal scale = dpiRelativeScale(dpi);
|
||||
const QMargins margins = QWindowsGeometryHint::frame(window(), style(), exStyle(), dpi);
|
||||
if (!(m_data.flags & Qt::FramelessWindowHint)) {
|
||||
// We need to update the custom margins to match the current DPI, because
|
||||
@ -1973,10 +1978,6 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *
|
||||
// are currently doing.
|
||||
m_data.customMargins *= scale;
|
||||
}
|
||||
if (!m_data.restoreGeometry.isEmpty()) {
|
||||
m_data.restoreGeometry.setWidth(m_data.restoreGeometry.width() * scale);
|
||||
m_data.restoreGeometry.setHeight(m_data.restoreGeometry.height() * scale);
|
||||
}
|
||||
|
||||
const QSize windowSize = (geometry().size() * scale).grownBy(margins + customMargins());
|
||||
SIZE *size = reinterpret_cast<SIZE *>(lParam);
|
||||
@ -1988,11 +1989,14 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *
|
||||
void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
const UINT dpi = HIWORD(wParam);
|
||||
const qreal scale = dpiRelativeScale(dpi);
|
||||
setSavedDpi(dpi);
|
||||
|
||||
// Send screen change first, so that the new screen is set during any following resize
|
||||
checkForScreenChanged(QWindowsWindow::FromDpiChange);
|
||||
|
||||
if (!IsZoomed(hwnd))
|
||||
m_data.restoreGeometry.setSize(m_data.restoreGeometry.size() * scale);
|
||||
|
||||
// We get WM_DPICHANGED in one of two situations:
|
||||
//
|
||||
// 1. The DPI change is a "spontaneous" DPI change as a result of e.g.
|
||||
@ -2030,7 +2034,7 @@ void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
void QWindowsWindow::handleDpiChangedAfterParent(HWND hwnd)
|
||||
{
|
||||
const UINT dpi = GetDpiForWindow(hwnd);
|
||||
const qreal scale = qreal(dpi) / qreal(savedDpi());
|
||||
const qreal scale = dpiRelativeScale(dpi);
|
||||
setSavedDpi(dpi);
|
||||
|
||||
checkForScreenChanged(QWindowsWindow::FromDpiChange);
|
||||
@ -2266,6 +2270,9 @@ void QWindowsWindow::handleGeometryChange()
|
||||
if (testFlag(SynchronousGeometryChangeEvent))
|
||||
QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
|
||||
if (!testFlag(ResizeMoveActive))
|
||||
updateRestoreGeometry();
|
||||
|
||||
if (!wasSync)
|
||||
clearFlag(SynchronousGeometryChangeEvent);
|
||||
qCDebug(lcQpaEvents) << __FUNCTION__ << this << window() << m_data.geometry;
|
||||
|
@ -345,6 +345,7 @@ public:
|
||||
|
||||
void setSavedDpi(int dpi) { m_savedDpi = dpi; }
|
||||
int savedDpi() const { return m_savedDpi; }
|
||||
qreal dpiRelativeScale(const UINT dpi) const;
|
||||
|
||||
private:
|
||||
inline void show_sys() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user