diff --git a/xwl/databridge.cpp b/xwl/databridge.cpp index 3badcea75a..0375c2953c 100644 --- a/xwl/databridge.cpp +++ b/xwl/databridge.cpp @@ -81,15 +81,14 @@ void DataBridge::init() m_clipboard = new Clipboard(atoms->clipboard, this); m_dnd = new Dnd(atoms->xdnd_selection, this); waylandServer()->dispatch(); + kwinApp()->installNativeEventFilter(this); } -bool DataBridge::filterEvent(xcb_generic_event_t *event) +bool DataBridge::nativeEventFilter(const QByteArray &eventType, void *message, long int *) { - if (m_clipboard && m_clipboard->filterEvent(event)) { - return true; - } - if (m_dnd && m_dnd->filterEvent(event)) { - return true; + if (eventType == "xcb_generic_event_t") { + xcb_generic_event_t *event = static_cast(message); + return m_clipboard->filterEvent(event) || m_dnd->filterEvent(event); } return false; } diff --git a/xwl/databridge.h b/xwl/databridge.h index e3f6b4a106..736807d605 100644 --- a/xwl/databridge.h +++ b/xwl/databridge.h @@ -9,6 +9,7 @@ #ifndef KWIN_XWL_DATABRIDGE #define KWIN_XWL_DATABRIDGE +#include #include #include @@ -42,7 +43,7 @@ enum class DragEventReply; * * Exists only once per Xwayland session. */ -class DataBridge : public QObject +class DataBridge : public QObject, public QAbstractNativeEventFilter { Q_OBJECT @@ -52,7 +53,6 @@ public: explicit DataBridge(QObject *parent = nullptr); ~DataBridge() override; - bool filterEvent(xcb_generic_event_t *event); DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos); KWayland::Client::DataDevice *dataDevice() const @@ -68,6 +68,8 @@ public: return m_dnd; } + bool nativeEventFilter(const QByteArray &eventType, void *message, long int *result) override; + private: void init(); diff --git a/xwl/xwayland.cpp b/xwl/xwayland.cpp index 3173c197f8..9f417d843e 100644 --- a/xwl/xwayland.cpp +++ b/xwl/xwayland.cpp @@ -187,10 +187,6 @@ void Xwayland::dispatchEvents() } while (xcb_generic_event_t *event = xcb_poll_for_event(connection)) { - if (m_dataBridge->filterEvent(event)) { - free(event); - continue; - } long result = 0; QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); dispatcher->filterNativeEvent(QByteArrayLiteral("xcb_generic_event_t"), event, &result);