From 4421b6c90a26ef45156059313b02f2c925d82104 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 23 Jun 2024 13:32:12 +0200 Subject: [PATCH] fix(windows): wait for Qt before getting bounds (#5478) --- CHANGELOG.md | 1 + src/widgets/BaseWindow.cpp | 11 ++++++++--- src/widgets/BaseWindow.hpp | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a676036..35717f6af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Bugfix: Fixed a crash that could occur when logging was enabled in IRC servers that were removed. (#5419) - Bugfix: Fixed message history occasionally not loading after a sleep. (#5457) - Bugfix: Fixed a crash when tab completing while having an invalid plugin loaded. (#5401) +- Bugfix: Fixed windows on Windows not saving correctly when snapping them to the edges. (#5478) - Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420) - Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422) - Dev: Unsingletonize `ISoundController`. (#5462) diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 6d880067e..6d636b9d6 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -240,7 +240,7 @@ BaseWindow::BaseWindow(FlagsEnum _flags, QWidget *parent) #ifdef USEWINSDK this->useNextBounds_.setSingleShot(true); QObject::connect(&this->useNextBounds_, &QTimer::timeout, this, [this]() { - this->currentBounds_ = this->nextBounds_; + this->currentBounds_ = this->geometry(); }); #endif @@ -1137,7 +1137,11 @@ bool BaseWindow::handleSIZE(MSG *msg) if (this->isNotMinimizedOrMaximized_) { - this->currentBounds_ = this->geometry(); + // Wait for WM_SIZE to be processed by Qt and update the current + // bounds afterwards. + postToThread([this] { + this->currentBounds_ = this->geometry(); + }); } this->useNextBounds_.stop(); @@ -1166,7 +1170,8 @@ bool BaseWindow::handleMOVE(MSG *msg) #ifdef USEWINSDK if (this->isNotMinimizedOrMaximized_) { - this->nextBounds_ = this->geometry(); + // Wait for WM_SIZE (in case the window was maximized, we don't want to + // save the bounds but keep the old ones) this->useNextBounds_.start(10); } #endif diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index 946c9e245..2f2168645 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -188,7 +188,6 @@ private: QRect initalBounds_; QRect currentBounds_; - QRect nextBounds_; QTimer useNextBounds_; bool isNotMinimizedOrMaximized_{}; bool lastEventWasNcMouseMove_ = false;