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.
This commit is contained in:
parent
2d4b67d361
commit
6c213d4392
4 changed files with 31 additions and 32 deletions
|
@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "useractions.h"
|
||||
#include "compositingprefs.h"
|
||||
#include "notifications.h"
|
||||
#include "xcbutils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -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<xcb_generic_error_t> error;
|
||||
ScopedCPointer<xcb_get_window_attributes_reply_t> 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<xcb_get_geometry_reply_t> 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;
|
||||
|
|
|
@ -54,10 +54,7 @@ bool OverlayWindow::create()
|
|||
if (!Xcb::Extensions::self()->isShapeInputAvailable()) // needed in setupOverlay()
|
||||
return false;
|
||||
#ifdef KWIN_HAVE_XCOMPOSITE_OVERLAY
|
||||
ScopedCPointer<xcb_composite_get_overlay_window_reply_t> 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;
|
||||
}
|
||||
|
|
|
@ -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<xcb_get_window_attributes_cookie_t> attr_cookies;
|
||||
QVector<xcb_get_geometry_cookie_t> geom_cookies;
|
||||
|
||||
attr_cookies.reserve(tree->children_len);
|
||||
geom_cookies.reserve(tree->children_len);
|
||||
QVector<Xcb::WindowAttributes> windowAttributes(tree->children_len);
|
||||
QVector<Xcb::WindowGeometry> 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<xcb_get_window_attributes_reply_t> attr
|
||||
= xcb_get_window_attributes_reply(conn, attr_cookies[i], 0);
|
||||
ScopedCPointer<xcb_get_geometry_reply_t> 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);
|
||||
|
||||
|
|
12
xcbutils.h
12
xcbutils.h
|
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QRect>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/composite.h>
|
||||
|
||||
namespace KWin {
|
||||
|
||||
|
@ -149,6 +150,7 @@ private:
|
|||
};
|
||||
|
||||
typedef Wrapper<xcb_get_window_attributes_reply_t, xcb_get_window_attributes_cookie_t, &xcb_get_window_attributes_reply, &xcb_get_window_attributes_unchecked> WindowAttributes;
|
||||
typedef Wrapper<xcb_composite_get_overlay_window_reply_t, xcb_composite_get_overlay_window_cookie_t, &xcb_composite_get_overlay_window_reply, &xcb_composite_get_overlay_window_unchecked> OverlayWindow;
|
||||
|
||||
|
||||
class WindowGeometry : public Wrapper<xcb_get_geometry_reply_t, xcb_get_geometry_cookie_t, &xcb_get_geometry_reply, &xcb_get_geometry_unchecked>
|
||||
|
@ -166,6 +168,16 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class Tree : public Wrapper<xcb_query_tree_reply_t, xcb_query_tree_cookie_t, &xcb_query_tree_reply, &xcb_query_tree_unchecked>
|
||||
{
|
||||
public:
|
||||
explicit Tree(WindowId window) : Wrapper<xcb_query_tree_reply_t, xcb_query_tree_cookie_t, &xcb_query_tree_reply, &xcb_query_tree_unchecked>(window) {}
|
||||
|
||||
inline WindowId *children() {
|
||||
return xcb_query_tree_children(data());
|
||||
}
|
||||
};
|
||||
|
||||
class ExtensionData
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue