From 6c213d43928c4c76e29b269817e0c02c9392e821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 7 Jan 2013 14:10:00 +0100 Subject: [PATCH] Make use of new Xcb Wrapper classes Use WindowAttributes and WindowGeometry everywhere where the xcb commands had already been used. Introduces another wrapper for overlay window and a subclass for query tree which also wrapps the children command. --- composite.cpp | 14 ++++++-------- overlaywindow.cpp | 5 +---- workspace.cpp | 32 ++++++++++++-------------------- xcbutils.h | 12 ++++++++++++ 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/composite.cpp b/composite.cpp index 1d1d44454b..c27b37f21e 100644 --- a/composite.cpp +++ b/composite.cpp @@ -37,6 +37,7 @@ along with this program. If not, see . #include "useractions.h" #include "compositingprefs.h" #include "notifications.h" +#include "xcbutils.h" #include @@ -874,8 +875,8 @@ xcb_pixmap_t Toplevel::createWindowPixmap() XServerGrabber grabber(); xcb_pixmap_t pix = xcb_generate_id(connection()); xcb_void_cookie_t namePixmapCookie = xcb_composite_name_window_pixmap_checked(connection(), frameId(), pix); - xcb_get_window_attributes_cookie_t attribsCookie = xcb_get_window_attributes(connection(), frameId()); - xcb_get_geometry_cookie_t geometryCookie = xcb_get_geometry(connection(), frameId()); + Xcb::WindowAttributes windowAttributes(frameId()); + Xcb::WindowGeometry windowGeometry(frameId()); if (xcb_generic_error_t *error = xcb_request_check(connection(), namePixmapCookie)) { kDebug(1212) << "Creating window pixmap failed: " << error->error_code; free(error); @@ -883,16 +884,13 @@ xcb_pixmap_t Toplevel::createWindowPixmap() } // check that the received pixmap is valid and actually matches what we // know about the window (i.e. size) - ScopedCPointer error; - ScopedCPointer attribs(xcb_get_window_attributes_reply(connection(), attribsCookie, &error)); - if (!error.isNull() || attribs.isNull() || attribs->map_state != XCB_MAP_STATE_VIEWABLE) { + if (!windowAttributes || windowAttributes->map_state != XCB_MAP_STATE_VIEWABLE) { kDebug(1212) << "Creating window pixmap failed: " << this; xcb_free_pixmap(connection(), pix); return XCB_PIXMAP_NONE; } - ScopedCPointer geometry(xcb_get_geometry_reply(connection(), geometryCookie, &error)); - if (!error.isNull() || geometry.isNull() || - geometry->width != width() || geometry->height != height()) { + if (!windowGeometry || + windowGeometry->width != width() || windowGeometry->height != height()) { kDebug(1212) << "Creating window pixmap failed: " << this; xcb_free_pixmap(connection(), pix); return XCB_PIXMAP_NONE; diff --git a/overlaywindow.cpp b/overlaywindow.cpp index 8ef7051b82..3602c12aba 100644 --- a/overlaywindow.cpp +++ b/overlaywindow.cpp @@ -54,10 +54,7 @@ bool OverlayWindow::create() if (!Xcb::Extensions::self()->isShapeInputAvailable()) // needed in setupOverlay() return false; #ifdef KWIN_HAVE_XCOMPOSITE_OVERLAY - ScopedCPointer overlay = - xcb_composite_get_overlay_window_reply(connection(), - xcb_composite_get_overlay_window(connection(), rootWindow()), - NULL); + Xcb::OverlayWindow overlay(rootWindow()); if (overlay.isNull()) { return false; } diff --git a/workspace.cpp b/workspace.cpp index 8b432415a1..9183fd66da 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -409,33 +409,26 @@ void Workspace::init() StackingUpdatesBlocker blocker(this); bool fixoffset = KCmdLineArgs::parsedArgs()->getOption("crashes").toInt() > 0; - xcb_connection_t *conn = connection(); - xcb_query_tree_reply_t *tree = xcb_query_tree_reply(conn, - xcb_query_tree_unchecked(conn, rootWindow()), 0); - xcb_window_t *wins = xcb_query_tree_children(tree); + Xcb::Tree tree(rootWindow()); + xcb_window_t *wins = xcb_query_tree_children(tree.data()); - QVector attr_cookies; - QVector geom_cookies; - - attr_cookies.reserve(tree->children_len); - geom_cookies.reserve(tree->children_len); + QVector windowAttributes(tree->children_len); + QVector windowGeometries(tree->children_len); // Request the attributes and geometries of all toplevel windows for (int i = 0; i < tree->children_len; i++) { - attr_cookies << xcb_get_window_attributes(conn, wins[i]); - geom_cookies << xcb_get_geometry(conn, wins[i]); + windowAttributes[i] = Xcb::WindowAttributes(wins[i]); + windowGeometries[i] = Xcb::WindowGeometry(wins[i]); } // Get the replies for (int i = 0; i < tree->children_len; i++) { - ScopedCPointer attr - = xcb_get_window_attributes_reply(conn, attr_cookies[i], 0); - ScopedCPointer geometry - = xcb_get_geometry_reply(conn, geom_cookies[i], 0); + Xcb::WindowAttributes attr(windowAttributes.at(i)); - if (!attr || !geometry) + if (attr.isNull()) { continue; + } if (attr->override_redirect) { if (attr->map_state == XCB_MAP_STATE_VIEWABLE && @@ -443,16 +436,15 @@ void Workspace::init() // ### This will request the attributes again createUnmanaged(wins[i]); } else if (attr->map_state != XCB_MAP_STATE_UNMAPPED) { - if (fixoffset) - fixPositionAfterCrash(wins[i], geometry); + if (fixoffset) { + fixPositionAfterCrash(wins[i], windowGeometries[i].data()); + } // ### This will request the attributes again createClient(wins[i], true); } } - free(tree); - // Propagate clients, will really happen at the end of the updates blocker block updateStackingOrder(true); diff --git a/xcbutils.h b/xcbutils.h index 5e7417825a..caa28f6ac1 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -26,6 +26,7 @@ along with this program. If not, see . #include #include +#include namespace KWin { @@ -149,6 +150,7 @@ private: }; typedef Wrapper WindowAttributes; +typedef Wrapper OverlayWindow; class WindowGeometry : public Wrapper @@ -166,6 +168,16 @@ public: } }; +class Tree : public Wrapper +{ +public: + explicit Tree(WindowId window) : Wrapper(window) {} + + inline WindowId *children() { + return xcb_query_tree_children(data()); + } +}; + class ExtensionData { public: