diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db0523..4fdb104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ option(FRAMELESSHELPER_BUILD_QUICK "Build FramelessHelper's Quick module." ON) option(FRAMELESSHELPER_BUILD_EXAMPLES "Build FramelessHelper demo applications." ON) option(FRAMELESSHELPER_EXAMPLES_DEPLOYQT "Deploy the Qt framework after building the demo projects." ON) option(FRAMELESSHELPER_NO_DEBUG_OUTPUT "Suppress the debug messages from FramelessHelper." OFF) +option(FRAMELESSHELPER_NO_BUNDLE_RESOURCE "Do not bundle any resources within FramelessHelper." OFF) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -48,7 +49,7 @@ endif() if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE) # MinGW has many bugs when LTO is enabled, and they are all very # hard to workaround, so just don't enable LTO at all for MinGW. - if(NOT MINGW) + if(NOT (MINGW OR FRAMELESSHELPER_BUILD_STATIC)) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) endif() endif() @@ -175,4 +176,5 @@ message("Build the FramelessHelper::Quick module: ${FRAMELESSHELPER_BUILD_QUICK} message("Build the FramelessHelper demo applications: ${FRAMELESSHELPER_BUILD_EXAMPLES}") message("Deploy Qt libraries after compilation: ${FRAMELESSHELPER_EXAMPLES_DEPLOYQT}") message("Suppress debug messages from FramelessHelper: ${FRAMELESSHELPER_NO_DEBUG_OUTPUT}") +message("Do not bundle any resources within FramelessHelper: ${FRAMELESSHELPER_NO_BUNDLE_RESOURCE}") message("#######################################") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6e509da..96d95ed 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -124,18 +124,20 @@ endif() add_library(${PROJECT_NAME}::${SUB_PROJ_NAME} ALIAS ${SUB_PROJ_NAME}) add_library(${PROJECT_NAME}::${SUB_MOD_NAME} ALIAS ${SUB_PROJ_NAME}) -if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) - qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore - PREFIX - "/org.wangwenx190.${PROJECT_NAME}" - FILES - "resources/fonts/Micon.ttf" - "resources/images/noise.png" - ) -else() - target_sources(${SUB_PROJ_NAME} PRIVATE - framelesshelpercore.qrc - ) +if(NOT FRAMELESSHELPER_NO_BUNDLE_RESOURCE) + if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) + qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore + PREFIX + "/org.wangwenx190.${PROJECT_NAME}" + FILES + "resources/fonts/Micon.ttf" + "resources/images/noise.png" + ) + else() + target_sources(${SUB_PROJ_NAME} PRIVATE + framelesshelpercore.qrc + ) + endif() endif() if(FRAMELESSHELPER_BUILD_STATIC) @@ -150,6 +152,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) ) endif() +if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE QT_NO_KEYWORDS FRAMELESSHELPER_CORE_LIBRARY diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index bf718c1..d2ddfe9 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -38,6 +38,7 @@ # include "winverhelper_p.h" #endif +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE // The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // so we wrap it into a separate function outside of the namespace and // then call it instead inside the namespace, that's also the recommended @@ -46,6 +47,7 @@ static inline void initResource() { Q_INIT_RESOURCE(framelesshelpercore); } +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE FRAMELESSHELPER_BEGIN_NAMESPACE @@ -76,16 +78,20 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper) Q_GLOBAL_STATIC(FramelessManager, g_manager) [[maybe_unused]] static constexpr const char kGlobalFlagVarName[] = "__FRAMELESSHELPER__"; + +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb") -#ifdef Q_OS_MACOS - [[maybe_unused]] static constexpr const int kIconFontPointSize = 10; -#else - [[maybe_unused]] static constexpr const int kIconFontPointSize = 8; -#endif +# ifdef Q_OS_MACOS +[[maybe_unused]] static constexpr const int kIconFontPointSize = 10; +# else // !Q_OS_MACOS +[[maybe_unused]] static constexpr const int kIconFontPointSize = 8; +# endif // Q_OS_MACOS +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE [[nodiscard]] static inline QString iconFontFamilyName() { static const auto result = []() -> QString { @@ -96,11 +102,12 @@ FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb") if (WindowsVersionHelper::isWin10OrGreater()) { return kIconFontFamilyName_win10; } -#endif +#endif // Q_OS_WINDOWS return kIconFontFamilyName_common; }(); return result; } +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q) { @@ -134,6 +141,7 @@ const FramelessManagerPrivate *FramelessManagerPrivate::get(const FramelessManag void FramelessManagerPrivate::initializeIconFont() { +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE static bool inited = false; if (inited) { return; @@ -147,10 +155,14 @@ void FramelessManagerPrivate::initializeIconFont() } else { DEBUG << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id); } +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE } QFont FramelessManagerPrivate::getIconFont() { +#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE + return {}; +#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE static const auto font = []() -> QFont { QFont f = {}; f.setFamily(iconFontFamilyName()); @@ -158,6 +170,7 @@ QFont FramelessManagerPrivate::getIconFont() return f; }(); return font; +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE } SystemTheme FramelessManagerPrivate::systemTheme() const diff --git a/src/core/micamaterial.cpp b/src/core/micamaterial.cpp index f34841b..f3145b4 100644 --- a/src/core/micamaterial.cpp +++ b/src/core/micamaterial.cpp @@ -37,6 +37,7 @@ #include #include +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE // The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // so we wrap it into a separate function outside of the namespace and // then call it instead inside the namespace, that's also the recommended @@ -45,6 +46,7 @@ static inline void initResource() { Q_INIT_RESOURCE(framelesshelpercore); } +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE FRAMELESSHELPER_BEGIN_NAMESPACE @@ -562,6 +564,7 @@ void MicaMaterialPrivate::maybeGenerateBlurredWallpaper(const bool force) void MicaMaterialPrivate::updateMaterialBrush() { +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE initResource(); static const QImage noiseTexture = QImage(kNoiseImageFilePath); QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied); @@ -581,6 +584,7 @@ void MicaMaterialPrivate::updateMaterialBrush() Q_Q(MicaMaterial); Q_EMIT q->shouldRedraw(); } +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE } void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos) diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 7d26d77..84dcd31 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -54,6 +54,7 @@ Q_LOGGING_CATEGORY(lcUtilsCommon, "wangwenx190.framelesshelper.core.utils.common using namespace Global; +#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE struct FONT_ICON { quint32 segoe = 0; @@ -69,6 +70,7 @@ static const QHash g_fontIconsTable = { {static_cast(SystemButtonType::Restore), {0xE923, 0xEAE2}}, {static_cast(SystemButtonType::Close), {0xE8BB, 0xEADA}} }; +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos) { @@ -141,23 +143,27 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos) QString Utils::getSystemButtonIconCode(const SystemButtonType button) { +#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE + return {}; +#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE const auto index = static_cast(button); if (!g_fontIconsTable.contains(index)) { WARNING << "FIXME: Add FONT_ICON value for button" << button; return {}; } const FONT_ICON icon = g_fontIconsTable.value(index); -#ifdef Q_OS_WINDOWS +# ifdef Q_OS_WINDOWS // Windows 11: Segoe Fluent Icons (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font) // Windows 10: Segoe MDL2 Assets (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font) // Windows 7~8.1: Micon (http://xtoolkit.github.io/Micon/) if (WindowsVersionHelper::isWin10OrGreater()) { return QChar(icon.segoe); } -#endif +# endif // Q_OS_WINDOWS // We always use Micon on UNIX platforms because Microsoft doesn't allow distributing // the Segoe icon font to other platforms than Windows. return QChar(icon.micon); +#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE } QWindow *Utils::findWindow(const WId windowId) diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 0bccd1b..4096eee 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -162,6 +162,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) ) endif() +if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_QUICK_NO_BUNDLE_RESOURCE + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE FRAMELESSHELPER_QUICK_LIBRARY ) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index f35d542..9274949 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -101,6 +101,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) ) endif() +if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_WIDGETS_NO_BUNDLE_RESOURCE + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE QT_NO_KEYWORDS FRAMELESSHELPER_WIDGETS_LIBRARY