22//
33// SPDX-License-Identifier: LGPL-3.0-or-later
44
5- #define protected public
6- #include < QWindow>
7- #undef protected
85#include " dnotitlebarwindowhelper.h"
9- #include " vtablehook.h"
106#include " utility.h"
117#include " dwmsupport.h"
128#include " dnativesettings.h"
139#include " dplatformintegration.h"
1410
11+ #include < QWindow>
1512#include < QMouseEvent>
1613#include < QTimer>
1714#include < QMetaProperty>
1815#include < QScreen>
1916#include < qpa/qplatformwindow.h>
2017#include < QGuiApplication>
2118#include < QStyleHints>
19+ #include < QDebug>
2220
2321#define _DEEPIN_SCISSOR_WINDOW " _DEEPIN_SCISSOR_WINDOW"
2422Q_DECLARE_METATYPE (QPainterPath)
@@ -81,9 +79,8 @@ DNoTitlebarWindowHelper::~DNoTitlebarWindowHelper()
8179{
8280 g_pressPoint.remove (this );
8381
84- if (VtableHook::hasVtable (m_window)) {
85- VtableHook::resetVtable (m_window);
86- }
82+ if (m_enableSystemMove)
83+ m_window->removeEventFilter (this );
8784
8885 mapped.remove (qobject_cast<QWindow*>(parent ()));
8986
@@ -426,9 +423,9 @@ void DNoTitlebarWindowHelper::updateEnableSystemMoveFromProperty()
426423 m_enableSystemMove = !v.isValid () || v.toBool ();
427424
428425 if (m_enableSystemMove) {
429- VtableHook::overrideVfptrFun ( m_window, &QWindow::event, this , &DNoTitlebarWindowHelper::windowEvent );
430- } else if ( VtableHook::hasVtable (m_window)) {
431- VtableHook::resetVfptrFun ( m_window, &QWindow::event );
426+ m_window-> installEventFilter ( this );
427+ } else {
428+ m_window-> removeEventFilter ( this );
432429 }
433430}
434431
@@ -510,9 +507,24 @@ void DNoTitlebarWindowHelper::updateAutoInputMaskByClipPathFromProperty()
510507 updateWindowShape ();
511508}
512509
513- bool DNoTitlebarWindowHelper::windowEvent ( QEvent *event)
510+ bool DNoTitlebarWindowHelper::eventFilter (QObject *watched, QEvent *event)
514511{
515- QWindow *w = this ->window ();
512+ QWindow *w = qobject_cast<QWindow *>(watched);
513+ if (!w)
514+ return false ;
515+
516+ static QSet<QEvent::Type> filterEvents {
517+ QEvent::TouchBegin,
518+ QEvent::TouchUpdate,
519+ QEvent::TouchEnd,
520+ // mouse event
521+ QEvent::MouseButtonPress,
522+ QEvent::MouseButtonRelease,
523+ QEvent::MouseMove,
524+ };
525+
526+ if (!filterEvents.contains (event->type ()))
527+ return false ;
516528
517529 // get touch begin position
518530 static bool isTouchDown = false ;
@@ -531,7 +543,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
531543 QPointF currentPos = static_cast <QMouseEvent*>(event)->globalPos ();
532544 QPointF delta = touchBeginPosition - currentPos;
533545 if (delta.manhattanLength () < QGuiApplication::styleHints ()->startDragDistance ()) {
534- return VtableHook::callOriginalFun (w, &QWindow:: event, event);
546+ return watched-> event ( event);
535547 }
536548 }
537549
@@ -549,7 +561,8 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
549561 updateMoveWindow (winId);
550562 }
551563
552- bool ret = VtableHook::callOriginalFun (w, &QWindow::event, event);
564+ // call first to set accept false(quickwindow)
565+ watched->event (event);
553566
554567 // workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
555568 // which makes app hang in windowMoving state. when a press happens, there's no sense of
@@ -563,12 +576,12 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
563576 QMouseEvent *me = static_cast <QMouseEvent*>(event);
564577 QRect windowRect = QRect (QPoint (0 , 0 ), w->size ());
565578 if (!windowRect.contains (me->windowPos ().toPoint ())) {
566- return ret ;
579+ return true ;
567580 }
568581
569582 QPointF delta = me->globalPos () - g_pressPoint[this ];
570583 if (delta.manhattanLength () < QGuiApplication::styleHints ()->startDragDistance ()) {
571- return ret ;
584+ return true ;
572585 }
573586
574587 if (!self->m_windowMoving && self->isEnableSystemMove (winId)) {
@@ -583,7 +596,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
583596 }
584597 }
585598
586- return ret ;
599+ return true ;
587600}
588601
589602bool DNoTitlebarWindowHelper::isEnableSystemMove (quint32 winId)
0 commit comments