minor fixes

This commit is contained in:
Yuhang Zhao 2023-06-02 14:51:12 +08:00
parent f7f8fc3dd0
commit 1e754c1612
6 changed files with 40 additions and 25 deletions

View File

@ -140,6 +140,8 @@ FRAMELESSHELPER_CORE_API void setDarkModeAllowedForApp(const bool allow = true);
FRAMELESSHELPER_CORE_API void bringWindowToFront(const WId windowId); FRAMELESSHELPER_CORE_API void bringWindowToFront(const WId windowId);
[[nodiscard]] FRAMELESSHELPER_CORE_API QPoint getWindowPlacementOffset(const WId windowId); [[nodiscard]] FRAMELESSHELPER_CORE_API QPoint getWindowPlacementOffset(const WId windowId);
[[nodiscard]] FRAMELESSHELPER_CORE_API QRect getWindowRestoreGeometry(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 #endif // Q_OS_WINDOWS
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX

View File

@ -82,7 +82,7 @@ void FramelessHelperQt::addWindow(FramelessParamsConst params)
QtHelperData data = {}; QtHelperData data = {};
data.params = *params; data.params = *params;
QWindow *window = params->getWindowHandle(); 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); data.eventFilter = new FramelessHelperQt(window);
g_qtHelper()->data.insert(windowId, data); g_qtHelper()->data.insert(windowId, data);
const auto shouldApplyFramelessFlag = []() -> bool { const auto shouldApplyFramelessFlag = []() -> bool {
@ -119,12 +119,6 @@ void FramelessHelperQt::removeWindow(const WId windowId)
if (!g_qtHelper()->data.contains(windowId)) { if (!g_qtHelper()->data.contains(windowId)) {
return; 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); g_qtHelper()->data.remove(windowId);
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
Utils::removeWindowProxy(windowId); Utils::removeWindowProxy(windowId);

View File

@ -600,7 +600,7 @@ void FramelessHelperWin::removeWindow(const WId windowId)
} }
++it; ++it;
} }
if (DestroyWindow(reinterpret_cast<HWND>(hwnd)) == FALSE) { if (DestroyWindow(hwnd) == FALSE) {
WARNING << Utils::getSystemErrorMessage(kDestroyWindow); WARNING << Utils::getSystemErrorMessage(kDestroyWindow);
} }
} }

View File

@ -36,6 +36,7 @@
#include <QtCore/qcoreapplication.h> #include <QtCore/qcoreapplication.h>
#include <QtCore/qloggingcategory.h> #include <QtCore/qloggingcategory.h>
#include <QtGui/qfontdatabase.h> #include <QtGui/qfontdatabase.h>
#include <QtGui/qwindow.h>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
# include <QtGui/qguiapplication.h> # include <QtGui/qguiapplication.h>
# include <QtGui/qstylehints.h> # include <QtGui/qstylehints.h>
@ -209,6 +210,7 @@ void FramelessManagerPrivate::addWindow(FramelessParamsConst params)
} }
Utils::installSystemMenuHook(windowId, params); Utils::installSystemMenuHook(windowId, params);
#endif #endif
connect(params->getWindowHandle(), &QWindow::destroyed, FramelessManager::instance(), [windowId](){ removeWindow(windowId); });
} }
void FramelessManagerPrivate::removeWindow(const WId windowId) void FramelessManagerPrivate::removeWindow(const WId windowId)
@ -229,7 +231,8 @@ void FramelessManagerPrivate::removeWindow(const WId windowId)
if (!pureQt) { if (!pureQt) {
FramelessHelperWin::removeWindow(windowId); FramelessHelperWin::removeWindow(windowId);
} }
Utils::uninstallSystemMenuHook(windowId); Utils::removeSysMenuHook(windowId);
Utils::removeMicaWindow(windowId);
#endif #endif
} }

View File

@ -2451,4 +2451,28 @@ QRect Utils::getWindowRestoreGeometry(const WId windowId)
return rect2qrect(wp.rcNormalPosition).translated(getWindowPlacementOffset(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 FRAMELESSHELPER_END_NAMESPACE

View File

@ -112,20 +112,15 @@ void WindowBorderPainterPrivate::paint(QPainter *painter, const QSize &size, con
return; return;
} }
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QList<QLine> lines = {}; QList<QLineF> lines = {};
#else #else
QVector<QLine> lines = {}; QVector<QLineF> lines = {};
#endif #endif
const QPoint leftTop = {0, 0}; static constexpr const auto gap = qreal(0.5);
// In fact, we should use "size.width() - 1" here in theory but we can't const QPointF leftTop = {gap, gap};
// because Qt's drawing system has some rounding errors internally and if const QPointF rightTop = {qreal(size.width()) - gap, gap};
// we minus one here we'll get a one pixel gap, so sad. But drawing a line const QPointF rightBottom = {qreal(size.width()) - gap, qreal(size.height()) - gap};
// with a little extra pixels won't hurt anyway. const QPointF leftBottom = {gap, qreal(size.height()) - gap};
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()};
const WindowEdges edges = m_edges.value_or(getNativeBorderEdges()); const WindowEdges edges = m_edges.value_or(getNativeBorderEdges());
if (edges & WindowEdge::Left) { if (edges & WindowEdge::Left) {
lines.append({leftBottom, leftTop}); lines.append({leftBottom, leftTop});
@ -143,10 +138,7 @@ void WindowBorderPainterPrivate::paint(QPainter *painter, const QSize &size, con
return; return;
} }
painter->save(); painter->save();
painter->setRenderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); painter->setRenderHints(QPainter::Antialiasing | 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);
QPen pen = {}; QPen pen = {};
pen.setColor([active, this]() -> QColor { pen.setColor([active, this]() -> QColor {
QColor color = {}; QColor color = {};