diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index b455d53..a569d6b 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -140,6 +140,8 @@ FRAMELESSHELPER_CORE_API void setDarkModeAllowedForApp(const bool allow = true); FRAMELESSHELPER_CORE_API void bringWindowToFront(const WId windowId); [[nodiscard]] FRAMELESSHELPER_CORE_API QPoint getWindowPlacementOffset(const WId windowId); [[nodiscard]] FRAMELESSHELPER_CORE_API QRect getWindowRestoreGeometry(const WId windowId); +FRAMELESSHELPER_CORE_API void removeMicaWindow(const WId windowId); +FRAMELESSHELPER_CORE_API void removeSysMenuHook(const WId windowId); #endif // Q_OS_WINDOWS #ifdef Q_OS_LINUX diff --git a/src/core/framelesshelper_qt.cpp b/src/core/framelesshelper_qt.cpp index 0a5ce32..b979d9a 100644 --- a/src/core/framelesshelper_qt.cpp +++ b/src/core/framelesshelper_qt.cpp @@ -82,7 +82,7 @@ void FramelessHelperQt::addWindow(FramelessParamsConst params) QtHelperData data = {}; data.params = *params; QWindow *window = params->getWindowHandle(); - // Give it a parent so that it can be deleted even if we forget to do so. + // Give it a parent so that it can be automatically deleted by Qt. data.eventFilter = new FramelessHelperQt(window); g_qtHelper()->data.insert(windowId, data); const auto shouldApplyFramelessFlag = []() -> bool { @@ -119,12 +119,6 @@ void FramelessHelperQt::removeWindow(const WId windowId) if (!g_qtHelper()->data.contains(windowId)) { return; } - if (const auto eventFilter = g_qtHelper()->data.value(windowId).eventFilter) { - if (QWindow * const window = Utils::findWindow(windowId)) { - window->removeEventFilter(eventFilter); - } - delete eventFilter; - } g_qtHelper()->data.remove(windowId); #ifdef Q_OS_MACOS Utils::removeWindowProxy(windowId); diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index e393d7a..0548ca3 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -600,7 +600,7 @@ void FramelessHelperWin::removeWindow(const WId windowId) } ++it; } - if (DestroyWindow(reinterpret_cast(hwnd)) == FALSE) { + if (DestroyWindow(hwnd) == FALSE) { WARNING << Utils::getSystemErrorMessage(kDestroyWindow); } } diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index a2ce720..a1cdbfe 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) # include # include @@ -209,6 +210,7 @@ void FramelessManagerPrivate::addWindow(FramelessParamsConst params) } Utils::installSystemMenuHook(windowId, params); #endif + connect(params->getWindowHandle(), &QWindow::destroyed, FramelessManager::instance(), [windowId](){ removeWindow(windowId); }); } void FramelessManagerPrivate::removeWindow(const WId windowId) @@ -229,7 +231,8 @@ void FramelessManagerPrivate::removeWindow(const WId windowId) if (!pureQt) { FramelessHelperWin::removeWindow(windowId); } - Utils::uninstallSystemMenuHook(windowId); + Utils::removeSysMenuHook(windowId); + Utils::removeMicaWindow(windowId); #endif } diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 0a33d1b..4583ea8 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -2451,4 +2451,28 @@ QRect Utils::getWindowRestoreGeometry(const WId windowId) return rect2qrect(wp.rcNormalPosition).translated(getWindowPlacementOffset(windowId)); } +void Utils::removeMicaWindow(const WId windowId) +{ + Q_ASSERT(windowId); + if (!windowId) { + return; + } + if (!g_utilsHelper()->micaWindowIds.contains(windowId)) { + return; + } + g_utilsHelper()->micaWindowIds.removeAll(windowId); +} + +void Utils::removeSysMenuHook(const WId windowId) +{ + Q_ASSERT(windowId); + if (!windowId) { + return; + } + if (!g_utilsHelper()->data.contains(windowId)) { + return; + } + g_utilsHelper()->data.remove(windowId); +} + FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/windowborderpainter.cpp b/src/core/windowborderpainter.cpp index b123d41..70e626a 100644 --- a/src/core/windowborderpainter.cpp +++ b/src/core/windowborderpainter.cpp @@ -112,20 +112,15 @@ void WindowBorderPainterPrivate::paint(QPainter *painter, const QSize &size, con return; } #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - QList lines = {}; + QList lines = {}; #else - QVector lines = {}; + QVector lines = {}; #endif - const QPoint leftTop = {0, 0}; - // In fact, we should use "size.width() - 1" here in theory but we can't - // because Qt's drawing system has some rounding errors internally and if - // we minus one here we'll get a one pixel gap, so sad. But drawing a line - // with a little extra pixels won't hurt anyway. - const QPoint rightTop = {size.width(), 0}; - // Same here as above: we should use "size.height() - 1" ideally but we - // can't, sadly. - const QPoint rightBottom = {size.width(), size.height()}; - const QPoint leftBottom = {0, size.height()}; + static constexpr const auto gap = qreal(0.5); + const QPointF leftTop = {gap, gap}; + const QPointF rightTop = {qreal(size.width()) - gap, gap}; + const QPointF rightBottom = {qreal(size.width()) - gap, qreal(size.height()) - gap}; + const QPointF leftBottom = {gap, qreal(size.height()) - gap}; const WindowEdges edges = m_edges.value_or(getNativeBorderEdges()); if (edges & WindowEdge::Left) { lines.append({leftBottom, leftTop}); @@ -143,10 +138,7 @@ void WindowBorderPainterPrivate::paint(QPainter *painter, const QSize &size, con return; } painter->save(); - painter->setRenderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); - // We can't enable antialiasing here, because the border is too thin and antialiasing - // will break it's painting. - painter->setRenderHint(QPainter::Antialiasing, false); + painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); QPen pen = {}; pen.setColor([active, this]() -> QColor { QColor color = {};