From 5c7434ea3564b69f8484512bbe6332ccad9f4fe1 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 1 Apr 2022 15:18:44 +0800 Subject: [PATCH] misc: refactor, take 2 add byte array literals handling Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .../Core/framelesshelpercore_global.h | 23 +++++++++++++++---- src/core/framelesshelper_win.cpp | 4 ++-- src/core/utils_win.cpp | 6 ++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index 76d85ae..0d4b9b7 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -90,21 +90,34 @@ using NATIVE_EVENT_RESULT_TYPE = long; # define QUtf8String(str) QString::fromUtf8(str) #endif -#ifndef QU8Str -# define QU8Str(str) QUtf8String(str) +#ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL +# if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) +# define FRAMELESSHELPER_BYTEARRAY_LITERAL(ba) ba##_qba +# else +# define FRAMELESSHELPER_BYTEARRAY_LITERAL(ba) QByteArrayLiteral(ba) +# endif #endif #ifndef FRAMELESSHELPER_STRING_LITERAL -# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) # define FRAMELESSHELPER_STRING_LITERAL(str) u##str##_qs # else # define FRAMELESSHELPER_STRING_LITERAL(str) QStringLiteral(str) # endif #endif +#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2 +# define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \ + [[maybe_unused]] static const auto k##name = FRAMELESSHELPER_BYTEARRAY_LITERAL(ba); +#endif + #ifndef FRAMELESSHELPER_STRING_CONSTANT2 # define FRAMELESSHELPER_STRING_CONSTANT2(name, str) \ - [[maybe_unused]] static const QString k##name = FRAMELESSHELPER_STRING_LITERAL(str); + [[maybe_unused]] static const auto k##name = FRAMELESSHELPER_STRING_LITERAL(str); +#endif + +#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT +# define FRAMELESSHELPER_BYTEARRAY_CONSTANT(ba) FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ba, #ba) #endif #ifndef FRAMELESSHELPER_STRING_CONSTANT @@ -112,7 +125,7 @@ using NATIVE_EVENT_RESULT_TYPE = long; #endif #ifndef FRAMELESSHELPER_NAMESPACE -# define FRAMELESSHELPER_NAMESPACE __flh_ns +# define FRAMELESSHELPER_NAMESPACE __wwx190_flh_ns #endif #ifndef FRAMELESSHELPER_BEGIN_NAMESPACE diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 1744131..c3ec518 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -52,8 +52,8 @@ struct Win32Helper Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) -static const QByteArray kWin32MessageTypeName = QByteArrayLiteral("windows_generic_MSG"); -static const QString qThemeSettingChangeEventName = QU8Str(kThemeSettingChangeEventName); +FRAMELESSHELPER_BYTEARRAY_CONSTANT2(Win32MessageTypeName, "windows_generic_MSG") +static const QString qThemeSettingChangeEventName = QUtf8String(kThemeSettingChangeEventName); FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow) FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW) FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient) diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index fe98327..f0c789d 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -70,9 +70,9 @@ struct Win32UtilsHelper Q_GLOBAL_STATIC(Win32UtilsHelper, g_utilsHelper) -static const QString qDwmRegistryKey = QU8Str(kDwmRegistryKey); -static const QString qPersonalizeRegistryKey = QU8Str(kPersonalizeRegistryKey); -static const QString qDwmColorKeyName = QU8Str(kDwmColorKeyName); +static const QString qDwmRegistryKey = QUtf8String(kDwmRegistryKey); +static const QString qPersonalizeRegistryKey = QUtf8String(kPersonalizeRegistryKey); +static const QString qDwmColorKeyName = QUtf8String(kDwmColorKeyName); FRAMELESSHELPER_STRING_CONSTANT2(SuccessMessageText, "The operation completed successfully.") FRAMELESSHELPER_STRING_CONSTANT2(FormatMessageEmptyResult, "\"FormatMessageW()\" returned empty string.") FRAMELESSHELPER_STRING_CONSTANT2(ErrorMessageTemplate, "Function \"%1()\" failed with error code %2: %3.")