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);
[[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

View File

@ -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);

View File

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

View File

@ -36,6 +36,7 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qloggingcategory.h>
#include <QtGui/qfontdatabase.h>
#include <QtGui/qwindow.h>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
# include <QtGui/qguiapplication.h>
# include <QtGui/qstylehints.h>
@ -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
}

View File

@ -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

View File

@ -112,20 +112,15 @@ void WindowBorderPainterPrivate::paint(QPainter *painter, const QSize &size, con
return;
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QList<QLine> lines = {};
QList<QLineF> lines = {};
#else
QVector<QLine> lines = {};
QVector<QLineF> 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 = {};