support the kwayland contrast protocol

support wayland as well in the background contrast effect
REVIEW:125035
This commit is contained in:
Marco Martin 2015-09-03 17:00:24 +02:00
parent 3f5bf65a9e
commit d3053fab58
2 changed files with 40 additions and 1 deletions

View file

@ -26,6 +26,10 @@
#include <QMatrix4x4>
#include <QLinkedList>
#include <KWayland/Server/surface_interface.h>
#include <KWayland/Server/contrast_interface.h>
#include <KWayland/Server/display.h>
namespace KWin
{
@ -33,6 +37,11 @@ static const QByteArray s_contrastAtomName = QByteArrayLiteral("_KDE_NET_WM_BACK
ContrastEffect::ContrastEffect()
{
KWayland::Server::Display *display = effects->waylandDisplay();
if (display) {
display->createContrastManager(this)->create();
}
shader = ContrastShader::create();
reconfigure(ReconfigureAll);
@ -46,6 +55,7 @@ ContrastEffect::ContrastEffect()
}
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long)));
connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged()));
@ -102,7 +112,16 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) const
shader->setColorMatrix(colorMatrix);
}
if (region.isEmpty() && !value.isNull()) {
KWayland::Server::SurfaceInterface *surf = w->surface();
if (surf && surf->contrast()) {
region = surf->contrast()->region();
shader->setColorMatrix(colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()));
}
//!value.isNull() full window in X11 case, surf->contrast()
//valid, full window in wayland case
if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) {
// Set the data to a dummy value.
// This is needed to be able to distinguish between the value not
// being set, and being set to an empty region.
@ -113,9 +132,27 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) const
void ContrastEffect::slotWindowAdded(EffectWindow *w)
{
KWayland::Server::SurfaceInterface *surf = w->surface();
if (surf) {
m_contrastChangedConnections[w] = connect(surf, &KWayland::Server::SurfaceInterface::contrastChanged, this, [this, w] () {
if (w) {
updateContrastRegion(w);
}
});
}
updateContrastRegion(w);
}
void ContrastEffect::slotWindowDeleted(EffectWindow *w)
{
if (m_contrastChangedConnections.contains(w)) {
disconnect(m_contrastChangedConnections[w]);
m_contrastChangedConnections.remove(w);
}
}
void ContrastEffect::slotPropertyNotify(EffectWindow *w, long atom)
{
if (w && atom == net_wm_contrast_region) {

View file

@ -58,6 +58,7 @@ public:
public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *w);
void slotWindowDeleted(KWin::EffectWindow *w);
void slotPropertyNotify(KWin::EffectWindow *w, long atom);
void slotScreenGeometryChanged();
@ -74,6 +75,7 @@ private:
long net_wm_contrast_region;
QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea
QRegion m_currentContrast; // keeps track of the currently contrasted area of non-caching windows(from bottom to top)
QHash< const EffectWindow*, QMetaObject::Connection > m_contrastChangedConnections; // used only in Wayland to keep track of effect changed
};
inline