From c29a622be1a3188e894db5e2068800a0e50c1a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 10 Sep 2013 13:06:09 +0200 Subject: [PATCH] Introduce a wrapper class for InternAtom Not extending Xcb::Wrapper as it does not operate on a window. Instead it is a specified class for the specific usecase. --- xcbutils.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/xcbutils.h b/xcbutils.h index 047885e1ec..9495d891fb 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -159,6 +159,49 @@ private: Reply *m_reply; }; +class Atom +{ +public: + explicit Atom(const QByteArray &name, bool onlyIfExists = false) + : m_retrieved(false) + , m_cookie(xcb_intern_atom_unchecked(connection(), onlyIfExists, name.length(), name.constData())) + , m_atom(XCB_ATOM_NONE) + , m_name(name) + { + } + + ~Atom() { + if (!m_retrieved && m_cookie.sequence) { + xcb_discard_reply(connection(), m_cookie.sequence); + } + } + + operator xcb_atom_t() const { + (const_cast(this))->getReply(); + return m_atom; + } + + inline const QByteArray &name() const { + return m_name; + } + +private: + void getReply() { + if (m_retrieved || !m_cookie.sequence) { + return; + } + ScopedCPointer reply(xcb_intern_atom_reply(connection(), m_cookie, nullptr)); + if (!reply.isNull()) { + m_atom = reply->atom; + } + m_retrieved = true; + } + bool m_retrieved; + xcb_intern_atom_cookie_t m_cookie; + xcb_atom_t m_atom; + QByteArray m_name; +}; + typedef Wrapper WindowAttributes; typedef Wrapper OverlayWindow;