Skip to content

Commit

Permalink
fix: quickwindow close crashed
Browse files Browse the repository at this point in the history
use eventfilter instead of vtablehook(QObject destroy crashed)
  • Loading branch information
kegechen committed Nov 28, 2024
1 parent 50e0707 commit 953444e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions xcb/dnotitlebarwindowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#define protected public
#include <QWindow>
#undef protected
#include "dnotitlebarwindowhelper.h"
#include "vtablehook.h"
#include "utility.h"
#include "dwmsupport.h"
#include "dnativesettings.h"
#include "dplatformintegration.h"

#include <QWindow>
#include <QMouseEvent>
#include <QTimer>
#include <QMetaProperty>
#include <QScreen>
#include <qpa/qplatformwindow.h>
#include <QGuiApplication>
#include <QStyleHints>
#include <QDebug>

#define _DEEPIN_SCISSOR_WINDOW "_DEEPIN_SCISSOR_WINDOW"
Q_DECLARE_METATYPE(QPainterPath)
Expand Down Expand Up @@ -81,9 +79,8 @@ DNoTitlebarWindowHelper::~DNoTitlebarWindowHelper()
{
g_pressPoint.remove(this);

if (VtableHook::hasVtable(m_window)) {
VtableHook::resetVtable(m_window);
}
if (m_enableSystemMove)
m_window->removeEventFilter(this);

mapped.remove(qobject_cast<QWindow*>(parent()));

Expand Down Expand Up @@ -426,9 +423,9 @@ void DNoTitlebarWindowHelper::updateEnableSystemMoveFromProperty()
m_enableSystemMove = !v.isValid() || v.toBool();

if (m_enableSystemMove) {
VtableHook::overrideVfptrFun(m_window, &QWindow::event, this, &DNoTitlebarWindowHelper::windowEvent);
} else if (VtableHook::hasVtable(m_window)) {
VtableHook::resetVfptrFun(m_window, &QWindow::event);
m_window->installEventFilter(this);
} else {
m_window->removeEventFilter(this);
}
}

Expand Down Expand Up @@ -510,9 +507,11 @@ void DNoTitlebarWindowHelper::updateAutoInputMaskByClipPathFromProperty()
updateWindowShape();
}

bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
bool DNoTitlebarWindowHelper::eventFilter(QObject *watched, QEvent *event)
{
QWindow *w = this->window();
QWindow *w = qobject_cast<QWindow *>(watched);
if (!w)
return false;

// get touch begin position
static bool isTouchDown = false;
Expand All @@ -531,7 +530,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
QPointF currentPos = static_cast<QMouseEvent*>(event)->globalPos();
QPointF delta = touchBeginPosition - currentPos;
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return VtableHook::callOriginalFun(w, &QWindow::event, event);
return w->event(event);
}
}

Expand All @@ -549,7 +548,8 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
updateMoveWindow(winId);
}

bool ret = VtableHook::callOriginalFun(w, &QWindow::event, event);
// call first to set accept false(quickwindow)
w->event(event);

// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
Expand All @@ -563,12 +563,12 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
QMouseEvent *me = static_cast<QMouseEvent*>(event);
QRect windowRect = QRect(QPoint(0, 0), w->size());
if (!windowRect.contains(me->windowPos().toPoint())) {
return ret;
return true;
}

QPointF delta = me->globalPos() - g_pressPoint[this];
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return ret;
return true;
}

if (!self->m_windowMoving && self->isEnableSystemMove(winId)) {
Expand All @@ -583,7 +583,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
}
}

return ret;
return true;
}

bool DNoTitlebarWindowHelper::isEnableSystemMove(quint32 winId)
Expand Down
2 changes: 1 addition & 1 deletion xcb/dnotitlebarwindowhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private slots:
Q_SLOT void updateAutoInputMaskByClipPathFromProperty();

private:
bool windowEvent(QEvent *event);
virtual bool eventFilter(QObject *watched, QEvent *event) override;
bool isEnableSystemMove(quint32 winId);
bool updateWindowBlurAreasForWM();
void updateWindowShape();
Expand Down

0 comments on commit 953444e

Please sign in to comment.