From bed85baf6cc66b9cbfd8bede36e5b1b52ab5d8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 28 Jan 2013 08:52:21 +0100 Subject: [PATCH] Split out event handling in ScreenEdges in separate methods Allows to also support xcb_generic_event_t in addition to XEvent. --- screenedge.cpp | 77 +++++++++++++++++++++++++++++++++++--------------- screenedge.h | 3 ++ 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/screenedge.cpp b/screenedge.cpp index 0e300baa63..a683a3dca3 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -948,32 +948,63 @@ void ScreenEdges::check(const QPoint &pos, const QDateTime &now, bool forceNoPus bool ScreenEdges::isEntered(XEvent* e) { if (e->type == EnterNotify) { - for (QList::iterator it = m_edges.begin(); it != m_edges.end(); ++it) { - WindowBasedEdge *edge = *it; - if (!edge->isReserved()) { - continue; - } - if (edge->window() == e->xcrossing.window) { - edge->check(QPoint(e->xcrossing.x_root, e->xcrossing.y_root), QDateTime::fromMSecsSinceEpoch(e->xcrossing.time)); - return true; - } - if (edge->approachWindow() == e->xcrossing.window) { - edge->startApproaching(); - // TODO: if it's a corner, it should also trigger for other windows - return true; - } - } + return handleEnterNotifiy(e->xcrossing.window, + QPoint(e->xcrossing.x_root, e->xcrossing.y_root), + QDateTime::fromMSecsSinceEpoch(e->xcrossing.time)); } if (e->type == ClientMessage) { if (e->xclient.message_type == atoms->xdnd_position) { - for (QList::iterator it = m_edges.begin(); it != m_edges.end(); ++it) { - WindowBasedEdge *edge = *it; - if (edge->isReserved() && edge->window() == e->xclient.window) { - updateXTime(); - edge->check(QPoint(e->xclient.data.l[2] >> 16, e->xclient.data.l[2] & 0xffff), QDateTime::fromMSecsSinceEpoch(xTime()), true); - return true; - } - } + return handleDndNotify(e->xclient.window, + QPoint(e->xclient.data.l[2] >> 16, e->xclient.data.l[2] & 0xffff)); + } + } + return false; +} + +bool ScreenEdges::isEntered(xcb_generic_event_t *e) +{ + if (e->response_type == XCB_ENTER_NOTIFY) { + xcb_enter_notify_event_t *event = reinterpret_cast(e); + return handleEnterNotifiy(event->event, + QPoint(event->root_x, event->root_y), + QDateTime::fromMSecsSinceEpoch(event->time)); + } + if (e->response_type == XCB_CLIENT_MESSAGE) { + xcb_client_message_event_t *event = reinterpret_cast(e); + return handleDndNotify(event->window, + QPoint(event->data.data32[2] >> 16, event->data.data32[2] & 0xffff)); + } + return false; +} + +bool ScreenEdges::handleEnterNotifiy(xcb_window_t window, const QPoint &point, const QDateTime ×tamp) +{ + for (QList::iterator it = m_edges.begin(); it != m_edges.end(); ++it) { + WindowBasedEdge *edge = *it; + if (!edge->isReserved()) { + continue; + } + if (edge->window() == window) { + edge->check(point, timestamp); + return true; + } + if (edge->approachWindow() == window) { + edge->startApproaching(); + // TODO: if it's a corner, it should also trigger for other windows + return true; + } + } + return false; +} + +bool ScreenEdges::handleDndNotify(xcb_window_t window, const QPoint &point) +{ + for (QList::iterator it = m_edges.begin(); it != m_edges.end(); ++it) { + WindowBasedEdge *edge = *it; + if (edge->isReserved() && edge->window() == window) { + updateXTime(); + edge->check(point, QDateTime::fromMSecsSinceEpoch(xTime()), true); + return true; } } return false; diff --git a/screenedge.h b/screenedge.h index 83e39dc15c..5b8a00f743 100644 --- a/screenedge.h +++ b/screenedge.h @@ -255,6 +255,7 @@ public: * @param e the X event which is passed to this method. */ bool isEntered(XEvent * e); + bool isEntered(xcb_generic_event_t *e); /** * Returns a QVector of all existing screen edge windows @@ -333,6 +334,8 @@ private: WindowBasedEdge *createEdge(ElectricBorder border, int x, int y, int width, int height); void setActionForBorder(ElectricBorder border, ElectricBorderAction *oldValue, ElectricBorderAction newValue); ElectricBorderAction actionForEdge(Edge *edge) const; + bool handleEnterNotifiy(xcb_window_t window, const QPoint &point, const QDateTime ×tamp); + bool handleDndNotify(xcb_window_t window, const QPoint &point); bool m_desktopSwitching; bool m_desktopSwitchingMovingClients; QSize m_cursorPushBackDistance;