avoid potential deadlocks
And some other minor tweaks. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
c914992aa4
commit
f97f000cc7
|
@ -97,6 +97,7 @@ private:
|
||||||
QColor m_savedWindowBackgroundColor = {};
|
QColor m_savedWindowBackgroundColor = {};
|
||||||
bool m_blurBehindWindowEnabled = false;
|
bool m_blurBehindWindowEnabled = false;
|
||||||
std::optional<bool> m_extendIntoTitleBar = std::nullopt;
|
std::optional<bool> m_extendIntoTitleBar = std::nullopt;
|
||||||
|
bool m_destroying = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -92,6 +92,7 @@ private:
|
||||||
QColor m_savedWindowBackgroundColor = {};
|
QColor m_savedWindowBackgroundColor = {};
|
||||||
bool m_blurBehindWindowEnabled = false;
|
bool m_blurBehindWindowEnabled = false;
|
||||||
QPointer<QWidget> m_window = nullptr;
|
QPointer<QWidget> m_window = nullptr;
|
||||||
|
bool m_destroying = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "framelessmanager_p.h"
|
#include "framelessmanager_p.h"
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
|
#include <QtCore/qcoreapplication.h>
|
||||||
#include <QtGui/qscreen.h>
|
#include <QtGui/qscreen.h>
|
||||||
#include <QtGui/qwindow.h>
|
#include <QtGui/qwindow.h>
|
||||||
#include <QtGui/qfontdatabase.h>
|
#include <QtGui/qfontdatabase.h>
|
||||||
|
@ -73,14 +74,15 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper)
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(FramelessManager, g_manager)
|
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(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
static constexpr const int kIconFontPointSize = 10;
|
[[maybe_unused]] static constexpr const int kIconFontPointSize = 10;
|
||||||
#else
|
#else
|
||||||
static constexpr const int kIconFontPointSize = 8;
|
[[maybe_unused]] static constexpr const int kIconFontPointSize = 8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] static inline QString iconFontFamilyName()
|
[[nodiscard]] static inline QString iconFontFamilyName()
|
||||||
|
@ -352,11 +354,21 @@ void FramelessManagerPrivate::initialize()
|
||||||
m_wallpaperAspectStyle = Utils::getWallpaperAspectStyle();
|
m_wallpaperAspectStyle = Utils::getWallpaperAspectStyle();
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||||
QStyleHints * const styleHints = QGuiApplication::styleHints();
|
QStyleHints * const styleHints = QGuiApplication::styleHints();
|
||||||
connect(styleHints, &QStyleHints::appearanceChanged, this, [this](const Qt::Appearance appearance){
|
Q_ASSERT(styleHints);
|
||||||
Q_UNUSED(appearance);
|
if (styleHints) {
|
||||||
notifySystemThemeHasChangedOrNot();
|
connect(styleHints, &QStyleHints::appearanceChanged, this, [this](const Qt::Appearance appearance){
|
||||||
});
|
Q_UNUSED(appearance);
|
||||||
|
notifySystemThemeHasChangedOrNot();
|
||||||
|
});
|
||||||
|
}
|
||||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
#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) :
|
FramelessManager::FramelessManager(QObject *parent) :
|
||||||
|
|
|
@ -282,18 +282,20 @@ struct SYSTEM_METRIC
|
||||||
if (code == ERROR_SUCCESS) {
|
if (code == ERROR_SUCCESS) {
|
||||||
return kSuccessMessageText;
|
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.
|
static constexpr const bool flag = false;
|
||||||
LPWSTR buf = nullptr;
|
if (flag) {
|
||||||
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
// The following code works well, we commented it out just because we want to use as many Qt functionalities as possible.
|
||||||
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&buf), 0, nullptr) == 0) {
|
LPWSTR buf = nullptr;
|
||||||
return kEmptyMessageText;
|
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&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);
|
const QString errorText = QSystemError::windowsString(code);
|
||||||
#endif
|
|
||||||
return kErrorMessageTemplate.arg(function, QString::number(code), errorText);
|
return kErrorMessageTemplate.arg(function, QString::number(code), errorText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ FramelessQuickHelperPrivate::FramelessQuickHelperPrivate(FramelessQuickHelper *q
|
||||||
|
|
||||||
FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate()
|
FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate()
|
||||||
{
|
{
|
||||||
|
m_destroying = true;
|
||||||
extendsContentIntoTitleBar(false);
|
extendsContentIntoTitleBar(false);
|
||||||
m_extendIntoTitleBar = std::nullopt;
|
m_extendIntoTitleBar = std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +142,9 @@ void FramelessQuickHelperPrivate::extendsContentIntoTitleBar(const bool value)
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
m_extendIntoTitleBar = value;
|
m_extendIntoTitleBar = value;
|
||||||
emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged"));
|
if (!m_destroying) {
|
||||||
|
emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem *FramelessQuickHelperPrivate::getTitleBarItem() const
|
QQuickItem *FramelessQuickHelperPrivate::getTitleBarItem() const
|
||||||
|
|
|
@ -109,6 +109,7 @@ FramelessWidgetsHelperPrivate::FramelessWidgetsHelperPrivate(FramelessWidgetsHel
|
||||||
|
|
||||||
FramelessWidgetsHelperPrivate::~FramelessWidgetsHelperPrivate()
|
FramelessWidgetsHelperPrivate::~FramelessWidgetsHelperPrivate()
|
||||||
{
|
{
|
||||||
|
m_destroying = true;
|
||||||
extendsContentIntoTitleBar(false);
|
extendsContentIntoTitleBar(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +449,9 @@ void FramelessWidgetsHelperPrivate::extendsContentIntoTitleBar(const bool value)
|
||||||
} else {
|
} else {
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged"));
|
if (!m_destroying) {
|
||||||
|
emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *FramelessWidgetsHelperPrivate::findTopLevelWindow() const
|
QWidget *FramelessWidgetsHelperPrivate::findTopLevelWindow() const
|
||||||
|
|
Loading…
Reference in New Issue