diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index f772f55..dcb8363 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -108,7 +108,7 @@ QT_END_NAMESPACE #endif #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) - using namespace Qt::Literals::StringLiterals; + using namespace Qt::StringLiterals; #endif #ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index 5620a43..0aa71ea 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -68,6 +68,7 @@ FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter( [[nodiscard]] FRAMELESSHELPER_CORE_API QString getWallpaperFilePath(); [[nodiscard]] FRAMELESSHELPER_CORE_API Global::WallpaperAspectStyle getWallpaperAspectStyle(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isBlurBehindWindowSupported(); +FRAMELESSHELPER_CORE_API void registerThemeChangeNotification(); #ifdef Q_OS_WINDOWS [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowsVersionOrGreater(const Global::WindowsVersion version); @@ -121,7 +122,6 @@ FRAMELESSHELPER_CORE_API void setQtDarkModeAwareEnabled(const bool enable, const #ifdef Q_OS_LINUX [[nodiscard]] FRAMELESSHELPER_CORE_API bool shouldAppsUseDarkMode_linux(); [[nodiscard]] FRAMELESSHELPER_CORE_API QColor getWmThemeColor(); -FRAMELESSHELPER_CORE_API void registerThemeChangeNotification(); #endif // Q_OS_LINUX #ifdef Q_OS_MACOS diff --git a/src/core/framelesshelpercore_global.cpp b/src/core/framelesshelpercore_global.cpp index 3b528aa..6f6f063 100644 --- a/src/core/framelesshelpercore_global.cpp +++ b/src/core/framelesshelpercore_global.cpp @@ -66,16 +66,6 @@ # endif #endif -#ifdef Q_OS_LINUX -static constexpr const char QT_QPA_ENV_VAR[] = "QT_QPA_PLATFORM"; -FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb) -#endif - -#ifdef Q_OS_MACOS -static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER"; -FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ValueOne, "1") -#endif - FRAMELESSHELPER_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcCoreGlobal, "wangwenx190.framelesshelper.core.global") @@ -86,6 +76,15 @@ Q_LOGGING_CATEGORY(lcCoreGlobal, "wangwenx190.framelesshelper.core.global") using namespace Global; +#ifdef Q_OS_LINUX +[[maybe_unused]] static constexpr const char QT_QPA_ENV_VAR[] = "QT_QPA_PLATFORM"; +FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb) +#endif + +#ifdef Q_OS_MACOS +[[maybe_unused]] static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER"; +#endif + struct CoreData { QMutex mutex; @@ -115,10 +114,8 @@ void initialize() qputenv(QT_QPA_ENV_VAR, kxcb); #endif -#ifdef Q_OS_MACOS - // This has become the default setting since some unknown Qt version, - // check whether we can remove this hack safely or not. - qputenv(MAC_LAYER_ENV_VAR, kValueOne); +#if (defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) + qputenv(MAC_LAYER_ENV_VAR, FRAMELESSHELPER_BYTEARRAY_LITERAL("1")); #endif #ifdef Q_OS_WINDOWS @@ -276,9 +273,6 @@ void registerUninitializeHook(const UninitializeHookCallback &cb) void setApplicationOSThemeAware(const bool enable, const bool pureQuick) { - Q_UNUSED(enable); - Q_UNUSED(pureQuick); - static bool set = false; if (set) { return; @@ -287,9 +281,13 @@ void setApplicationOSThemeAware(const bool enable, const bool pureQuick) #if (defined(Q_OS_WINDOWS) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) Utils::setQtDarkModeAwareEnabled(enable, pureQuick); +#else + Q_UNUSED(enable); + Q_UNUSED(pureQuick); #endif -#if (defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) +#if ((defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) || \ + (defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)))) Utils::registerThemeChangeNotification(); #endif } diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 67e566e..97e2414 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -219,7 +219,7 @@ bool Utils::isThemeChangeEvent(const QEvent * const event) if (!event) { return false; } - // QGuiApplication will only deliver theme change events to top level QWindow(QQuickWindow)s, + // QGuiApplication will only deliver theme change events to top level Q(Quick)Windows, // QWidgets won't get such notifications, no matter whether it's top level widget or not. // QEvent::ThemeChange: Send by the Windows QPA. // QEvent::ApplicationPaletteChange: All other platforms (Linux & macOS). diff --git a/src/core/utils_mac.mm b/src/core/utils_mac.mm index 3279f02..1b174b6 100644 --- a/src/core/utils_mac.mm +++ b/src/core/utils_mac.mm @@ -39,7 +39,8 @@ #include QT_BEGIN_NAMESPACE -[[nodiscard]] Q_GUI_EXPORT QColor qt_mac_toQColor(const NSColor *color); +[[nodiscard]] Q_CORE_EXPORT bool qt_mac_applicationIsInDarkMode(); // Since 5.12 +[[nodiscard]] Q_GUI_EXPORT QColor qt_mac_toQColor(const NSColor *color); // Since 5.8 QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE @@ -499,9 +500,13 @@ bool Utils::isTitleBarColorized() bool Utils::shouldAppsUseDarkMode_macos() { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + return qt_mac_applicationIsInDarkMode(); +#else const auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames: @[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; return [appearance isEqualToString:NSAppearanceNameDarkAqua]; +#endif } bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode, const QColor &color) @@ -573,6 +578,11 @@ bool Utils::isBlurBehindWindowSupported() return result; } +void Utils::registerThemeChangeNotification() +{ + // ### TODO +} + FRAMELESSHELPER_END_NAMESPACE #include "utils_mac.moc" diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index c646622..f18d3bc 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -1870,4 +1870,11 @@ void Utils::setQtDarkModeAwareEnabled(const bool enable, const bool pureQuick) #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) } +void Utils::registerThemeChangeNotification() +{ + // On Windows we don't need to subscribe to the theme change event + // manually. Windows will send the theme change notification to all + // top level windows by default. +} + FRAMELESSHELPER_END_NAMESPACE