diff --git a/src/core/framelessconfig.cpp b/src/core/framelessconfig.cpp index 87cdc81..c98fa33 100644 --- a/src/core/framelessconfig.cpp +++ b/src/core/framelessconfig.cpp @@ -93,7 +93,7 @@ FramelessConfig *FramelessConfig::instance() void FramelessConfig::reload(const bool force) { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); if (g_data()->loaded && !force) { return; } @@ -117,25 +117,25 @@ void FramelessConfig::reload(const bool force) void FramelessConfig::set(const Option option, const bool on) { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); g_data()->options[static_cast(option)] = on; } bool FramelessConfig::isSet(const Option option) const { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); return g_data()->options[static_cast(option)]; } void FramelessConfig::setLoadFromEnvironmentVariablesDisabled(const bool on) { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); g_data()->disableEnvVar = on; } void FramelessConfig::setLoadFromConfigurationFileDisabled(const bool on) { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); g_data()->disableCfgFile = on; } @@ -147,7 +147,7 @@ std::optional FramelessConfig::setInternal(const QString &key, const Q return std::nullopt; } std::optional previous = std::nullopt; - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); if (g_data()->internals.contains(key)) { previous = g_data()->internals.value(key); g_data()->internals.remove(key); @@ -162,7 +162,7 @@ std::optional FramelessConfig::getInternal(const QString &key) const if (key.isEmpty()) { return std::nullopt; } - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); if (g_data()->internals.contains(key)) { return g_data()->internals.value(key); } diff --git a/src/core/framelesshelper_qt.cpp b/src/core/framelesshelper_qt.cpp index 385f1b7..23385dc 100644 --- a/src/core/framelesshelper_qt.cpp +++ b/src/core/framelesshelper_qt.cpp @@ -166,7 +166,7 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event) } break; case QEvent::MouseButtonRelease: { if (button == Qt::LeftButton) { - QMutexLocker locker(&g_qtHelper()->mutex); + const QMutexLocker locker(&g_qtHelper()->mutex); g_qtHelper()->data[windowId].leftButtonPressed = false; } if (button == Qt::RightButton) { @@ -191,12 +191,12 @@ bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event) if (cs == Qt::ArrowCursor) { if (data.cursorShapeChanged) { window->unsetCursor(); - QMutexLocker locker(&g_qtHelper()->mutex); + const QMutexLocker locker(&g_qtHelper()->mutex); g_qtHelper()->data[windowId].cursorShapeChanged = false; } } else { window->setCursor(cs); - QMutexLocker locker(&g_qtHelper()->mutex); + const QMutexLocker locker(&g_qtHelper()->mutex); g_qtHelper()->data[windowId].cursorShapeChanged = true; } } diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 5c839d9..ea9904d 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -257,7 +257,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) WARNING << Utils::getSystemErrorMessage(kTrackMouseEvent); break; } - QMutexLocker locker(&g_win32Helper()->mutex); + const QMutexLocker locker(&g_win32Helper()->mutex); g_win32Helper()->data[parentWindowId].trackingMouse = true; } } break; @@ -265,7 +265,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) case WM_MOUSELEAVE: { // When the mouse leaves the drag rect, make sure to dismiss any hover. releaseButtons(std::nullopt); - QMutexLocker locker(&g_win32Helper()->mutex); + const QMutexLocker locker(&g_win32Helper()->mutex); g_win32Helper()->data[parentWindowId].trackingMouse = false; } break; // NB: *Shouldn't be forwarding these* when they're not over the caption @@ -346,7 +346,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) case WM_NCRBUTTONUP: return SendMessageW(parentWindowHandle, uMsg, wParam, lParam); case WM_DESTROY: { - QMutexLocker locker(&g_win32Helper()->mutex); + const QMutexLocker locker(&g_win32Helper()->mutex); g_win32Helper()->fallbackTitleBarToParentWindowMapping.remove(windowId); if (g_win32Helper()->fallbackTitleBarToParentWindowMapping.count() < 1) { // According to Microsoft Docs, window classes registered by DLLs will @@ -473,7 +473,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) WARNING << "Failed to re-position the fallback title bar window."; return false; } - QMutexLocker locker(&g_win32Helper()->mutex); + const QMutexLocker locker(&g_win32Helper()->mutex); g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId; g_win32Helper()->fallbackTitleBarToParentWindowMapping.insert(fallbackTitleBarWindowId, parentWindowId); return true; diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index 21b01c4..9faaffe 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -152,25 +152,25 @@ QFont FramelessManagerPrivate::getIconFont() SystemTheme FramelessManagerPrivate::systemTheme() const { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); return m_systemTheme; } QColor FramelessManagerPrivate::systemAccentColor() const { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); return m_accentColor; } QString FramelessManagerPrivate::wallpaper() const { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); return m_wallpaper; } WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); return m_wallpaperAspectStyle; } @@ -227,7 +227,7 @@ void FramelessManagerPrivate::addWindow(const SystemParameters ¶ms) void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot() { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); const SystemTheme currentSystemTheme = Utils::getSystemTheme(); #ifdef Q_OS_WINDOWS const DwmColorizationArea currentColorizationArea = Utils::getDwmColorizationArea(); @@ -263,7 +263,7 @@ void FramelessManagerPrivate::notifySystemThemeHasChangedOrNot() void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot() { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); const QString currentWallpaper = Utils::getWallpaperFilePath(); const WallpaperAspectStyle currentWallpaperAspectStyle = Utils::getWallpaperAspectStyle(); bool notify = false; @@ -284,7 +284,7 @@ void FramelessManagerPrivate::notifyWallpaperHasChangedOrNot() void FramelessManagerPrivate::initialize() { - QMutexLocker locker(&g_helper()->mutex); + const QMutexLocker locker(&g_helper()->mutex); m_systemTheme = Utils::getSystemTheme(); #ifdef Q_OS_WINDOWS m_colorizationArea = Utils::getDwmColorizationArea(); diff --git a/src/core/sysapiloader.cpp b/src/core/sysapiloader.cpp index 9e626a5..40fa0c2 100644 --- a/src/core/sysapiloader.cpp +++ b/src/core/sysapiloader.cpp @@ -82,7 +82,7 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function) if (library.isEmpty() || function.isEmpty()) { return false; } - QMutexLocker locker(&m_mutex); + const QMutexLocker locker(&m_mutex); if (m_functionCache.contains(function)) { return m_functionCache.value(function).has_value(); } @@ -103,7 +103,7 @@ QFunctionPointer SysApiLoader::get(const QString &function) if (function.isEmpty()) { return nullptr; } - QMutexLocker locker(&m_mutex); + const QMutexLocker locker(&m_mutex); if (m_functionCache.contains(function)) { const std::optional symbol = m_functionCache.value(function); if (symbol.has_value()) { diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 7c93cf0..67e566e 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -144,6 +144,8 @@ QString Utils::getSystemButtonIconCode(const SystemButtonType button) return QChar(icon.segoe); } #endif + // 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); } diff --git a/src/core/utils_mac.mm b/src/core/utils_mac.mm index 8db135b..f49ab3a 100644 --- a/src/core/utils_mac.mm +++ b/src/core/utils_mac.mm @@ -406,7 +406,7 @@ Q_GLOBAL_STATIC(MacUtilsData, g_macUtilsData); if (!windowId) { return nil; } - QMutexLocker locker(&g_macUtilsData()->mutex); + const QMutexLocker locker(&g_macUtilsData()->mutex); if (!g_macUtilsData()->hash.contains(windowId)) { QWindow * const qwindow = Utils::findWindow(windowId); Q_ASSERT(qwindow); diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index eda156a..a2f9904 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -132,6 +132,7 @@ FRAMELESSHELPER_STRING_CONSTANT(AccentColor) FRAMELESSHELPER_STRING_CONSTANT(GetScaleFactorForMonitor) FRAMELESSHELPER_STRING_CONSTANT(WallpaperStyle) FRAMELESSHELPER_STRING_CONSTANT(TileWallpaper) +FRAMELESSHELPER_STRING_CONSTANT(UnregisterClassW) struct Win32UtilsHelperData { @@ -176,15 +177,15 @@ static const QHash g_systemMetricsTable = { {SM_CXPADDEDBORDER, { 4, 5, 5, 6, 6, 6, 7, 7, 8, 9, 10, 12, 14, 16, 18, 20}} }; -template +template class HumbleComPtr { Q_DISABLE_COPY_MOVE(HumbleComPtr) public: - HumbleComPtr() = default; + explicit HumbleComPtr() = default; - HumbleComPtr(std::nullptr_t ptr) + explicit HumbleComPtr(std::nullptr_t ptr) { Q_UNUSED(ptr); } @@ -231,6 +232,35 @@ private: T *p = nullptr; }; +struct WindowClassCleaner +{ + explicit WindowClassCleaner(const std::wstring &name) + { + this->name = name; + } + + ~WindowClassCleaner() + { + if (name.empty()) { + return; + } + const HINSTANCE instance = GetModuleHandleW(nullptr); + if (!instance) { + WARNING << Utils::getSystemErrorMessage(kGetModuleHandleW); + return; + } + if (UnregisterClassW(name.c_str(), instance) == FALSE) { + WARNING << Utils::getSystemErrorMessage(kUnregisterClassW); + } + } + +private: + Q_DISABLE_COPY_MOVE(WindowClassCleaner) + +private: + std::wstring name = {}; +}; + [[nodiscard]] static inline QString hkcuRegistryKey() { static const QString key = FRAMELESSHELPER_STRING_LITERAL("HKEY_CURRENT_USER"); @@ -274,6 +304,7 @@ private: WARNING << Utils::getSystemErrorMessage(kRegisterClassExW); return nullptr; } + static const auto cleaner = WindowClassCleaner(kDummyWindowClassName); } const HWND window = CreateWindowExW(0, kDummyWindowClassName, nullptr, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, instance, nullptr); @@ -961,7 +992,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal) HRESULT(WINAPI *)(D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **); const auto pD2D1CreateFactory = reinterpret_cast(SysApiLoader::instance()->get(kD2D1CreateFactory)); - HumbleComPtr d2dFactory = nullptr; + auto d2dFactory = HumbleComPtr(nullptr); HRESULT hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), nullptr, reinterpret_cast(&d2dFactory)); if (SUCCEEDED(hr)) { @@ -1279,7 +1310,7 @@ void Utils::installSystemMenuHook(const WId windowId, if (!windowId || !isWindowFixedSize) { return; } - QMutexLocker locker(&g_utilsHelper()->mutex); + const QMutexLocker locker(&g_utilsHelper()->mutex); if (g_utilsHelper()->data.contains(windowId)) { return; } @@ -1311,7 +1342,7 @@ void Utils::uninstallSystemMenuHook(const WId windowId) if (!windowId) { return; } - QMutexLocker locker(&g_utilsHelper()->mutex); + const QMutexLocker locker(&g_utilsHelper()->mutex); if (!g_utilsHelper()->data.contains(windowId)) { return; } diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index 82ba11f..2344b3d 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -129,7 +129,7 @@ void FramelessQuickHelperPrivate::setTitleBarItem(QQuickItem *value) if (!value) { return; } - QMutexLocker locker(&g_quickHelper()->mutex); + const QMutexLocker locker(&g_quickHelper()->mutex); QuickHelperData *data = getWindowDataMutable(); if (!data) { return; @@ -225,7 +225,7 @@ void FramelessQuickHelperPrivate::setSystemButton(QQuickItem *item, const QuickG if (!item || (buttonType == QuickGlobal::SystemButtonType::Unknown)) { return; } - QMutexLocker locker(&g_quickHelper()->mutex); + const QMutexLocker locker(&g_quickHelper()->mutex); QuickHelperData *data = getWindowDataMutable(); if (!data) { return; @@ -259,7 +259,7 @@ void FramelessQuickHelperPrivate::setHitTestVisible(QQuickItem *item, const bool if (!item) { return; } - QMutexLocker locker(&g_quickHelper()->mutex); + const QMutexLocker locker(&g_quickHelper()->mutex); QuickHelperData *data = getWindowDataMutable(); if (!data) { return; @@ -662,7 +662,7 @@ QuickHelperData FramelessQuickHelperPrivate::getWindowData() const return {}; } const WId windowId = window->winId(); - QMutexLocker locker(&g_quickHelper()->mutex); + const QMutexLocker locker(&g_quickHelper()->mutex); if (!g_quickHelper()->data.contains(windowId)) { g_quickHelper()->data.insert(windowId, {}); } diff --git a/src/quick/quickmicamaterial.cpp b/src/quick/quickmicamaterial.cpp index ee68d9e..a51820e 100644 --- a/src/quick/quickmicamaterial.cpp +++ b/src/quick/quickmicamaterial.cpp @@ -114,7 +114,7 @@ void WallpaperImageNode::initialize() void WallpaperImageNode::maybeGenerateWallpaperImageCache(const bool force) { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); if (!m_pixmapCache.isNull() && !force) { return; } @@ -130,7 +130,7 @@ void WallpaperImageNode::maybeGenerateWallpaperImageCache(const bool force) void WallpaperImageNode::maybeUpdateWallpaperImageClipRect() { - QMutexLocker locker(&g_data()->mutex); + const QMutexLocker locker(&g_data()->mutex); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) const QSizeF itemSize = m_item->size(); #else diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 41a8f5a..3f7d27c 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -236,7 +236,7 @@ void FramelessWidgetsHelperPrivate::setTitleBarWidget(QWidget *widget) if (!widget) { return; } - QMutexLocker locker(&g_widgetsHelper()->mutex); + const QMutexLocker locker(&g_widgetsHelper()->mutex); WidgetsHelperData *data = getWindowDataMutable(); if (!data) { return; @@ -259,7 +259,7 @@ void FramelessWidgetsHelperPrivate::setHitTestVisible(QWidget *widget, const boo if (!widget) { return; } - QMutexLocker locker(&g_widgetsHelper()->mutex); + const QMutexLocker locker(&g_widgetsHelper()->mutex); WidgetsHelperData *data = getWindowDataMutable(); if (!data) { return; @@ -378,7 +378,7 @@ WidgetsHelperData FramelessWidgetsHelperPrivate::getWindowData() const return {}; } const WId windowId = window->winId(); - QMutexLocker locker(&g_widgetsHelper()->mutex); + const QMutexLocker locker(&g_widgetsHelper()->mutex); if (!g_widgetsHelper()->data.contains(windowId)) { g_widgetsHelper()->data.insert(windowId, {}); } @@ -672,7 +672,7 @@ void FramelessWidgetsHelperPrivate::setSystemButton(QWidget *widget, const Syste if (!widget || (buttonType == SystemButtonType::Unknown)) { return; } - QMutexLocker locker(&g_widgetsHelper()->mutex); + const QMutexLocker locker(&g_widgetsHelper()->mutex); WidgetsHelperData *data = getWindowDataMutable(); if (!data) { return; diff --git a/tools/dpitester/main.cpp b/tools/dpitester/main.cpp index 9b6b168..3639002 100644 --- a/tools/dpitester/main.cpp +++ b/tools/dpitester/main.cpp @@ -424,7 +424,7 @@ EXTERN_C int WINAPI wmain(int argc, wchar_t *argv[]) for (int i = 0; i != DPI_COUNT; ++i) { const auto entry = DPI_TABLE[i]; const auto percent = int(std::round(entry.DevicePixelRatio * double(100))); - text += L" const int DPI_" + std::to_wstring(entry.DotsPerInch) + L" = 0;"; + text += L" int DPI_" + std::to_wstring(entry.DotsPerInch) + L" = 0;"; text += L" // " + std::to_wstring(percent) + L"%. The scale factor for the device is " + std::to_wstring(entry.DevicePixelRatio) + L"x.\n"; if (i == (DPI_COUNT - 1)) {