diff --git a/CMakeLists.txt b/CMakeLists.txt index a97ca67..a6fbd0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ option(FRAMELESSHELPER_BUILD_WIDGETS "Build FramelessHelper's Widgets module." O 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) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -163,4 +164,5 @@ message("Build the FramelessHelper::Widgets module: ${FRAMELESSHELPER_BUILD_WIDG 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("#######################################") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fe910e9..6e509da 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -144,6 +144,12 @@ if(FRAMELESSHELPER_BUILD_STATIC) ) endif() +if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE QT_NO_KEYWORDS FRAMELESSHELPER_CORE_LIBRARY diff --git a/src/core/framelesshelpercore_global.cpp b/src/core/framelesshelpercore_global.cpp index 87e1bbc..aee19bc 100644 --- a/src/core/framelesshelpercore_global.cpp +++ b/src/core/framelesshelpercore_global.cpp @@ -94,15 +94,40 @@ FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb) [[maybe_unused]] static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER"; #endif +FRAMELESSHELPER_STRING_CONSTANT2(FramelessHelperLogPrefix, "wangwenx190.framelesshelper.") + struct CoreData { QMutex mutex; QList initHooks = {}; QList uninitHooks = {}; + QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr; }; Q_GLOBAL_STATIC(CoreData, coreData) +[[maybe_unused]] static inline void flhCategoryFilter(QLoggingCategory *category) +{ + Q_ASSERT(category); + if (!category) { + return; + } + coreData()->mutex.lock(); + if (coreData()->oldCategoryFilter) { + coreData()->oldCategoryFilter(category); + } + coreData()->mutex.unlock(); + const QString categoryName = QUtf8String(category->categoryName()); + if (!categoryName.isEmpty() + && categoryName.startsWith(kFramelessHelperLogPrefix, Qt::CaseInsensitive)) { + category->setEnabled(QtInfoMsg, false); + category->setEnabled(QtDebugMsg, false); + category->setEnabled(QtWarningMsg, false); + category->setEnabled(QtCriticalMsg, false); + // QtFatalMsg cannot be changed; it will always remain true. + } +} + namespace FramelessHelper::Core { @@ -114,6 +139,12 @@ void initialize() } inited = true; +#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT + coreData()->mutex.lock(); + coreData()->oldCategoryFilter = QLoggingCategory::installFilter(flhCategoryFilter); + coreData()->mutex.unlock(); +#endif + #ifdef Q_OS_LINUX gtk_init(nullptr, nullptr); #endif diff --git a/src/core/utils_linux.cpp b/src/core/utils_linux.cpp index 8408b37..84c20eb 100644 --- a/src/core/utils_linux.cpp +++ b/src/core/utils_linux.cpp @@ -106,7 +106,7 @@ template return {}; } const auto propertyValue = gtkSetting(propertyName); - const QString result = QString::fromUtf8(propertyValue); + const QString result = QUtf8String(propertyValue); g_free(propertyValue); return result; } diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 0a2ed39..0bccd1b 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -156,6 +156,12 @@ if(FRAMELESSHELPER_BUILD_STATIC) ) endif() +if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE FRAMELESSHELPER_QUICK_LIBRARY ) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index a14a3bb..f35d542 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -95,6 +95,12 @@ if(FRAMELESSHELPER_BUILD_STATIC) ) endif() +if(FRAMELESSHELPER_NO_DEBUG_OUTPUT) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT + ) +endif() + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE QT_NO_KEYWORDS FRAMELESSHELPER_WIDGETS_LIBRARY