From 736ad55e374a5cf181e6509d92e71511c8141835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 15 Apr 2016 13:19:22 +0200 Subject: [PATCH] Add ::window() and ::approachWindow as virtual methods to Edge This allows to no longer needing to dynamic cast the Edge to WindowBasedEdge for the X11 specific event handling. --- autotests/test_screen_edges.cpp | 2 +- screenedge.cpp | 23 +++++++++++++++-------- screenedge.h | 21 +++++++++++++++++---- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/autotests/test_screen_edges.cpp b/autotests/test_screen_edges.cpp index a81df1ec8c..65b73d1d3c 100644 --- a/autotests/test_screen_edges.cpp +++ b/autotests/test_screen_edges.cpp @@ -445,7 +445,7 @@ void TestScreenEdges::testCallback() }; event.root = XCB_WINDOW_NONE; event.child = XCB_WINDOW_NONE; - event.event = static_cast(*it)->window(); + event.event = (*it)->window(); event.same_screen_focus = 1; event.time = QDateTime::currentMSecsSinceEpoch(); setPos(QPoint(0, 50)); diff --git a/screenedge.cpp b/screenedge.cpp index e7b37c0748..b7093e6a66 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -487,6 +487,16 @@ void Edge::updateApproaching(const QPoint &point) } } +quint32 Edge::window() const +{ + return 0; +} + +quint32 Edge::approachWindow() const +{ + return 0; +} + /********************************************************** * ScreenEdges *********************************************************/ @@ -1233,8 +1243,8 @@ bool ScreenEdges::handleEnterNotifiy(xcb_window_t window, const QPoint &point, c bool activated = false; bool activatedForClient = false; for (auto it = m_edges.begin(); it != m_edges.end(); ++it) { - WindowBasedEdge *edge = dynamic_cast(*it); - if (!edge) { + Edge *edge = *it; + if (!edge || edge->window() == XCB_WINDOW_NONE) { continue; } if (!edge->isReserved()) { @@ -1268,8 +1278,8 @@ bool ScreenEdges::handleEnterNotifiy(xcb_window_t window, const QPoint &point, c bool ScreenEdges::handleDndNotify(xcb_window_t window, const QPoint &point) { for (auto it = m_edges.begin(); it != m_edges.end(); ++it) { - WindowBasedEdge *edge = dynamic_cast(*it); - if (!edge) { + Edge *edge = *it; + if (!edge || edge->window() == XCB_WINDOW_NONE) { continue; } if (edge->isReserved() && edge->window() == window) { @@ -1292,10 +1302,7 @@ QVector< xcb_window_t > ScreenEdges::windows() const for (auto it = m_edges.constBegin(); it != m_edges.constEnd(); ++it) { - WindowBasedEdge *edge = dynamic_cast(*it); - if (!edge) { - continue; - } + Edge *edge = *it; xcb_window_t w = edge->window(); if (w != XCB_WINDOW_NONE) { wins.append(w); diff --git a/screenedge.h b/screenedge.h index 4d837d168b..c11358af4e 100644 --- a/screenedge.h +++ b/screenedge.h @@ -74,6 +74,19 @@ public: Client *client() const; const QRect &geometry() const; + /** + * The window id of the native window representing the edge. + * Default implementation returns @c 0, which means no window. + **/ + virtual quint32 window() const; + /** + * The approach window is a special window to notice when get close to the screen border but + * not yet triggering the border. + * + * The default implementation returns @c 0, which means no window. + **/ + virtual quint32 approachWindow() const; + public Q_SLOTS: void reserve(); void unreserve(); @@ -126,12 +139,12 @@ public: explicit WindowBasedEdge(ScreenEdges *parent); virtual ~WindowBasedEdge(); - xcb_window_t window() const; + quint32 window() const override; /** * The approach window is a special window to notice when get close to the screen border but * not yet triggering the border. **/ - xcb_window_t approachWindow() const; + quint32 approachWindow() const override; protected: virtual void doGeometryUpdate(); @@ -487,12 +500,12 @@ inline bool Edge::isApproaching() const * Inlines WindowBasedEdge *********************************************************/ -inline xcb_window_t WindowBasedEdge::window() const +inline quint32 WindowBasedEdge::window() const { return m_window; } -inline xcb_window_t WindowBasedEdge::approachWindow() const +inline quint32 WindowBasedEdge::approachWindow() const { return m_approachWindow; }