This commit is contained in:
Yuhang Zhao 2023-05-19 11:55:41 +08:00
parent 721f46307b
commit 1ba9c9c918
5 changed files with 7 additions and 26 deletions

View File

@ -33,7 +33,6 @@
#include <QtWidgets/qboxlayout.h> #include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qfileiconprovider.h> #include <QtWidgets/qfileiconprovider.h>
#include <FramelessHelper/Core/framelessmanager.h> #include <FramelessHelper/Core/framelessmanager.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Widgets/framelesswidgetshelper.h> #include <FramelessHelper/Widgets/framelesswidgetshelper.h>
#include <FramelessHelper/Widgets/standardtitlebar.h> #include <FramelessHelper/Widgets/standardtitlebar.h>
#include <FramelessHelper/Widgets/standardsystembutton.h> #include <FramelessHelper/Widgets/standardsystembutton.h>
@ -144,7 +143,7 @@ void Widget::initialize()
void Widget::updateStyleSheet() void Widget::updateStyleSheet()
{ {
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
const QColor clockLabelTextColor = (dark ? kDefaultWhiteColor : kDefaultBlackColor); const QColor clockLabelTextColor = (dark ? kDefaultWhiteColor : kDefaultBlackColor);
m_clockLabel->setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent; color: %1;") m_clockLabel->setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent; color: %1;")
.arg(clockLabelTextColor.name())); .arg(clockLabelTextColor.name()));

View File

@ -81,7 +81,7 @@ const ChromePalettePrivate *ChromePalettePrivate::get(const ChromePalette *q)
void ChromePalettePrivate::refresh() void ChromePalettePrivate::refresh()
{ {
const bool colorized = Utils::isTitleBarColorized(); const bool colorized = Utils::isTitleBarColorized();
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
titleBarActiveBackgroundColor_sys = [colorized, dark]() -> QColor { titleBarActiveBackgroundColor_sys = [colorized, dark]() -> QColor {
if (colorized) { if (colorized) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS

View File

@ -558,7 +558,7 @@ void FramelessHelperWin::addWindow(FramelessParamsConst params)
// Tell DWM we may need dark theme non-client area (title bar & frame border). // Tell DWM we may need dark theme non-client area (title bar & frame border).
FramelessHelper::Core::setApplicationOSThemeAware(); FramelessHelper::Core::setApplicationOSThemeAware();
if (WindowsVersionHelper::isWin10RS5OrGreater()) { if (WindowsVersionHelper::isWin10RS5OrGreater()) {
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
const auto isWidget = [params]() -> bool { const auto isWidget = [params]() -> bool {
const auto widget = params->getWidgetHandle(); const auto widget = params->getWidgetHandle();
return (widget && widget->isWidgetType()); return (widget && widget->isWidgetType());
@ -1336,7 +1336,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
&& (std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), kThemeSettingChangeEventName) == 0)) { && (std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), kThemeSettingChangeEventName) == 0)) {
systemThemeChanged = true; systemThemeChanged = true;
if (WindowsVersionHelper::isWin10RS5OrGreater()) { if (WindowsVersionHelper::isWin10RS5OrGreater()) {
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
const auto isWidget = [&data]() -> bool { const auto isWidget = [&data]() -> bool {
const auto widget = data.params.getWidgetHandle(); const auto widget = data.params.getWidgetHandle();
return (widget && widget->isWidgetType()); return (widget && widget->isWidgetType());

View File

@ -32,7 +32,6 @@
# include "framelesshelper_win.h" # include "framelesshelper_win.h"
# include "winverhelper_p.h" # include "winverhelper_p.h"
#endif #endif
#include <QtCore/qmutex.h>
#include <QtCore/qvariant.h> #include <QtCore/qvariant.h>
#include <QtCore/qcoreapplication.h> #include <QtCore/qcoreapplication.h>
#include <QtCore/qloggingcategory.h> #include <QtCore/qloggingcategory.h>
@ -62,7 +61,6 @@ using namespace Global;
struct FramelessManagerHelper struct FramelessManagerHelper
{ {
QMutex mutex;
QList<WId> windowIds = {}; QList<WId> windowIds = {};
}; };
@ -170,28 +168,23 @@ SystemTheme FramelessManagerPrivate::systemTheme() const
{ {
// The user's choice has top priority. // The user's choice has top priority.
if (isThemeOverrided()) { if (isThemeOverrided()) {
const QMutexLocker locker(&g_helper()->mutex);
return m_overrideTheme.value(); return m_overrideTheme.value();
} }
const QMutexLocker locker(&g_helper()->mutex);
return m_systemTheme; return m_systemTheme;
} }
QColor FramelessManagerPrivate::systemAccentColor() const QColor FramelessManagerPrivate::systemAccentColor() const
{ {
const QMutexLocker locker(&g_helper()->mutex);
return m_accentColor; return m_accentColor;
} }
QString FramelessManagerPrivate::wallpaper() const QString FramelessManagerPrivate::wallpaper() const
{ {
const QMutexLocker locker(&g_helper()->mutex);
return m_wallpaper; return m_wallpaper;
} }
WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const
{ {
const QMutexLocker locker(&g_helper()->mutex);
return m_wallpaperAspectStyle; return m_wallpaperAspectStyle;
} }
@ -202,13 +195,10 @@ void FramelessManagerPrivate::addWindow(FramelessParamsConst params)
return; return;
} }
const WId windowId = params->getWindowId(); const WId windowId = params->getWindowId();
g_helper()->mutex.lock();
if (g_helper()->windowIds.contains(windowId)) { if (g_helper()->windowIds.contains(windowId)) {
g_helper()->mutex.unlock();
return; return;
} }
g_helper()->windowIds.append(windowId); g_helper()->windowIds.append(windowId);
g_helper()->mutex.unlock();
static const bool pureQt = usePureQtImplementation(); static const bool pureQt = usePureQtImplementation();
if (pureQt) { if (pureQt) {
FramelessHelperQt::addWindow(params); FramelessHelperQt::addWindow(params);
@ -227,13 +217,10 @@ void FramelessManagerPrivate::removeWindow(const WId windowId)
if (!windowId) { if (!windowId) {
return; return;
} }
g_helper()->mutex.lock();
if (!g_helper()->windowIds.contains(windowId)) { if (!g_helper()->windowIds.contains(windowId)) {
g_helper()->mutex.unlock();
return; return;
} }
g_helper()->windowIds.removeAll(windowId); g_helper()->windowIds.removeAll(windowId);
g_helper()->mutex.unlock();
static const bool pureQt = usePureQtImplementation(); static const bool pureQt = usePureQtImplementation();
if (pureQt) { if (pureQt) {
FramelessHelperQt::removeWindow(windowId); FramelessHelperQt::removeWindow(windowId);
@ -248,7 +235,6 @@ void FramelessManagerPrivate::removeWindow(const WId windowId)
void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot() void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot()
{ {
const QMutexLocker locker(&g_helper()->mutex);
const SystemTheme currentSystemTheme = Utils::getSystemTheme(); const SystemTheme currentSystemTheme = Utils::getSystemTheme();
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
const DwmColorizationArea currentColorizationArea = Utils::getDwmColorizationArea(); const DwmColorizationArea currentColorizationArea = Utils::getDwmColorizationArea();
@ -276,7 +262,7 @@ void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot()
} }
#endif #endif
// Don't emit the signal if the user has overrided the global theme. // Don't emit the signal if the user has overrided the global theme.
if (notify && (m_overrideTheme.value_or(SystemTheme::Unknown) == SystemTheme::Unknown)) { if (notify && !isThemeOverrided()) {
Q_Q(FramelessManager); Q_Q(FramelessManager);
Q_EMIT q->systemThemeChanged(); Q_EMIT q->systemThemeChanged();
DEBUG.nospace() << "System theme changed. Current theme: " << m_systemTheme DEBUG.nospace() << "System theme changed. Current theme: " << m_systemTheme
@ -290,7 +276,6 @@ void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot()
void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot() void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot()
{ {
const QMutexLocker locker(&g_helper()->mutex);
const QString currentWallpaper = Utils::getWallpaperFilePath(); const QString currentWallpaper = Utils::getWallpaperFilePath();
const WallpaperAspectStyle currentWallpaperAspectStyle = Utils::getWallpaperAspectStyle(); const WallpaperAspectStyle currentWallpaperAspectStyle = Utils::getWallpaperAspectStyle();
bool notify = false; bool notify = false;
@ -324,7 +309,6 @@ bool FramelessManagerPrivate::usePureQtImplementation()
void FramelessManagerPrivate::setOverrideTheme(const SystemTheme theme) void FramelessManagerPrivate::setOverrideTheme(const SystemTheme theme)
{ {
const QMutexLocker locker(&g_helper()->mutex);
if (theme == SystemTheme::Unknown) { if (theme == SystemTheme::Unknown) {
m_overrideTheme = std::nullopt; m_overrideTheme = std::nullopt;
} else { } else {
@ -336,13 +320,11 @@ void FramelessManagerPrivate::setOverrideTheme(const SystemTheme theme)
bool FramelessManagerPrivate::isThemeOverrided() const bool FramelessManagerPrivate::isThemeOverrided() const
{ {
const QMutexLocker locker(&g_helper()->mutex);
return (m_overrideTheme.value_or(SystemTheme::Unknown) != SystemTheme::Unknown); return (m_overrideTheme.value_or(SystemTheme::Unknown) != SystemTheme::Unknown);
} }
void FramelessManagerPrivate::initialize() void FramelessManagerPrivate::initialize()
{ {
const QMutexLocker locker(&g_helper()->mutex);
m_systemTheme = Utils::getSystemTheme(); m_systemTheme = Utils::getSystemTheme();
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
m_colorizationArea = Utils::getDwmColorizationArea(); m_colorizationArea = Utils::getDwmColorizationArea();

View File

@ -585,7 +585,7 @@ void MicaMaterialPrivate::updateMaterialBrush()
static const QImage noiseTexture = QImage(kNoiseImageFilePath); static const QImage noiseTexture = QImage(kNoiseImageFilePath);
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE #endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied); QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied);
QColor fillColor = (Utils::shouldAppsUseDarkMode() ? kDefaultSystemDarkColor : kDefaultSystemLightColor2); QColor fillColor = ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultSystemDarkColor : kDefaultSystemLightColor2);
fillColor.setAlphaF(0.9f); fillColor.setAlphaF(0.9f);
micaTexture.fill(fillColor); micaTexture.fill(fillColor);
QPainter painter(&micaTexture); QPainter painter(&micaTexture);
@ -673,7 +673,7 @@ void MicaMaterialPrivate::prepareGraphicsResources()
QColor MicaMaterialPrivate::systemFallbackColor() QColor MicaMaterialPrivate::systemFallbackColor()
{ {
return (Utils::shouldAppsUseDarkMode() ? kDefaultFallbackColorDark : kDefaultFallbackColorLight); return ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultFallbackColorDark : kDefaultFallbackColorLight);
} }
MicaMaterial::MicaMaterial(QObject *parent) MicaMaterial::MicaMaterial(QObject *parent)