Skip to content

Commit

Permalink
Backport Qt patch - Revert "Windows QPA: Move transient children with…
Browse files Browse the repository at this point in the history
… a window move"

From 19471b2 Mon Sep 17 00:00:00 2001
From: Timothée Keller <[email protected]>
Date: Tue, 10 Oct 2023 07:57:09 +0000
Subject: [PATCH] Revert "Windows QPA: Move transient children with a window move"

This reverts commit 530d092.

Reason for revert: Moving transient children as a whole is too broad, and forces unrelated windows to have their position completely dependent on a transient parent.

Fixes: QTBUG-117779
Pick-to: 6.5
Change-Id: I01312e26e95c8144c392eca33aec41f54aaa40b0
Reviewed-by: Tor Arne Vestbø <[email protected]>
(cherry picked from commit 614e0f1)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
woelker-adsk committed Mar 21, 2024
1 parent 97990d1 commit c3f7031
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 52 deletions.
46 changes: 0 additions & 46 deletions src/plugins/platforms/windows/qwindowswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ QWindowsWindowData

result.geometry = obtainedGeometry;
result.restoreGeometry = frameGeometry(result.hwnd, topLevel);
result.preMoveGeometry = obtainedGeometry;
result.fullFrameMargins = context->margins;
result.embedded = embedded;
result.hasFrame = hasFrame;
Expand Down Expand Up @@ -2164,56 +2163,11 @@ void QWindowsWindow::setGeometry(const QRect &rectIn)
}
}

QWindow *QWindowsWindow::topTransientOf(QWindow *w)
{
while (QWindow *transientParent = w->transientParent())
w = transientParent;
return w;
}

void QWindowsWindow::moveTransientChildren()
{
// We need the topmost Transient parent since it is the window that will initiate
// the chain of moves, and is the only one with an already up to date DPI, which we
// need for the scaling.
const QWindowsWindow *topTransient = QWindowsWindow::windowsWindowOf(topTransientOf(window()));

const QWindow *currentWindow = window();
const QWindowList allWindows = QGuiApplication::allWindows();
for (QWindow *w : allWindows) {
if (w->transientParent() == currentWindow && w != currentWindow && w->isVisible()) {
QWindowsWindow *transientChild = QWindowsWindow::windowsWindowOf(w);

RECT oldChildPos{};
GetWindowRect(transientChild->handle(), &oldChildPos);
const RECT oldParentPos = RECTfromQRect(preMoveRect());

const qreal scale =
QHighDpiScaling::roundScaleFactor(qreal(topTransient->savedDpi()) / QWindowsScreen::baseDpi) /
QHighDpiScaling::roundScaleFactor(qreal(transientChild->savedDpi()) / QWindowsScreen::baseDpi);

const RECT offset =
RECTfromQRect(QRect(scale * (oldChildPos.left - oldParentPos.left),
scale * (oldChildPos.top - oldParentPos.top), 0, 0));
const RECT newParentPos = RECTfromQRect(m_data.geometry);
const RECT newChildPos { newParentPos.left + offset.left,
newParentPos.top + offset.top,
transientChild->geometry().width(),
transientChild->geometry().height() };

SetWindowPos(transientChild->handle(), nullptr, newChildPos.left, newChildPos.top,
newChildPos.right, newChildPos.bottom, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
}

void QWindowsWindow::handleMoved()
{
setPreMoveRect(geometry());
// Minimize/Set parent can send nonsensical move events.
if (!IsIconic(m_data.hwnd) && !testFlag(WithinSetParent))
handleGeometryChange();
moveTransientChildren();
}

void QWindowsWindow::handleResized(int wParam, LPARAM lParam)
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/platforms/windows/qwindowswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct QWindowsWindowData
{
Qt::WindowFlags flags;
QRect geometry;
QRect preMoveGeometry;
QRect restoreGeometry;
QMargins fullFrameMargins; // Do not use directly for windows, see FrameDirty.
QMargins customMargins; // User-defined, additional frame for NCCALCSIZE
Expand Down Expand Up @@ -223,11 +222,6 @@ class QWindowsWindow : public QWindowsBaseWindow
QRect restoreGeometry() const { return m_data.restoreGeometry; }
void updateRestoreGeometry();

static QWindow *topTransientOf(QWindow *w);
QRect preMoveRect() const { return m_data.preMoveGeometry; }
void setPreMoveRect(const QRect &rect) { m_data.preMoveGeometry = rect; }
void moveTransientChildren();

void setVisible(bool visible) override;
bool isVisible() const;
bool isExposed() const override { return testFlag(Exposed); }
Expand Down

0 comments on commit c3f7031

Please sign in to comment.