diff --git a/screenedge.cpp b/screenedge.cpp index ee81bd1064..b7c50855c9 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -36,7 +36,6 @@ along with this program. If not, see . #include "utils.h" #include "workspace.h" #include "virtualdesktops.h" -#include "xcbutils.h" // Qt #include #include @@ -439,7 +438,6 @@ WindowBasedEdge::WindowBasedEdge(ScreenEdges *parent) WindowBasedEdge::~WindowBasedEdge() { - destroyWindow(); } void WindowBasedEdge::activate() @@ -451,12 +449,13 @@ void WindowBasedEdge::activate() void WindowBasedEdge::deactivate() { - destroyWindow(); + m_window.reset(); + m_approachWindow.reset(); } void WindowBasedEdge::createWindow() { - if (m_window != XCB_WINDOW_NONE) { + if (m_window.isValid()) { return; } const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK; @@ -464,8 +463,8 @@ void WindowBasedEdge::createWindow() true, XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW }; - m_window = Xcb::createInputWindow(geometry(), mask, values); - xcb_map_window(connection(), m_window); + m_window.create(geometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values); + m_window.map(); // Set XdndAware on the windows, so that DND enter events are received (#86998) xcb_atom_t version = 4; // XDND version xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, m_window, @@ -474,7 +473,7 @@ void WindowBasedEdge::createWindow() void WindowBasedEdge::createApproachWindow() { - if (m_approachWindow != XCB_WINDOW_NONE) { + if (m_approachWindow.isValid()) { return; } if (!approachGeometry().isValid()) { @@ -485,32 +484,19 @@ void WindowBasedEdge::createApproachWindow() true, XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW }; - const QRect geo = approachGeometry(); - m_approachWindow = Xcb::createInputWindow(geo, mask, values); - xcb_map_window(connection(), m_approachWindow); -} - -void WindowBasedEdge::destroyWindow() -{ - if (m_window != XCB_WINDOW_NONE) { - xcb_destroy_window(connection(), m_window); - m_window = XCB_WINDOW_NONE; - } - if (m_approachWindow != XCB_WINDOW_NONE) { - xcb_destroy_window(connection(), m_approachWindow); - m_approachWindow = XCB_WINDOW_NONE; - } + m_approachWindow.create(approachGeometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values); + m_approachWindow.map(); } void WindowBasedEdge::doGeometryUpdate() { - Xcb::moveResizeWindow(m_window, geometry()); - Xcb::moveResizeWindow(m_approachWindow, approachGeometry()); + m_window.setGeometry(geometry()); + m_approachWindow.setGeometry(approachGeometry()); } void WindowBasedEdge::doStartApproaching() { - xcb_unmap_window(connection(), m_approachWindow); + m_approachWindow.unmap(); connect(edges(), SIGNAL(mousePollingTimerEvent(QPoint)), SLOT(updateApproaching(QPoint))); edges()->startMousePolling(); } @@ -519,9 +505,7 @@ void WindowBasedEdge::doStopApproaching() { disconnect(edges(), SIGNAL(mousePollingTimerEvent(QPoint)), this, SLOT(updateApproaching(QPoint))); edges()->stopMousePolling(); - if (m_approachWindow != XCB_WINDOW_NONE) { - xcb_map_window(connection(), m_approachWindow); - } + m_approachWindow.map(); } void WindowBasedEdge::doUpdateBlocking() @@ -530,11 +514,11 @@ void WindowBasedEdge::doUpdateBlocking() return; } if (isBlocked()) { - xcb_unmap_window(connection(), m_window); - xcb_unmap_window(connection(), m_approachWindow); + m_window.unmap(); + m_approachWindow.unmap(); } else { - xcb_map_window(connection(), m_window); - xcb_map_window(connection(), m_approachWindow); + m_window.map(); + m_approachWindow.map(); } } diff --git a/screenedge.h b/screenedge.h index 345acfc35a..cf18af2102 100644 --- a/screenedge.h +++ b/screenedge.h @@ -31,6 +31,7 @@ along with this program. If not, see . #define KWIN_SCREENEDGE_H // KWin #include "kwinglobals.h" +#include "xcbutils.h" // KDE includes #include // Qt @@ -132,11 +133,10 @@ protected: virtual void doUpdateBlocking(); private: - void destroyWindow(); void createWindow(); void createApproachWindow(); - xcb_window_t m_window; - xcb_window_t m_approachWindow; + Xcb::Window m_window; + Xcb::Window m_approachWindow; }; /** diff --git a/xcbutils.h b/xcbutils.h index ba1cfb3b8f..60a770364e 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -304,6 +304,10 @@ public: * @param parent The parent window **/ void create(const QRect &geometry, uint16_t windowClass, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow()); + /** + * Frees the existing window and starts to manage the new @p window. + **/ + void reset(xcb_window_t window = XCB_WINDOW_NONE); /** * @returns @c true if a window is managed, @c false otherwise. **/ @@ -398,6 +402,13 @@ xcb_window_t Window::doCreate(const QRect &geometry, uint16_t windowClass, uint3 return w; } +inline +void Window::reset(xcb_window_t window) +{ + destroy(); + m_window = window; +} + inline void Window::setGeometry(const QRect &geometry) {