From 5670a28559ab459c33896c346ddd1cdd23046143 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Mon, 13 Nov 2023 17:29:52 +0800 Subject: [PATCH] win: minor improvements --- .../Quick/private/framelessquickhelper_p.h | 1 - .../private/framelesswidgetshelper_p.h | 1 - src/quick/framelessquickhelper.cpp | 60 +++++++++---------- src/widgets/framelesswidgetshelper.cpp | 20 +++---- 4 files changed, 36 insertions(+), 46 deletions(-) diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index d7ac9b10..358129c5 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -86,7 +86,6 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject bool qpaReady = false; quint32 qpaWaitTime = 0; QTimer repaintTimer{}; - bool repaintedOnce = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index d544d037..ba00b8c8 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -86,7 +86,6 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject QSizePolicy savedSizePolicy = {}; quint32 qpaWaitTime = 0; QTimer repaintTimer{}; - bool repaintedOnce = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index 21c51ca7..bf95aeab 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -72,7 +72,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE using namespace Global; -static constexpr const auto kRepaintTimerInterval = 500; +static constexpr const auto kRepaintTimerInterval = 300; struct FramelessQuickHelperExtraData : public FramelessExtraData { @@ -414,42 +414,38 @@ void FramelessQuickHelperPrivate::repaintAllChildren() void FramelessQuickHelperPrivate::doRepaintAllChildren() { repaintTimer.stop(); - if (repaintedOnce) { - Q_Q(const FramelessQuickHelper); - QQuickWindow *window = q->window(); - if (!window) { - return; - } + Q_Q(const FramelessQuickHelper); + QQuickWindow *window = q->window(); + if (!window) { + return; + } #if (defined(Q_OS_WINDOWS) && (QT_VERSION != QT_VERSION_CHECK(6, 5, 3)) && (QT_VERSION != QT_VERSION_CHECK(6, 6, 0))) - // Sync the internal window frame margins with the latest DPI, otherwise - // we will get wrong window sizes after the DPI change. - std::ignore = Utils::updateInternalWindowFrameMargins(window, true); + // Sync the internal window frame margins with the latest DPI, otherwise + // we will get wrong window sizes after the DPI change. + std::ignore = Utils::updateInternalWindowFrameMargins(window, true); #endif // Q_OS_WINDOWS - // No need to repaint the window when it's hidden. - if (!window->isVisible()) { - return; - } - if (!((window->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) || q->isWindowFixedSize())) { - const QSize originalSize = window->size(); - static constexpr const auto margins = QMargins{ 1, 1, 1, 1 }; - window->resize(originalSize.shrunkBy(margins)); - window->resize(originalSize.grownBy(margins)); - window->resize(originalSize); - } - window->requestUpdate(); + // No need to repaint the window when it's hidden. + if (!window->isVisible()) { + return; + } + if (!((window->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) || q->isWindowFixedSize())) { + const QSize originalSize = window->size(); + static constexpr const auto margins = QMargins{ 1, 1, 1, 1 }; + window->resize(originalSize.shrunkBy(margins)); + window->resize(originalSize.grownBy(margins)); + window->resize(originalSize); + } + window->requestUpdate(); #if 0 // Calling QWindow::requestUpdate() should be enough. - const QList items = window->findChildren(); - for (auto &&item : std::as_const(items)) { - // Only items with the "QQuickItem::ItemHasContents" flag enabled are allowed to call "update()". - // And don't repaint the item if it's hidden. - if ((item->flags() & QQuickItem::ItemHasContents) && item->isVisible()) { - item->update(); - } + const QList items = window->findChildren(); + for (auto &&item : std::as_const(items)) { + // Only items with the "QQuickItem::ItemHasContents" flag enabled are allowed to call "update()". + // And don't repaint the item if it's hidden. + if ((item->flags() & QQuickItem::ItemHasContents) && item->isVisible()) { + item->update(); } -#endif - } else { - repaintedOnce = true; } +#endif } quint32 FramelessQuickHelperPrivate::readyWaitTime() const diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 965d0ff9..c560d023 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -71,7 +71,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE using namespace Global; -static constexpr const auto kRepaintTimerInterval = 500; +static constexpr const auto kRepaintTimerInterval = 300; struct FramelessWidgetsHelperExtraData : public FramelessExtraData { @@ -378,17 +378,13 @@ void FramelessWidgetsHelperPrivate::repaintAllChildren() void FramelessWidgetsHelperPrivate::doRepaintAllChildren() { repaintTimer.stop(); - if (repaintedOnce) { - if (!window) { - return; - } - forceWidgetRepaint(window); - const QList widgets = window->findChildren(); - for (auto &&widget : std::as_const(widgets)) { - forceWidgetRepaint(widget); - } - } else { - repaintedOnce = true; + if (!window) { + return; + } + forceWidgetRepaint(window); + const QList widgets = window->findChildren(); + for (auto &&widget : std::as_const(widgets)) { + forceWidgetRepaint(widget); } }