xwayland: Make DataBridge a native event filter

With the DataBridge being a native event filter, we can further separate
DataBridge-specific and generic Xwayland bits. In particular, we no
longer have to call DataBridge::filterEvent() from the dispatchEvents()
method, whose main purpose is to dispatch X11 events to kwin.
This commit is contained in:
Vlad Zahorodnii 2020-08-06 11:07:36 +03:00
parent c86d3b717a
commit 8baf535a7a
3 changed files with 9 additions and 12 deletions

View file

@ -81,15 +81,14 @@ void DataBridge::init()
m_clipboard = new Clipboard(atoms->clipboard, this); m_clipboard = new Clipboard(atoms->clipboard, this);
m_dnd = new Dnd(atoms->xdnd_selection, this); m_dnd = new Dnd(atoms->xdnd_selection, this);
waylandServer()->dispatch(); 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)) { if (eventType == "xcb_generic_event_t") {
return true; xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message);
} return m_clipboard->filterEvent(event) || m_dnd->filterEvent(event);
if (m_dnd && m_dnd->filterEvent(event)) {
return true;
} }
return false; return false;
} }

View file

@ -9,6 +9,7 @@
#ifndef KWIN_XWL_DATABRIDGE #ifndef KWIN_XWL_DATABRIDGE
#define KWIN_XWL_DATABRIDGE #define KWIN_XWL_DATABRIDGE
#include <QAbstractNativeEventFilter>
#include <QObject> #include <QObject>
#include <QPoint> #include <QPoint>
@ -42,7 +43,7 @@ enum class DragEventReply;
* *
* Exists only once per Xwayland session. * Exists only once per Xwayland session.
*/ */
class DataBridge : public QObject class DataBridge : public QObject, public QAbstractNativeEventFilter
{ {
Q_OBJECT Q_OBJECT
@ -52,7 +53,6 @@ public:
explicit DataBridge(QObject *parent = nullptr); explicit DataBridge(QObject *parent = nullptr);
~DataBridge() override; ~DataBridge() override;
bool filterEvent(xcb_generic_event_t *event);
DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos); DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos);
KWayland::Client::DataDevice *dataDevice() const KWayland::Client::DataDevice *dataDevice() const
@ -68,6 +68,8 @@ public:
return m_dnd; return m_dnd;
} }
bool nativeEventFilter(const QByteArray &eventType, void *message, long int *result) override;
private: private:
void init(); void init();

View file

@ -187,10 +187,6 @@ void Xwayland::dispatchEvents()
} }
while (xcb_generic_event_t *event = xcb_poll_for_event(connection)) { while (xcb_generic_event_t *event = xcb_poll_for_event(connection)) {
if (m_dataBridge->filterEvent(event)) {
free(event);
continue;
}
long result = 0; long result = 0;
QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
dispatcher->filterNativeEvent(QByteArrayLiteral("xcb_generic_event_t"), event, &result); dispatcher->filterNativeEvent(QByteArrayLiteral("xcb_generic_event_t"), event, &result);