diff --git a/src/Lib/HostOsInfo.cc b/src/Lib/HostOsInfo.cc index 48f5bc6d82b88abad196be8db98ad895555cd467..b6628feaf875fd22881c405140a72662fe10bb9f 100644 --- a/src/Lib/HostOsInfo.cc +++ b/src/Lib/HostOsInfo.cc @@ -1,10 +1,13 @@ #include "HostOsInfo.hh" #if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB) +#define VIVY_OPENGL 1 #include <QOpenGLContext> +#else +#define VIVY_OPENGL 0 #endif -#ifdef Q_OS_WIN +#if VIVY_WIN32 #include <qt_windows.h> #endif @@ -13,7 +16,7 @@ using namespace Vivy::Utils; Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive; bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false; -#ifdef Q_OS_WIN +#if VIVY_WIN32 static WORD hostProcessorArchitecture() { @@ -26,7 +29,7 @@ hostProcessorArchitecture() HostOsInfo::HostArchitecture HostOsInfo::hostArchitecture() { -#ifdef Q_OS_WIN +#if VIVY_WIN32 static const WORD processorArchitecture = hostProcessorArchitecture(); switch (processorArchitecture) { case PROCESSOR_ARCHITECTURE_AMD64: return HostOsInfo::HostArchitectureAMD64; @@ -54,16 +57,15 @@ HostOsInfo::unsetOverrideFileNameCaseSensitivity() } bool -HostOsInfo::canCreateOpenGLContext(QString *errorMessage) +HostOsInfo::canCreateOpenGLContext([[maybe_unused]] QString *errorMessage) { -#if defined(QT_NO_OPENGL) || !defined(QT_GUI_LIB) - Q_UNUSED(errorMessage) - return false; -#else +#if VIVY_OPENGL static const bool canCreate = QOpenGLContext().create(); if (!canCreate) *errorMessage = QCoreApplication::translate("Utils::HostOsInfo", "Cannot create OpenGL context."); return canCreate; +#else + return false; #endif } diff --git a/src/Lib/HostOsInfo.hh b/src/Lib/HostOsInfo.hh index 97b2889621b1348bfdea6b5c88afd68db1090417..af00e94b2d361aba557445eab4835236b5a45cdb 100644 --- a/src/Lib/HostOsInfo.hh +++ b/src/Lib/HostOsInfo.hh @@ -4,27 +4,47 @@ #ifdef Q_OS_WIN #define VIVY_HOST_EXE_SUFFIX VIVY_WIN_EXE_SUFFIX +#define VIVY_WIN32 1 #else #define VIVY_HOST_EXE_SUFFIX "" +#define VIVY_WIN32 0 #endif // Q_OS_WIN +// Detect MacOS +#if defined(Q_OS_DARWIN) || defined(Q_OS_MACOS) +#define VIVY_MACOS 1 +#else +#define VIVY_MACOS 0 +#endif + +// Detect Linux or UNIX +#if defined(Q_OS_LINUX) +#define VIVY_LINUX 1 +#define VIVY_UNIX 1 +#elif defined(Q_OS_UNIX) +#define VIVY_LINUX 0 +#define VIVY_UNIX 1 +#else +#define VIVY_LINUX 0 +#define VIVY_UNIX 0 +#endif + namespace Vivy::Utils { class HostOsInfo { public: static constexpr OsType hostOs() { -#if defined(Q_OS_WIN) - return OsTypeWindows; -#elif defined(Q_OS_LINUX) - return OsTypeLinux; -#elif defined(Q_OS_MAC) - return OsTypeMac; -#elif defined(Q_OS_UNIX) - return OsTypeOtherUnix; -#else - return OsTypeOther; -#endif + if constexpr (VIVY_WIN32) + return OsTypeWindows; + else if constexpr (VIVY_LINUX) + return OsTypeLinux; + else if constexpr (VIVY_MACOS) + return OsTypeMac; + else if constexpr (VIVY_UNIX) + return OsTypeOtherUnix; + else + return OsTypeOther; } enum HostArchitecture { @@ -39,14 +59,7 @@ public: static constexpr bool isWindowsHost() { return hostOs() == OsTypeWindows; } static constexpr bool isLinuxHost() { return hostOs() == OsTypeLinux; } static constexpr bool isMacHost() { return hostOs() == OsTypeMac; } - static constexpr bool isAnyUnixHost() - { -#ifdef Q_OS_UNIX - return true; -#else - return false; -#endif - } + static constexpr bool isAnyUnixHost() { return VIVY_UNIX; } static QString withExecutableSuffix(const QString &executable) { diff --git a/src/UI/Theme/Theme.cc b/src/UI/Theme/Theme.cc index 60d5a103b79b7e8b1d60b5e9a099911dd5fd6848..31c53f16d5c53f74915227b758329ce52fa42f3c 100644 --- a/src/UI/Theme/Theme.cc +++ b/src/UI/Theme/Theme.cc @@ -50,11 +50,14 @@ systemUsesDarkMode() noexcept const auto setting = QSettings(regkey, QSettings::NativeFormat).value("AppsUseLightTheme").toInt(&ok); return ok && setting == 0; - } else if (Utils::HostOsInfo::isMacHost()) { + } + + else if constexpr (Utils::HostOsInfo::isMacHost()) return false; - } else if (Utils::HostOsInfo::isLinuxHost()) { + + else if constexpr (Utils::HostOsInfo::isLinuxHost()) return true; - } + return false; } diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index d0a25b8bc48e85138ede3015397f00ec43de1977..4d67f0ec94850af9a26ec6b319108f0c6a3ef614 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -42,6 +42,7 @@ #endif #include "Lib/Log.hh" +#include "Lib/HostOsInfo.hh" #include "UI/Theme/Theme.hh" namespace Vivy