From 995ff71546e82b479d22bc24f4b53c6aa75e242e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Aug 2023 19:31:23 +0300 Subject: [PATCH] Fix infinite recursion. --- src/libs/vmisc/theme/macutils.h | 10 +++++----- src/libs/vmisc/theme/macutils.mm | 19 ++++++------------- src/libs/vmisc/theme/vtheme.cpp | 28 ++++++++++++++-------------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/libs/vmisc/theme/macutils.h b/src/libs/vmisc/theme/macutils.h index 0cf687c15..aa44cd8a3 100644 --- a/src/libs/vmisc/theme/macutils.h +++ b/src/libs/vmisc/theme/macutils.h @@ -28,10 +28,10 @@ #ifndef MACUTILS_H #define MACUTILS_H -bool NativeMacDarkThemeAvailable(); -bool MacIsInDarkTheme(); -void MacSetToDarkTheme(); -void MacSetToLightTheme(); -void MacSetToAutoTheme(); +bool NSNativeMacDarkThemeAvailable(); +bool NSMacIsInDarkTheme(); +void NSMacSetToDarkTheme(); +void NSMacSetToLightTheme(); +void NSMacSetToAutoTheme(); #endif // MACUTILS_H diff --git a/src/libs/vmisc/theme/macutils.mm b/src/libs/vmisc/theme/macutils.mm index 8fe4461bf..fca7bc3de 100644 --- a/src/libs/vmisc/theme/macutils.mm +++ b/src/libs/vmisc/theme/macutils.mm @@ -30,20 +30,13 @@ #import //--------------------------------------------------------------------------------------------------------------------- -bool NativeMacDarkThemeAvailable() +bool NSNativeMacDarkThemeAvailable() { - if (__builtin_available(macOS 10.14, *)) - { - return true; - } - else - { - return false; - } + return __builtin_available(macOS 10.14, *); } //--------------------------------------------------------------------------------------------------------------------- -bool MacIsInDarkTheme() +bool NSMacIsInDarkTheme() { if (__builtin_available(macOS 10.14, *)) { @@ -55,7 +48,7 @@ bool MacIsInDarkTheme() } //--------------------------------------------------------------------------------------------------------------------- -void MacSetToDarkTheme() +void NSMacSetToDarkTheme() { // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code if (__builtin_available(macOS 10.14, *)) @@ -65,7 +58,7 @@ void MacSetToDarkTheme() } //--------------------------------------------------------------------------------------------------------------------- -void MacSetToLightTheme() +void NSMacSetToLightTheme() { // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code if (__builtin_available(macOS 10.14, *)) @@ -75,7 +68,7 @@ void MacSetToLightTheme() } //--------------------------------------------------------------------------------------------------------------------- -void MacSetToAutoTheme() +void NSMacSetToAutoTheme() { if (__builtin_available(macOS 10.14, *)) { diff --git a/src/libs/vmisc/theme/vtheme.cpp b/src/libs/vmisc/theme/vtheme.cpp index 79cb63af2..07c2150fc 100644 --- a/src/libs/vmisc/theme/vtheme.cpp +++ b/src/libs/vmisc/theme/vtheme.cpp @@ -168,7 +168,7 @@ auto NativeWindowsDarkThemeAvailable() -> bool #if defined(Q_OS_MACX) auto NativeMacDarkThemeAvailable() -> bool { - return NativeMacDarkThemeAvailable(); + return NSNativeMacDarkThemeAvailable(); } #endif @@ -219,7 +219,7 @@ void ActivateDefaultTheme() qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) #if defined(Q_OS_MACX) - MacSetToAutoTheme(); + NSMacSetToAutoTheme(); #endif } @@ -261,7 +261,7 @@ void VTheme::StoreDefaultThemeName(const QString &themeName) auto VTheme::NativeDarkThemeAvailable() -> bool { #if defined(Q_OS_MACX) - return NativeMacDarkThemeAvailable(); + return NSNativeMacDarkThemeAvailable(); #elif defined(Q_OS_WIN) return NativeWindowsDarkThemeAvailable(); #elif defined(Q_OS_LINUX) @@ -281,7 +281,7 @@ auto VTheme::IsInDarkTheme() -> bool return hints->colorScheme() == Qt::ColorScheme::Dark; #else #if defined(Q_OS_MACX) - return MacIsInDarkTheme(); + return NSMacIsInDarkTheme(); #elif defined(Q_OS_WIN) QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat); @@ -344,16 +344,16 @@ void VTheme::SetIconTheme() static const char *GENERIC_ICON_TO_CHECK = "document-open"; if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK)) { - // // If there is no default working icon theme then we should - // // use an icon theme that we provide via a .qrc file - // // This case happens under Windows and Mac OS X - // // This does not happen under GNOME or KDE + // If there is no default working icon theme then we should + // use an icon theme that we provide via a .qrc file + // This case happens under Windows and Mac OS X + // This does not happen under GNOME or KDE - // #if defined(Q_OS_MACX) - // QIcon::setThemeName(QStringLiteral("La-Sierra-%1").arg(themePrefix)); - // #else +#if defined(Q_OS_MACX) + QIcon::setThemeName(QStringLiteral("La-Sierra-%1").arg(themePrefix)); +#else QIcon::setThemeName(QStringLiteral("Eleven-%1").arg(themePrefix)); - // #endif +#endif } else { @@ -386,7 +386,7 @@ void VTheme::InitThemeMode() if (IsInDarkTheme()) { #if defined(Q_OS_MACX) - MacSetToLightTheme(); + NSMacSetToLightTheme(); #else ActivateCustomLightTheme(); #endif @@ -404,7 +404,7 @@ void VTheme::InitThemeMode() if (!IsInDarkTheme()) { #if defined(Q_OS_MACX) - MacSetToDarkTheme(); + NSMacSetToDarkTheme(); #else ActivateCustomDarkTheme(); #endif