From c1b4167598f192228d06cd7a26f72bb3d21379d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 16 Apr 2014 14:27:48 +0200 Subject: [PATCH] [effects] Allow Built-In Effects using xcbutils.h xcbutils.h has quite a few inline only implementations such as Xcb::Atom, the Wrappers, Xcb::Window and the convenient methods. Thus there is nothing wrong with using it from the built-in Effects. Xcb::Atom is used in Glide and Logout Effect to get the atom. To keep the logic of the existing code it got extended by a bool isValid() which gets the reply and returns true if the atom is set. REVIEW: 117587 --- effects/CMakeLists.txt | 2 ++ effects/glide/glide.cpp | 19 +++++++------------ effects/glide/glide.h | 2 ++ effects/logout/logout.cpp | 9 ++------- effects/logout/logout.h | 3 ++- xcbutils.h | 8 ++++++++ 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index b247db6388..d92c2a08b8 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories(${KWIN_SOURCE_DIR}) # for xcbutils.h + set(kwin_effect_OWN_LIBS kwineffects ) diff --git a/effects/glide/glide.cpp b/effects/glide/glide.cpp index 7345b11a90..7f690a43af 100644 --- a/effects/glide/glide.cpp +++ b/effects/glide/glide.cpp @@ -32,18 +32,13 @@ namespace KWin { static const int IsGlideWindow = 0x22A982D4; -static xcb_atom_t slideAtom; -static const QByteArray s_slideAtomName = QByteArrayLiteral("_KDE_SLIDE"); GlideEffect::GlideEffect() + : Effect() + , m_atom(QByteArrayLiteral("_KDE_SLIDE")) { - slideAtom = XCB_ATOM_NONE; - xcb_connection_t *c = xcbConnection(); - const auto cookie = xcb_intern_atom(c, false, s_slideAtomName.length(), s_slideAtomName.constData()); - QScopedPointer atom(xcb_intern_atom_reply(c, cookie, nullptr)); - if (atom) { - slideAtom = atom->atom; - effects->registerPropertyType( slideAtom, true ); + if (m_atom.isValid()) { + effects->registerPropertyType( m_atom, true ); } reconfigure(ReconfigureAll); connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*))); @@ -53,8 +48,8 @@ GlideEffect::GlideEffect() GlideEffect::~GlideEffect() { - if (slideAtom) { - effects->registerPropertyType( slideAtom, false ); + if (m_atom.isValid()) { + effects->registerPropertyType( m_atom, false ); } } @@ -219,7 +214,7 @@ bool GlideEffect::isGlideWindow(EffectWindow* w) return false; if (w->data(IsGlideWindow).toBool()) return true; - if (slideAtom && !w->readProperty( slideAtom, slideAtom, 32 ).isNull()) + if (m_atom.isValid() && !w->readProperty( m_atom, m_atom, 32 ).isNull()) return false; if (w->hasDecoration()) return true; diff --git a/effects/glide/glide.h b/effects/glide/glide.h index 81e11a9699..3adda141f6 100644 --- a/effects/glide/glide.h +++ b/effects/glide/glide.h @@ -24,6 +24,7 @@ along with this program. If not, see . #define KWIN_GLIDE_H #include +#include class QTimeLine; @@ -74,6 +75,7 @@ private: void glideIn(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info); void glideOut(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info); bool isGlideWindow(EffectWindow* w); + Xcb::Atom m_atom; InfoHash windows; float duration; int angle; diff --git a/effects/logout/logout.cpp b/effects/logout/logout.cpp index 4fff0d7b55..effc99bcaa 100644 --- a/effects/logout/logout.cpp +++ b/effects/logout/logout.cpp @@ -41,20 +41,15 @@ LogoutEffect::LogoutEffect() , logoutWindow(NULL) , logoutWindowClosed(true) , logoutWindowPassed(false) - , logoutAtom(XCB_ATOM_NONE) + , logoutAtom(QByteArrayLiteral("_KDE_LOGGING_OUT")) , canDoPersistent(false) , ignoredWindows() , m_vignettingShader(NULL) , m_blurShader(NULL) , m_shadersDir(QStringLiteral("kwin/shaders/1.10/")) { - xcb_connection_t *c = xcbConnection(); - const QByteArray &name = QByteArrayLiteral("_KDE_LOGGING_OUT"); - const auto cookie = xcb_intern_atom(c, false, name.length(), name.constData()); - QScopedPointer atom(xcb_intern_atom_reply(c, cookie, nullptr)); - if (atom) { + if (logoutAtom.isValid()) { // Persistent effect - logoutAtom = atom->atom; effects->registerPropertyType(logoutAtom, true); } diff --git a/effects/logout/logout.h b/effects/logout/logout.h index 8cb6f24756..9feb774b98 100644 --- a/effects/logout/logout.h +++ b/effects/logout/logout.h @@ -24,6 +24,7 @@ along with this program. If not, see . #define KWIN_LOGOUT_H #include +#include namespace KWin @@ -69,7 +70,7 @@ private: bool logoutWindowPassed; // Persistent effect - xcb_atom_t logoutAtom; + Xcb::Atom logoutAtom; bool canDoPersistent; EffectWindowList ignoredWindows; diff --git a/xcbutils.h b/xcbutils.h index 2762f2e0ac..7dda90b895 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -472,6 +472,14 @@ public: (const_cast(this))->getReply(); return m_atom; } + bool isValid() { + getReply(); + return m_atom != XCB_ATOM_NONE; + } + bool isValid() const { + (const_cast(this))->getReply(); + return m_atom != XCB_ATOM_NONE; + } inline const QByteArray &name() const { return m_name;