From 3af443867f577bc02ae56e81e17f6610af989f6d Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Mon, 4 Aug 2014 09:56:45 +0200 Subject: [PATCH] added compositing methods --- kstyle/breezehelper.cpp | 66 +++++++++++++++++++++++++++++++++++++++-- kstyle/breezehelper.h | 39 +++++++++++++++++++++++- 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index c288a38b..d21700cf 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -25,14 +25,35 @@ #include "breezemetrics.h" #include +#include + +#include #include namespace Breeze { //____________________________________________________________________ Helper::Helper( KSharedConfig::Ptr config ): - _config( config ) - {} + _config( config ), + _isX11( false ) + { + + #if HAVE_X11 + + // initialize X11 flag + _isX11 = QGuiApplication::platformName() == QStringLiteral("xcb"); + + + if( _isX11 ) + { + // create compositing screen + const QString atomName( QStringLiteral( "_NET_WM_CM_S%1" ).arg( QX11Info::appScreen() ) ); + _compositingManagerAtom = createAtom( atomName ); + } + + #endif + + } //____________________________________________________________________ KSharedConfigPtr Helper::config() const @@ -878,4 +899,45 @@ namespace Breeze } + //________________________________________________________________________________________________________ + bool Helper::compositingActive( void ) const + { + + #if HAVE_X11 + if( isX11() ) + { + // direct call to X + xcb_get_selection_owner_cookie_t cookie( xcb_get_selection_owner( QX11Info::connection(), _compositingManagerAtom ) ); + ScopedPointer reply( xcb_get_selection_owner_reply( QX11Info::connection(), cookie, nullptr ) ); + return reply && reply->owner; + + } + #endif + + // use KWindowSystem + return KWindowSystem::compositingActive(); + + } + + + #if HAVE_X11 + + //____________________________________________________________________ + xcb_atom_t Helper::createAtom( const QString& name ) const + { + + if( isX11() ) + { + + xcb_connection_t* connection( QX11Info::connection() ); + xcb_intern_atom_cookie_t cookie( xcb_intern_atom( connection, false, name.size(), qPrintable( name ) ) ); + ScopedPointer reply( xcb_intern_atom_reply( connection, cookie, nullptr) ); + return reply ? reply->atom:0; + + } else return 0; + + } + + #endif + } diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index 04536934..ab773983 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -29,6 +29,12 @@ #include #include +#include + +#if HAVE_X11 +#include +#include +#endif namespace Breeze { @@ -189,6 +195,28 @@ namespace Breeze //@} + //!@name compositing utilities + //@{ + + //! true if style was compiled for and is running on X11 + bool isX11() const + { return _isX11; } + + //! returns true if compositing is active + bool compositingActive( void ) const; + + //! returns true if a given widget supports alpha channel + bool hasAlphaChannel( const QWidget* ) const; + + #if HAVE_X11 + + //! create xcb atom + xcb_atom_t createAtom( const QString& ) const; + + #endif + + //@} + protected: //! return color key for a given color, properly accounting for invalid colors @@ -210,7 +238,16 @@ namespace Breeze KStatefulBrush _viewNegativeTextBrush; //@} - }; + bool _isX11; + + #if HAVE_X11 + + //! atom used for compositing manager + xcb_atom_t _compositingManagerAtom; + + #endif + + }; }