diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index 6f7c855..84bd411 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -97,6 +97,7 @@ private: QColor m_savedWindowBackgroundColor = {}; bool m_blurBehindWindowEnabled = false; std::optional m_extendIntoTitleBar = std::nullopt; + bool m_destroying = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index 12528d9..f9ed797 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -92,6 +92,7 @@ private: QColor m_savedWindowBackgroundColor = {}; bool m_blurBehindWindowEnabled = false; QPointer m_window = nullptr; + bool m_destroying = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index 2ed0190..1542f23 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -25,6 +25,7 @@ #include "framelessmanager_p.h" #include #include +#include #include #include #include @@ -73,14 +74,15 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper) Q_GLOBAL_STATIC(FramelessManager, g_manager) +[[maybe_unused]] static constexpr const char kGlobalFlagVarName[] = "__FRAMELESSHELPER__"; FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb") #ifdef Q_OS_MACOS - static constexpr const int kIconFontPointSize = 10; + [[maybe_unused]] static constexpr const int kIconFontPointSize = 10; #else - static constexpr const int kIconFontPointSize = 8; + [[maybe_unused]] static constexpr const int kIconFontPointSize = 8; #endif [[nodiscard]] static inline QString iconFontFamilyName() @@ -352,11 +354,21 @@ void FramelessManagerPrivate::initialize() m_wallpaperAspectStyle = Utils::getWallpaperAspectStyle(); #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) QStyleHints * const styleHints = QGuiApplication::styleHints(); - connect(styleHints, &QStyleHints::appearanceChanged, this, [this](const Qt::Appearance appearance){ - Q_UNUSED(appearance); - notifySystemThemeHasChangedOrNot(); - }); + Q_ASSERT(styleHints); + if (styleHints) { + connect(styleHints, &QStyleHints::appearanceChanged, this, [this](const Qt::Appearance appearance){ + Q_UNUSED(appearance); + notifySystemThemeHasChangedOrNot(); + }); + } #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) + static bool flagSet = false; + if (!flagSet) { + flagSet = true; + // Set a global flag so that people can check whether FramelessHelper is being + // used without actually accessing the FramelessHelper interface. + qApp->setProperty(kGlobalFlagVarName, FramelessHelper::Core::version().version); + } } FramelessManager::FramelessManager(QObject *parent) : diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 272aa1b..7ddb6c1 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -282,18 +282,20 @@ struct SYSTEM_METRIC if (code == ERROR_SUCCESS) { return kSuccessMessageText; } -#if 0 // The following code works well, we commented it out just because we want to use as many Qt functionalities as possible. - LPWSTR buf = nullptr; - if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&buf), 0, nullptr) == 0) { - return kEmptyMessageText; + static constexpr const bool flag = false; + if (flag) { + // The following code works well, we commented it out just because we want to use as many Qt functionalities as possible. + LPWSTR buf = nullptr; + if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&buf), 0, nullptr) == 0) { + return kEmptyMessageText; + } + const QString errorText = QString::fromWCharArray(buf).trimmed(); + LocalFree(buf); + buf = nullptr; + return kErrorMessageTemplate.arg(function, QString::number(code), errorText); } - const QString errorText = QString::fromWCharArray(buf).trimmed(); - LocalFree(buf); - buf = nullptr; -#else const QString errorText = QSystemError::windowsString(code); -#endif return kErrorMessageTemplate.arg(function, QString::number(code), errorText); } diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index a837941..9b678c5 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -103,6 +103,7 @@ FramelessQuickHelperPrivate::FramelessQuickHelperPrivate(FramelessQuickHelper *q FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate() { + m_destroying = true; extendsContentIntoTitleBar(false); m_extendIntoTitleBar = std::nullopt; } @@ -141,7 +142,9 @@ void FramelessQuickHelperPrivate::extendsContentIntoTitleBar(const bool value) detach(); } m_extendIntoTitleBar = value; - emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged")); + if (!m_destroying) { + emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged")); + } } QQuickItem *FramelessQuickHelperPrivate::getTitleBarItem() const diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 6ac5634..78b8694 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -109,6 +109,7 @@ FramelessWidgetsHelperPrivate::FramelessWidgetsHelperPrivate(FramelessWidgetsHel FramelessWidgetsHelperPrivate::~FramelessWidgetsHelperPrivate() { + m_destroying = true; extendsContentIntoTitleBar(false); } @@ -448,7 +449,9 @@ void FramelessWidgetsHelperPrivate::extendsContentIntoTitleBar(const bool value) } else { detach(); } - emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged")); + if (!m_destroying) { + emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged")); + } } QWidget *FramelessWidgetsHelperPrivate::findTopLevelWindow() const