Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
win: don't repaint superflus
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Oct 19, 2023
1 parent 3ed04de commit aa489b2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
4 changes: 1 addition & 3 deletions FramelessHelperConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ foreach(_component ${@PROJECT_NAME@_FIND_COMPONENTS})
if(EXISTS "${__targets_file}")
include("${__targets_file}")
add_library(${__target} ALIAS @PROJECT_NAME@::${__target_full})
if(NOT "x${_component}" STREQUAL "xCore")
list(APPEND _@PROJECT_NAME@_available_components ${_component})
endif()
else()
set(@PROJECT_NAME@_FOUND FALSE)
set(@PROJECT_NAME@_NOT_FOUND_MESSAGE "Can't find necessary configuration file for ${__target}, please make sure this component is built successfully and installed properly.")
Expand Down Expand Up @@ -76,6 +73,7 @@ set_package_properties(@PROJECT_NAME@ PROPERTIES
)

if(${@PROJECT_NAME@_FOUND})
list(REMOVE_DUPLICATES _@PROJECT_NAME@_available_components)
find_dependency(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${_@PROJECT_NAME@_available_components})
find_dependency(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${_@PROJECT_NAME@_available_components})
endif()
61 changes: 33 additions & 28 deletions src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,39 +409,44 @@ void FramelessQuickHelperPrivate::repaintAllChildren()

void FramelessQuickHelperPrivate::doRepaintAllChildren()
{
Q_Q(const FramelessQuickHelper);
QQuickWindow *window = q->window();
if (!window) {
return;
}
repaintTimer.stop();
static bool firstTime = true;
if (firstTime) {
firstTime = false;
} else {
Q_Q(const FramelessQuickHelper);
QQuickWindow *window = q->window();
if (!window) {
return;
}
#ifdef Q_OS_WINDOWS
// 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{ 10, 10, 10, 10 };
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{ 10, 10, 10, 10 };
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<QQuickItem *> items = window->findChildren<QQuickItem *>();
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<QQuickItem *> items = window->findChildren<QQuickItem *>();
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
repaintTimer.stop();
}
}

quint32 FramelessQuickHelperPrivate::readyWaitTime() const
Expand Down
15 changes: 10 additions & 5 deletions src/widgets/framelesswidgetshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,20 @@ void FramelessWidgetsHelperPrivate::repaintAllChildren()

void FramelessWidgetsHelperPrivate::doRepaintAllChildren()
{
repaintTimer.stop();
if (!window) {
return;
}
forceWidgetRepaint(window);
const QList<QWidget *> widgets = window->findChildren<QWidget *>();
for (auto &&widget : std::as_const(widgets)) {
forceWidgetRepaint(widget);
static bool firstTime = true;
if (firstTime) {
firstTime = false;
} else {
forceWidgetRepaint(window);
const QList<QWidget *> widgets = window->findChildren<QWidget *>();
for (auto &&widget : std::as_const(widgets)) {
forceWidgetRepaint(widget);
}
}
repaintTimer.stop();
}

quint32 FramelessWidgetsHelperPrivate::readyWaitTime() const
Expand Down

0 comments on commit aa489b2

Please sign in to comment.