diff options
author | Pier Luigi Fiorini <pierluigi.fiorini@liri.io> | 2019-08-29 15:03:02 +0200 |
---|---|---|
committer | Pier Luigi Fiorini <pierluigi.fiorini@liri.io> | 2019-09-05 09:42:19 +0200 |
commit | a85e1542de6fcd84de22955c8aa764e8c8317331 (patch) | |
tree | 37cfef9d3b6b76610f948f038950dc981f486abb /src | |
parent | f1148d63430347af03827c995bf68f86793c7ae0 (diff) |
Improve QWaylandQuickShellIntegration API
During the API review we came up with an improved API.
QWaylandQuickShellIntegration now filter events delivered to
QWaylandQuickShellSurfaceItem using QObject event filter,
thus we don't need a new API anymore.
Change-Id: I91b05c4c8ecee56cd782f036160c569cd972abdb
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'src')
12 files changed, 132 insertions, 333 deletions
diff --git a/src/compositor/extensions/qwaylandquickshellintegration.cpp b/src/compositor/extensions/qwaylandquickshellintegration.cpp index 961b7b111..d56d6c22a 100644 --- a/src/compositor/extensions/qwaylandquickshellintegration.cpp +++ b/src/compositor/extensions/qwaylandquickshellintegration.cpp @@ -48,8 +48,46 @@ * Shell surface implementations should inherit from this class in order to provide * an integration between the shell surface and QtQuick. * - * \sa QWaylandShellSurface - * \sa QWaylandShellSurfaceItem + * Shell integration is installed as an event filter for a QWaylandQuickShellSurfaceItem. + * Reimplement the event filter method and return \c true when you want to filter the + * event out, otherwise return \c false. + * + * Example: + * + * \code + * class MyShellIntegration : public QWaylandQuickShellIntegration + * { + * Q_OBJECT + * public: + * MyShellIntegration(QObject *parent = nullptr); + * + * protected: + * bool eventFilter(QObject *object, QEvent *event) override; + * }; + * + * MyShellIntegration::MyShellIntegration(QObject *parent) + * : QWaylandQuickShellIntegration(parent) + * { + * } + * + * bool MyShellIntegration::eventFilter(QObject *object, QEvent *event) + * { + * QWaylandQuickShellSurfaceItem *shellSurfaceItem = qobject_cast<QWaylandQuickShellSurfaceItem *>(object); + * if (!shellSurfaceItem) + * return QWaylandQuickShellIntegration::eventFilter(object, event); + * + * if (event->type() == QEvent::MouseMove) { + * QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + * qDebug() << "Mouse moved on" << shellSurfaceItem << "pos:" << mouseEvent->pos(); + * return true; + * } + * + * return QWaylandQuickShellIntegration::eventFilter(object, event); + * } + * \endcode + * + * \sa QWaylandQuickShellSurfaceItem + * \sa QObject::eventFilter() */ QWaylandQuickShellIntegration::QWaylandQuickShellIntegration(QObject *parent) @@ -57,200 +95,6 @@ QWaylandQuickShellIntegration::QWaylandQuickShellIntegration(QObject *parent) { } -/*! - * This method can be reimplemented in a subclass to receive touch events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::touchEvent() - */ -bool QWaylandQuickShellIntegration::touchEvent(QTouchEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive hover-enter events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Hover events are only provided if \l {QWaylandQuickShellSurfaceItem::} {acceptHoverEvents()} - * is \a true. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::hoverEnterEvent() - */ -bool QWaylandQuickShellIntegration::hoverEnterEvent(QHoverEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive hover-leave events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Hover events are only provided if \l {QWaylandQuickShellSurfaceItem::} {acceptHoverEvents()} - * is \a true. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::hoverLeaveEvent() - */ -bool QWaylandQuickShellIntegration::hoverLeaveEvent(QHoverEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive hover-move events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Hover events are only provided if \l {QWaylandQuickShellSurfaceItem::} {acceptHoverEvents()} - * is \a true. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::hoverMoveEvent() - */ -bool QWaylandQuickShellIntegration::hoverMoveEvent(QHoverEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive key press events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::keyPressEvent() - */ -bool QWaylandQuickShellIntegration::keyPressEvent(QKeyEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive key release events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::keyReleaseEvent() - */ -bool QWaylandQuickShellIntegration::keyReleaseEvent(QKeyEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive mouse double click events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::mouseDoubleClickEvent() - */ -bool QWaylandQuickShellIntegration::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive mouse move events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::mouseMoveEvent() - */ -bool QWaylandQuickShellIntegration::mouseMoveEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive mouse press events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::mousePressEvent() - */ -bool QWaylandQuickShellIntegration::mousePressEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - return false; -} - -/*! - * This method can be reimplemented in a subclass to receive mouse release events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::mouseReleaseEvent() - */ -bool QWaylandQuickShellIntegration::mouseReleaseEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - return false; -} - -#if QT_CONFIG(wheelevent) -/*! - * This method can be reimplemented in a subclass to receive wheel events - * for a shell surface. - * - * The event information is provided by the \a event parameter. - * - * Return \a false if you want QWaylandQuickShellSurfaceItem to handle - * the event. - * - * \sa QWaylandQuickShellSurfaceItem::wheelEvent() - */ -bool QWaylandQuickShellIntegration::wheelEvent(QWheelEvent *event) +QWaylandQuickShellIntegration::~QWaylandQuickShellIntegration() { - Q_UNUSED(event); - return false; } -#endif diff --git a/src/compositor/extensions/qwaylandquickshellintegration.h b/src/compositor/extensions/qwaylandquickshellintegration.h index e1a4c2384..00696681b 100644 --- a/src/compositor/extensions/qwaylandquickshellintegration.h +++ b/src/compositor/extensions/qwaylandquickshellintegration.h @@ -41,7 +41,6 @@ #define QWAYLANDQUICKSHELLINTEGRATION_H #include <QtCore/QObject> -#include <QtGui/QMouseEvent> #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> QT_BEGIN_NAMESPACE @@ -50,25 +49,8 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickShellIntegration : public QObject { Q_OBJECT public: - explicit QWaylandQuickShellIntegration(QObject *parent = nullptr); - - virtual bool touchEvent(QTouchEvent *event); - - virtual bool hoverEnterEvent(QHoverEvent *event); - virtual bool hoverLeaveEvent(QHoverEvent *event); - virtual bool hoverMoveEvent(QHoverEvent *event); - - virtual bool keyPressEvent(QKeyEvent *event); - virtual bool keyReleaseEvent(QKeyEvent *event); - - virtual bool mouseDoubleClickEvent(QMouseEvent *event); - virtual bool mouseMoveEvent(QMouseEvent *event); - virtual bool mousePressEvent(QMouseEvent *event); - virtual bool mouseReleaseEvent(QMouseEvent *event); - -#if QT_CONFIG(wheelevent) - virtual bool wheelEvent(QWheelEvent *event); -#endif + QWaylandQuickShellIntegration(QObject *parent = nullptr); + ~QWaylandQuickShellIntegration() override; }; QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp b/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp index 110c3d0a3..bda536017 100644 --- a/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp +++ b/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp @@ -96,7 +96,11 @@ QWaylandQuickShellSurfaceItem::QWaylandQuickShellSurfaceItem(QQuickItem *parent) QWaylandQuickShellSurfaceItem::~QWaylandQuickShellSurfaceItem() { Q_D(QWaylandQuickShellSurfaceItem); - delete d->m_shellIntegration; + + if (d->m_shellIntegration) { + removeEventFilter(d->m_shellIntegration); + delete d->m_shellIntegration; + } } /*! @@ -137,12 +141,15 @@ void QWaylandQuickShellSurfaceItem::setShellSurface(QWaylandShellSurface *shellS d->m_shellSurface = shellSurface; if (d->m_shellIntegration) { + removeEventFilter(d->m_shellIntegration); delete d->m_shellIntegration; d->m_shellIntegration = nullptr; } - if (shellSurface) + if (shellSurface) { d->m_shellIntegration = shellSurface->createIntegration(this); + installEventFilter(d->m_shellIntegration); + } emit shellSurfaceChanged(); } @@ -208,86 +215,6 @@ void QWaylandQuickShellSurfaceItem::setAutoCreatePopupItems(bool enabled) emit autoCreatePopupItemsChanged(); } -void QWaylandQuickShellSurfaceItem::touchEvent(QTouchEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->touchEvent(event)) - QWaylandQuickItem::touchEvent(event); -} - -void QWaylandQuickShellSurfaceItem::hoverEnterEvent(QHoverEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->hoverEnterEvent(event)) - QWaylandQuickItem::hoverEnterEvent(event); -} - -void QWaylandQuickShellSurfaceItem::hoverLeaveEvent(QHoverEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->hoverLeaveEvent(event)) - QWaylandQuickItem::hoverLeaveEvent(event); -} - -void QWaylandQuickShellSurfaceItem::hoverMoveEvent(QHoverEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->hoverMoveEvent(event)) - QWaylandQuickItem::hoverMoveEvent(event); -} - - -void QWaylandQuickShellSurfaceItem::keyPressEvent(QKeyEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->keyPressEvent(event)) - QWaylandQuickItem::keyPressEvent(event); -} - -void QWaylandQuickShellSurfaceItem::keyReleaseEvent(QKeyEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->keyReleaseEvent(event)) - QWaylandQuickItem::keyReleaseEvent(event); -} - -void QWaylandQuickShellSurfaceItem::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->mouseDoubleClickEvent(event)) - QWaylandQuickItem::mouseDoubleClickEvent(event); -} - -void QWaylandQuickShellSurfaceItem::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->mouseMoveEvent(event)) - QWaylandQuickItem::mouseMoveEvent(event); -} - -void QWaylandQuickShellSurfaceItem::mousePressEvent(QMouseEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->mousePressEvent(event)) - QWaylandQuickItem::mousePressEvent(event); -} - -void QWaylandQuickShellSurfaceItem::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->mouseReleaseEvent(event)) - QWaylandQuickItem::mouseReleaseEvent(event); -} - -#if QT_CONFIG(wheelevent) -void QWaylandQuickShellSurfaceItem::wheelEvent(QWheelEvent *event) -{ - Q_D(QWaylandQuickShellSurfaceItem); - if (!d->m_shellIntegration->wheelEvent(event)) - QWaylandQuickItem::wheelEvent(event); -} -#endif - /*! \class QWaylandQuickShellEventFilter \brief QWaylandQuickShellEventFilter implements a Wayland popup grab diff --git a/src/compositor/extensions/qwaylandquickshellsurfaceitem.h b/src/compositor/extensions/qwaylandquickshellsurfaceitem.h index 73a4900bb..51c0425e6 100644 --- a/src/compositor/extensions/qwaylandquickshellsurfaceitem.h +++ b/src/compositor/extensions/qwaylandquickshellsurfaceitem.h @@ -75,24 +75,6 @@ Q_SIGNALS: protected: QWaylandQuickShellSurfaceItem(QWaylandQuickShellSurfaceItemPrivate &dd, QQuickItem *parent); - - void touchEvent(QTouchEvent *event) override; - - void hoverEnterEvent(QHoverEvent *event) override; - void hoverLeaveEvent(QHoverEvent *event) override; - void hoverMoveEvent(QHoverEvent *event) override; - - void keyPressEvent(QKeyEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; - - void mouseDoubleClickEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - -#if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *event) override; -#endif }; QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandwlshellintegration.cpp b/src/compositor/extensions/qwaylandwlshellintegration.cpp index b732069c4..724580e24 100644 --- a/src/compositor/extensions/qwaylandwlshellintegration.cpp +++ b/src/compositor/extensions/qwaylandwlshellintegration.cpp @@ -289,7 +289,19 @@ void WlShellIntegration::adjustOffsetForNextFrame(const QPointF &offset) moveItem->setPosition(moveItem->position() + m_item->mapFromSurface(offset)); } -bool WlShellIntegration::mouseMoveEvent(QMouseEvent *event) +bool WlShellIntegration::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseMoveEvent(mouseEvent); + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseReleaseEvent(mouseEvent); + } + return QWaylandQuickShellIntegration::eventFilter(object, event); +} + +bool WlShellIntegration::filterMouseMoveEvent(QMouseEvent *event) { if (grabberState == GrabberState::Resize) { Q_ASSERT(resizeState.seat == m_item->compositor()->seatFor(event)); @@ -318,7 +330,7 @@ bool WlShellIntegration::mouseMoveEvent(QMouseEvent *event) return false; } -bool WlShellIntegration::mouseReleaseEvent(QMouseEvent *event) +bool WlShellIntegration::filterMouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); if (grabberState != GrabberState::Default) { diff --git a/src/compositor/extensions/qwaylandwlshellintegration_p.h b/src/compositor/extensions/qwaylandwlshellintegration_p.h index 8af54dfc4..eb23a62fc 100644 --- a/src/compositor/extensions/qwaylandwlshellintegration_p.h +++ b/src/compositor/extensions/qwaylandwlshellintegration_p.h @@ -65,8 +65,9 @@ class WlShellIntegration : public QWaylandQuickShellIntegration public: WlShellIntegration(QWaylandQuickShellSurfaceItem *item); ~WlShellIntegration() override; - bool mouseMoveEvent(QMouseEvent *event) override; - bool mouseReleaseEvent(QMouseEvent *event) override; + +protected: + bool eventFilter(QObject *object, QEvent *event) override; private Q_SLOTS: void handleStartMove(QWaylandSeat *seat); @@ -130,6 +131,9 @@ private: QPointF normalPosition; QPointF finalPosition; + + bool filterMouseMoveEvent(QMouseEvent *event); + bool filterMouseReleaseEvent(QMouseEvent *event); }; } diff --git a/src/compositor/extensions/qwaylandxdgshellintegration.cpp b/src/compositor/extensions/qwaylandxdgshellintegration.cpp index 3de52944b..336ede3cc 100644 --- a/src/compositor/extensions/qwaylandxdgshellintegration.cpp +++ b/src/compositor/extensions/qwaylandxdgshellintegration.cpp @@ -77,7 +77,19 @@ XdgToplevelIntegration::XdgToplevelIntegration(QWaylandQuickShellSurfaceItem *it connect(m_toplevel, &QObject::destroyed, this, &XdgToplevelIntegration::handleToplevelDestroyed); } -bool XdgToplevelIntegration::mouseMoveEvent(QMouseEvent *event) +bool XdgToplevelIntegration::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseMoveEvent(mouseEvent); + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseReleaseEvent(mouseEvent); + } + return QWaylandQuickShellIntegration::eventFilter(object, event); +} + +bool XdgToplevelIntegration::filterMouseMoveEvent(QMouseEvent *event) { if (grabberState == GrabberState::Resize) { Q_ASSERT(resizeState.seat == m_item->compositor()->seatFor(event)); @@ -105,7 +117,7 @@ bool XdgToplevelIntegration::mouseMoveEvent(QMouseEvent *event) return false; } -bool XdgToplevelIntegration::mouseReleaseEvent(QMouseEvent *event) +bool XdgToplevelIntegration::filterMouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); diff --git a/src/compositor/extensions/qwaylandxdgshellintegration_p.h b/src/compositor/extensions/qwaylandxdgshellintegration_p.h index 34e3873d5..cd6bad572 100644 --- a/src/compositor/extensions/qwaylandxdgshellintegration_p.h +++ b/src/compositor/extensions/qwaylandxdgshellintegration_p.h @@ -63,8 +63,9 @@ class XdgToplevelIntegration : public QWaylandQuickShellIntegration Q_OBJECT public: XdgToplevelIntegration(QWaylandQuickShellSurfaceItem *item); - bool mouseMoveEvent(QMouseEvent *event) override; - bool mouseReleaseEvent(QMouseEvent *event) override; + +protected: + bool eventFilter(QObject *object, QEvent *event) override; private Q_SLOTS: void handleStartMove(QWaylandSeat *seat); @@ -120,6 +121,9 @@ private: // will be hooked to geometry-changed or available- // geometry-changed. } nonwindowedState; + + bool filterMouseMoveEvent(QMouseEvent *event); + bool filterMouseReleaseEvent(QMouseEvent *event); }; class XdgPopupIntegration : public QWaylandQuickShellIntegration diff --git a/src/compositor/extensions/qwaylandxdgshellv5integration.cpp b/src/compositor/extensions/qwaylandxdgshellv5integration.cpp index 1d63632a3..4907a0611 100644 --- a/src/compositor/extensions/qwaylandxdgshellv5integration.cpp +++ b/src/compositor/extensions/qwaylandxdgshellv5integration.cpp @@ -82,7 +82,19 @@ XdgShellV5Integration::~XdgShellV5Integration() m_item->setSurface(nullptr); } -bool XdgShellV5Integration::mouseMoveEvent(QMouseEvent *event) +bool XdgShellV5Integration::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseMoveEvent(mouseEvent); + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseReleaseEvent(mouseEvent); + } + return QWaylandQuickShellIntegration::eventFilter(object, event); +} + +bool XdgShellV5Integration::filterMouseMoveEvent(QMouseEvent *event) { if (grabberState == GrabberState::Resize) { Q_ASSERT(resizeState.seat == m_item->compositor()->seatFor(event)); @@ -110,7 +122,7 @@ bool XdgShellV5Integration::mouseMoveEvent(QMouseEvent *event) return false; } -bool XdgShellV5Integration::mouseReleaseEvent(QMouseEvent *event) +bool XdgShellV5Integration::filterMouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); diff --git a/src/compositor/extensions/qwaylandxdgshellv5integration_p.h b/src/compositor/extensions/qwaylandxdgshellv5integration_p.h index 5d0e1e142..99983c866 100644 --- a/src/compositor/extensions/qwaylandxdgshellv5integration_p.h +++ b/src/compositor/extensions/qwaylandxdgshellv5integration_p.h @@ -64,8 +64,9 @@ class XdgShellV5Integration : public QWaylandQuickShellIntegration public: XdgShellV5Integration(QWaylandQuickShellSurfaceItem *item); ~XdgShellV5Integration() override; - bool mouseMoveEvent(QMouseEvent *event) override; - bool mouseReleaseEvent(QMouseEvent *event) override; + +protected: + bool eventFilter(QObject *object, QEvent *event) override; private Q_SLOTS: void handleStartMove(QWaylandSeat *seat); @@ -108,6 +109,9 @@ private: QSize initialWindowSize; QPointF initialPosition; } maximizeState; + + bool filterMouseMoveEvent(QMouseEvent *event); + bool filterMouseReleaseEvent(QMouseEvent *event); }; class XdgPopupV5Integration : public QWaylandQuickShellIntegration diff --git a/src/compositor/extensions/qwaylandxdgshellv6integration.cpp b/src/compositor/extensions/qwaylandxdgshellv6integration.cpp index 66dbc6841..e424af193 100644 --- a/src/compositor/extensions/qwaylandxdgshellv6integration.cpp +++ b/src/compositor/extensions/qwaylandxdgshellv6integration.cpp @@ -77,7 +77,19 @@ XdgToplevelV6Integration::XdgToplevelV6Integration(QWaylandQuickShellSurfaceItem connect(m_toplevel, &QObject::destroyed, this, &XdgToplevelV6Integration::handleToplevelDestroyed); } -bool XdgToplevelV6Integration::mouseMoveEvent(QMouseEvent *event) +bool XdgToplevelV6Integration::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseMoveEvent(mouseEvent); + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + return filterMouseReleaseEvent(mouseEvent); + } + return QWaylandQuickShellIntegration::eventFilter(object, event); +} + +bool XdgToplevelV6Integration::filterMouseMoveEvent(QMouseEvent *event) { if (grabberState == GrabberState::Resize) { Q_ASSERT(resizeState.seat == m_item->compositor()->seatFor(event)); @@ -105,7 +117,7 @@ bool XdgToplevelV6Integration::mouseMoveEvent(QMouseEvent *event) return false; } -bool XdgToplevelV6Integration::mouseReleaseEvent(QMouseEvent *event) +bool XdgToplevelV6Integration::filterMouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); diff --git a/src/compositor/extensions/qwaylandxdgshellv6integration_p.h b/src/compositor/extensions/qwaylandxdgshellv6integration_p.h index 049b901c9..9df2885f1 100644 --- a/src/compositor/extensions/qwaylandxdgshellv6integration_p.h +++ b/src/compositor/extensions/qwaylandxdgshellv6integration_p.h @@ -63,8 +63,9 @@ class XdgToplevelV6Integration : public QWaylandQuickShellIntegration Q_OBJECT public: XdgToplevelV6Integration(QWaylandQuickShellSurfaceItem *item); - bool mouseMoveEvent(QMouseEvent *event) override; - bool mouseReleaseEvent(QMouseEvent *event) override; + +protected: + bool eventFilter(QObject *object, QEvent *event) override; private Q_SLOTS: void handleStartMove(QWaylandSeat *seat); @@ -120,6 +121,9 @@ private: // will be hooked to geometry-changed or available- // geometry-changed. } nonwindowedState; + + bool filterMouseMoveEvent(QMouseEvent *event); + bool filterMouseReleaseEvent(QMouseEvent *event); }; class XdgPopupV6Integration : public QWaylandQuickShellIntegration |