From 634a84e5c03dba0641370075ae4edc57cc3138b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 11 Sep 2013 08:21:44 +0200 Subject: [PATCH] Port reading the shadow property to XCB --- shadow.cpp | 25 +++++++++++-------------- shadow.h | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/shadow.cpp b/shadow.cpp index cbe7aab1cb..1d24a5922d 100644 --- a/shadow.cpp +++ b/shadow.cpp @@ -46,7 +46,7 @@ Shadow *Shadow::createShadow(Toplevel *toplevel) if (!effects) { return NULL; } - QVector data = Shadow::readX11ShadowProperty(toplevel->window()); + auto data = Shadow::readX11ShadowProperty(toplevel->window()); if (!data.isEmpty()) { Shadow *shadow = NULL; if (effects->isOpenGLCompositing()) { @@ -72,27 +72,24 @@ Shadow *Shadow::createShadow(Toplevel *toplevel) } } -QVector< long > Shadow::readX11ShadowProperty(WId id) +QVector< uint32_t > Shadow::readX11ShadowProperty(xcb_window_t id) { - QVector ret; - Atom type; - int format, status; - unsigned long nitems = 0; - unsigned long extra = 0; - unsigned char *data = 0; - status = XGetWindowProperty(display(), id, atoms->kde_net_wm_shadow, 0, 12, false, XA_CARDINAL, &type, &format, &nitems, &extra, &data); - if (status == Success && type == XA_CARDINAL && format == 32 && nitems == 12) { - long* shadow = reinterpret_cast< long* >(data); + QVector ret; + xcb_connection_t *c = connection(); + const auto cookie = xcb_get_property_unchecked(c, false, id, atoms->kde_net_wm_shadow, + XCB_ATOM_CARDINAL, 0, 12); + ScopedCPointer prop(xcb_get_property_reply(c, cookie, nullptr)); + if (!prop.isNull() && prop->type == XCB_ATOM_CARDINAL && prop->format == 32 ) { + uint32_t* shadow = reinterpret_cast< uint32_t* >(xcb_get_property_value(prop.data())); ret.reserve(12); for (int i=0; i<12; ++i) { ret << shadow[i]; } - XFree(data); } return ret; } -bool Shadow::init(const QVector< long > &data) +bool Shadow::init(const QVector< uint32_t > &data) { QVector pixmapGeometries(ShadowElementsCount); QVector getImageCookies(ShadowElementsCount); @@ -228,7 +225,7 @@ void Shadow::buildQuads() bool Shadow::updateShadow() { - QVector data = Shadow::readX11ShadowProperty(m_topLevel->window()); + auto data = Shadow::readX11ShadowProperty(m_topLevel->window()); if (data.isEmpty()) { if (m_topLevel && m_topLevel->effectWindow() && m_topLevel->effectWindow()->sceneWindow() && m_topLevel->effectWindow()->sceneWindow()->shadow()) { diff --git a/shadow.h b/shadow.h index 8ce9802237..b8d5db67a0 100644 --- a/shadow.h +++ b/shadow.h @@ -141,8 +141,8 @@ protected: WindowQuadList m_shadowQuads; private: - static QVector readX11ShadowProperty(WId id); - bool init(const QVector &data); + static QVector readX11ShadowProperty(xcb_window_t id); + bool init(const QVector &data); Toplevel *m_topLevel; // shadow pixmaps QPixmap m_shadowElements[ShadowElementsCount];