Fix infinite recursion.

This commit is contained in:
Roman Telezhynskyi 2023-08-05 19:31:23 +03:00
parent 45c0b1cf1f
commit 995ff71546
3 changed files with 25 additions and 32 deletions

View File

@ -28,10 +28,10 @@
#ifndef MACUTILS_H #ifndef MACUTILS_H
#define MACUTILS_H #define MACUTILS_H
bool NativeMacDarkThemeAvailable(); bool NSNativeMacDarkThemeAvailable();
bool MacIsInDarkTheme(); bool NSMacIsInDarkTheme();
void MacSetToDarkTheme(); void NSMacSetToDarkTheme();
void MacSetToLightTheme(); void NSMacSetToLightTheme();
void MacSetToAutoTheme(); void NSMacSetToAutoTheme();
#endif // MACUTILS_H #endif // MACUTILS_H

View File

@ -30,20 +30,13 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool NativeMacDarkThemeAvailable() bool NSNativeMacDarkThemeAvailable()
{ {
if (__builtin_available(macOS 10.14, *)) return __builtin_available(macOS 10.14, *);
{
return true;
}
else
{
return false;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool MacIsInDarkTheme() bool NSMacIsInDarkTheme()
{ {
if (__builtin_available(macOS 10.14, *)) 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 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
if (__builtin_available(macOS 10.14, *)) 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 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
if (__builtin_available(macOS 10.14, *)) if (__builtin_available(macOS 10.14, *))
@ -75,7 +68,7 @@ void MacSetToLightTheme()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MacSetToAutoTheme() void NSMacSetToAutoTheme()
{ {
if (__builtin_available(macOS 10.14, *)) if (__builtin_available(macOS 10.14, *))
{ {

View File

@ -168,7 +168,7 @@ auto NativeWindowsDarkThemeAvailable() -> bool
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
auto NativeMacDarkThemeAvailable() -> bool auto NativeMacDarkThemeAvailable() -> bool
{ {
return NativeMacDarkThemeAvailable(); return NSNativeMacDarkThemeAvailable();
} }
#endif #endif
@ -219,7 +219,7 @@ void ActivateDefaultTheme()
qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
MacSetToAutoTheme(); NSMacSetToAutoTheme();
#endif #endif
} }
@ -261,7 +261,7 @@ void VTheme::StoreDefaultThemeName(const QString &themeName)
auto VTheme::NativeDarkThemeAvailable() -> bool auto VTheme::NativeDarkThemeAvailable() -> bool
{ {
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
return NativeMacDarkThemeAvailable(); return NSNativeMacDarkThemeAvailable();
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
return NativeWindowsDarkThemeAvailable(); return NativeWindowsDarkThemeAvailable();
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
@ -281,7 +281,7 @@ auto VTheme::IsInDarkTheme() -> bool
return hints->colorScheme() == Qt::ColorScheme::Dark; return hints->colorScheme() == Qt::ColorScheme::Dark;
#else #else
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
return MacIsInDarkTheme(); return NSMacIsInDarkTheme();
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
QSettings::NativeFormat); QSettings::NativeFormat);
@ -344,16 +344,16 @@ void VTheme::SetIconTheme()
static const char *GENERIC_ICON_TO_CHECK = "document-open"; static const char *GENERIC_ICON_TO_CHECK = "document-open";
if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK)) if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK))
{ {
// // If there is no default working icon theme then we should // If there is no default working icon theme then we should
// // use an icon theme that we provide via a .qrc file // use an icon theme that we provide via a .qrc file
// // This case happens under Windows and Mac OS X // This case happens under Windows and Mac OS X
// // This does not happen under GNOME or KDE // This does not happen under GNOME or KDE
// #if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
// QIcon::setThemeName(QStringLiteral("La-Sierra-%1").arg(themePrefix)); QIcon::setThemeName(QStringLiteral("La-Sierra-%1").arg(themePrefix));
// #else #else
QIcon::setThemeName(QStringLiteral("Eleven-%1").arg(themePrefix)); QIcon::setThemeName(QStringLiteral("Eleven-%1").arg(themePrefix));
// #endif #endif
} }
else else
{ {
@ -386,7 +386,7 @@ void VTheme::InitThemeMode()
if (IsInDarkTheme()) if (IsInDarkTheme())
{ {
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
MacSetToLightTheme(); NSMacSetToLightTheme();
#else #else
ActivateCustomLightTheme(); ActivateCustomLightTheme();
#endif #endif
@ -404,7 +404,7 @@ void VTheme::InitThemeMode()
if (!IsInDarkTheme()) if (!IsInDarkTheme())
{ {
#if defined(Q_OS_MACX) #if defined(Q_OS_MACX)
MacSetToDarkTheme(); NSMacSetToDarkTheme();
#else #else
ActivateCustomDarkTheme(); ActivateCustomDarkTheme();
#endif #endif