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

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Oct 15, 2023
1 parent b13f13a commit ff4b9f3
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 72 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ option(FRAMELESSHELPER_NO_SUMMARY "Don't show CMake configure summary." ON)
option(FRAMELESSHELPER_ENABLE_SPECTRE "Mitigate Spectre security vulnerabilities." OFF)
option(FRAMELESSHELPER_ENABLE_EHCONTGUARD "MSVC only: Enable EH Continuation (EHCONT) Metadata." OFF)
option(FRAMELESSHELPER_ENABLE_INTELCET "Enable Intel CET." OFF)
option(FRAMELESSHELPER_ENABLE_INTELJCC "Enable Intel JCC." OFF)
#option(FRAMELESSHELPER_ENABLE_INTELJCC "Enable Intel JCC." OFF) # Always enabled now.
option(FRAMELESSHELPER_ENABLE_CFGUARD "Enable Control Flow Guard (CFG)." OFF)
option(FRAMELESSHELPER_EXAMPLES_STANDALONE "Build the demo projects as standalone CMake projects." OFF)
cmake_dependent_option(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD "macOS only: build universal library/example for Mac." ON APPLE OFF)
option(FRAMELESSHELPER_FORCE_LTO "Force enable LTO/LTCG even when building static libraries." OFF)
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON)
#option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON) # Always enabled now.
option(FRAMELESSHELPER_NO_WINDOW "Disable the pre-defined FramelessWindow wrapper class." OFF)
option(FRAMELESSHELPER_NO_TITLEBAR "Disable the pre-defined StandardTitleBar control." OFF)
option(FRAMELESSHELPER_NO_TRANSLATION "Don't bundle the I18N translations into the library." OFF)
Expand Down Expand Up @@ -163,7 +163,7 @@ if(MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(FRAMELESSHELPER_ENABLE_SPECTRE OFF)
set(FRAMELESSHELPER_ENABLE_EHCONTGUARD OFF)
set(FRAMELESSHELPER_ENABLE_INTELCET OFF)
set(FRAMELESSHELPER_ENABLE_INTELJCC OFF)
#set(FRAMELESSHELPER_ENABLE_INTELJCC OFF)
set(FRAMELESSHELPER_ENABLE_CFGUARD OFF)
endif()

Expand Down Expand Up @@ -299,12 +299,12 @@ if(NOT FRAMELESSHELPER_NO_SUMMARY)
message("Mitigate Spectre security vulnerabilities: ${FRAMELESSHELPER_ENABLE_SPECTRE}")
message("[MSVC] Enable EH Continuation (EHCONT) Metadata: ${FRAMELESSHELPER_ENABLE_EHCONTGUARD}")
message("Enable Intel CET: ${FRAMELESSHELPER_ENABLE_INTELCET}")
message("Enable Intel JCC: ${FRAMELESSHELPER_ENABLE_INTELJCC}")
#message("Enable Intel JCC: ${FRAMELESSHELPER_ENABLE_INTELJCC}")
message("Enable Control Flow Guard (CFG): ${FRAMELESSHELPER_ENABLE_CFGUARD}")
message("Build standalone demo projects: ${FRAMELESSHELPER_EXAMPLES_STANDALONE}")
message("[macOS]: Build universal library/example: ${FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD}")
message("Force enable LTO: ${FRAMELESSHELPER_FORCE_LTO}")
message("Make output reproducible: ${FRAMELESSHELPER_REPRODUCIBLE_OUTPUT}")
#message("Make output reproducible: ${FRAMELESSHELPER_REPRODUCIBLE_OUTPUT}")
message("Disable the FramelessWindow class (to reduce file size): ${FRAMELESSHELPER_NO_WINDOW}")
message("Disable the StandardTitleBar class (to reduce file size): ${FRAMELESSHELPER_NO_TITLEBAR}")
message("Don't embed the I18N resources (to reduce file size): ${FRAMELESSHELPER_NO_TRANSLATION}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using GetPropertyCallback = std::function<QVariant(const char *, const QVariant
using SetCursorCallback = std::function<void(const QCursor &)>;
using UnsetCursorCallback = std::function<void()>;
using GetWidgetHandleCallback = std::function<QObject *()>;
using ForceChildrenRepaintCallback = std::function<void(const int)>;
using ForceChildrenRepaintCallback = std::function<void()>;
using ResetQtGrabbedControlCallback = std::function<bool()>;

struct FRAMELESSHELPER_CORE_API FramelessCallbacks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <FramelessHelper/Quick/framelesshelperquick_global.h>
#include <QtCore/qtimer.h>
#include <optional>

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -67,7 +68,8 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject

Q_NODISCARD static FramelessQuickHelper *findOrCreateFramelessHelper(QObject *object);

void repaintAllChildren(const quint32 delay = 0) const;
void repaintAllChildren();
Q_INVOKABLE void doRepaintAllChildren();

Q_NODISCARD quint32 readyWaitTime() const;
void setReadyWaitTime(const quint32 time);
Expand All @@ -84,6 +86,7 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject
std::optional<bool> extendIntoTitleBar = std::nullopt;
bool qpaReady = false;
quint32 qpaWaitTime = 0;
QTimer repaintTimer{};
};

FRAMELESSHELPER_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <FramelessHelper/Widgets/framelesshelperwidgets_global.h>
#include <QtCore/qvariant.h>
#include <QtCore/qtimer.h>
#include <QtWidgets/qsizepolicy.h>

FRAMELESSHELPER_BEGIN_NAMESPACE
Expand Down Expand Up @@ -66,7 +67,8 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject
Q_NODISCARD static WidgetsSharedHelper *findOrCreateSharedHelper(QWidget *window);
Q_NODISCARD static FramelessWidgetsHelper *findOrCreateFramelessHelper(QObject *object);

void repaintAllChildren(const quint32 delay = 0) const;
void repaintAllChildren();
Q_INVOKABLE void doRepaintAllChildren();

Q_NODISCARD quint32 readyWaitTime() const;
void setReadyWaitTime(const quint32 time);
Expand All @@ -84,6 +86,7 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject
bool qpaReady = false;
QSizePolicy savedSizePolicy = {};
quint32 qpaWaitTime = 0;
QTimer repaintTimer{};
};

FRAMELESSHELPER_END_NAMESPACE
3 changes: 0 additions & 3 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ endif()
if(FRAMELESSHELPER_ENABLE_INTELCET)
list(APPEND __extra_flags INTELCET)
endif()
if(FRAMELESSHELPER_ENABLE_INTELJCC)
list(APPEND __extra_flags INTELJCC)
endif()
if(FRAMELESSHELPER_ENABLE_CFGUARD)
list(APPEND __extra_flags CFGUARD)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/core/framelesshelper_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event)
if (type == QEvent::ScreenChangeInternal)
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
{
data->callbacks->forceChildrenRepaint(500);
data->callbacks->forceChildrenRepaint();
return false;
}
const auto qWindow = qobject_cast<QWindow *>(object);
Expand Down
4 changes: 2 additions & 2 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
data->restoreGeometry.setSize(Utils::rescaleSize(data->restoreGeometry.size(), oldDpi.x, newDpi.x));
}
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
data->callbacks->forceChildrenRepaint(500);
data->callbacks->forceChildrenRepaint();
} break;
case WM_DWMCOMPOSITIONCHANGED:
// Re-apply the custom window frame if recovered from the basic theme.
Expand Down Expand Up @@ -1202,7 +1202,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
break;
}
data->monitor = currentMonitor;
data->callbacks->forceChildrenRepaint(500);
data->callbacks->forceChildrenRepaint();
} break;
case WM_SYSCOMMAND: {
const WPARAM filteredWParam = (wParam & 0xFFF0);
Expand Down
3 changes: 0 additions & 3 deletions src/quick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ endif()
if(FRAMELESSHELPER_ENABLE_INTELCET)
list(APPEND __extra_flags INTELCET)
endif()
if(FRAMELESSHELPER_ENABLE_INTELJCC)
list(APPEND __extra_flags INTELJCC)
endif()
if(FRAMELESSHELPER_ENABLE_CFGUARD)
list(APPEND __extra_flags CFGUARD)
endif()
Expand Down
72 changes: 37 additions & 35 deletions src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#ifdef Q_OS_WINDOWS
# include <FramelessHelper/Core/private/winverhelper_p.h>
#endif // Q_OS_WINDOWS
#include <QtCore/qtimer.h>
#include <QtCore/qeventloop.h>
#include <QtCore/qloggingcategory.h>
#include <QtGui/qcursor.h>
Expand Down Expand Up @@ -73,6 +72,8 @@ FRAMELESSHELPER_BEGIN_NAMESPACE

using namespace Global;

static constexpr const auto kRepaintTimerInterval = 500;

struct FramelessQuickHelperExtraData : public FramelessExtraData
{
QPointer<QQuickItem> titleBarItem = nullptr;
Expand Down Expand Up @@ -137,6 +138,9 @@ FramelessQuickHelperPrivate::FramelessQuickHelperPrivate(FramelessQuickHelper *q
return;
}
q_ptr = q;
repaintTimer.setTimerType(Qt::VeryCoarseTimer);
repaintTimer.setInterval(kRepaintTimerInterval);
connect(&repaintTimer, &QTimer::timeout, this, &FramelessQuickHelperPrivate::doRepaintAllChildren);
// Workaround a MOC limitation: we can't emit a signal from the parent class.
connect(q_ptr, &FramelessQuickHelper::windowChanged, q_ptr, &FramelessQuickHelper::windowChanged2);
}
Expand Down Expand Up @@ -212,7 +216,7 @@ void FramelessQuickHelperPrivate::attach()
data->callbacks->setCursor = [window](const QCursor &cursor) -> void { window->setCursor(cursor); };
data->callbacks->unsetCursor = [window]() -> void { window->unsetCursor(); };
data->callbacks->getWidgetHandle = []() -> QObject * { return nullptr; };
data->callbacks->forceChildrenRepaint = [this](const int delay) -> void { repaintAllChildren(delay); };
data->callbacks->forceChildrenRepaint = [this]() -> void { repaintAllChildren(); };
data->callbacks->resetQtGrabbedControl = []() -> bool { return false; };
}

Expand Down Expand Up @@ -398,48 +402,46 @@ FramelessQuickHelper *FramelessQuickHelperPrivate::findOrCreateFramelessHelper(Q
return instance;
}

void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
void FramelessQuickHelperPrivate::repaintAllChildren()
{
repaintTimer.start();
}

void FramelessQuickHelperPrivate::doRepaintAllChildren()
{
Q_Q(const FramelessQuickHelper);
QQuickWindow * const window = q->window();
QQuickWindow *window = q->window();
if (!window) {
return;
}
const auto update = [window, q]() -> void {
#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();
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
if (items.isEmpty()) {
return;
}
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();
}
// 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();
}
};
if (delay > 0) {
QTimer::singleShot(delay, this, update);
} else {
update();
}
#endif
repaintTimer.stop();
}

quint32 FramelessQuickHelperPrivate::readyWaitTime() const
Expand Down
3 changes: 0 additions & 3 deletions src/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ endif()
if(FRAMELESSHELPER_ENABLE_INTELCET)
list(APPEND __extra_flags INTELCET)
endif()
if(FRAMELESSHELPER_ENABLE_INTELJCC)
list(APPEND __extra_flags INTELJCC)
endif()
if(FRAMELESSHELPER_ENABLE_CFGUARD)
list(APPEND __extra_flags CFGUARD)
endif()
Expand Down
34 changes: 17 additions & 17 deletions src/widgets/framelesswidgetshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/private/framelesshelpercore_global_p.h>
#include <QtCore/qhash.h>
#include <QtCore/qtimer.h>
#include <QtCore/qeventloop.h>
#include <QtCore/qloggingcategory.h>
#include <QtGui/qwindow.h>
Expand Down Expand Up @@ -72,6 +71,8 @@ FRAMELESSHELPER_BEGIN_NAMESPACE

using namespace Global;

static constexpr const auto kRepaintTimerInterval = 500;

struct FramelessWidgetsHelperExtraData : public FramelessExtraData
{
QPointer<QWidget> titleBarWidget = nullptr;
Expand Down Expand Up @@ -210,6 +211,9 @@ FramelessWidgetsHelperPrivate::FramelessWidgetsHelperPrivate(FramelessWidgetsHel
return;
}
q_ptr = q;
repaintTimer.setTimerType(Qt::VeryCoarseTimer);
repaintTimer.setInterval(kRepaintTimerInterval);
connect(&repaintTimer, &QTimer::timeout, this, &FramelessWidgetsHelperPrivate::doRepaintAllChildren);
}

FramelessWidgetsHelperPrivate::~FramelessWidgetsHelperPrivate() = default;
Expand Down Expand Up @@ -363,26 +367,22 @@ FramelessWidgetsHelper *FramelessWidgetsHelperPrivate::findOrCreateFramelessHelp
return instance;
}

void FramelessWidgetsHelperPrivate::repaintAllChildren(const quint32 delay) const
void FramelessWidgetsHelperPrivate::repaintAllChildren()
{
repaintTimer.start();
}

void FramelessWidgetsHelperPrivate::doRepaintAllChildren()
{
if (!window) {
return;
}
const auto update = [this]() -> void {
forceWidgetRepaint(window);
const QList<QWidget *> widgets = window->findChildren<QWidget *>();
if (widgets.isEmpty()) {
return;
}
for (auto &&widget : std::as_const(widgets)) {
forceWidgetRepaint(widget);
}
};
if (delay > 0) {
QTimer::singleShot(delay, this, update);
} else {
update();
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 Expand Up @@ -460,7 +460,7 @@ void FramelessWidgetsHelperPrivate::attach()
data->callbacks->setCursor = [this](const QCursor &cursor) -> void { window->setCursor(cursor); };
data->callbacks->unsetCursor = [this]() -> void { window->unsetCursor(); };
data->callbacks->getWidgetHandle = [this]() -> QObject * { return window; };
data->callbacks->forceChildrenRepaint = [this](const int delay) -> void { repaintAllChildren(delay); };
data->callbacks->forceChildrenRepaint = [this]() -> void { repaintAllChildren(); };
data->callbacks->resetQtGrabbedControl = []() -> bool {
if (qt_button_down) {
static constexpr const auto invalidPos = QPoint{ -99999, -99999 };
Expand Down

0 comments on commit ff4b9f3

Please sign in to comment.