From 7287019050c58d25939c9fdd686abd4a2e09a07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 3 Apr 2011 12:43:57 +0200 Subject: [PATCH] Update cached Shadow information on size changes In order to notice when the geometry changes a new signal is added to toplevel and both Unmanaged and Client connect all their signals which are emitted whenever the geometry changes in some way to this new signal. Shadow connects to the signal and updates the quads and region whenever the size changes. --- client.cpp | 4 ++++ shadow.cpp | 22 +++++++++++++++++++--- shadow.h | 5 +++++ toplevel.h | 1 + unmanaged.cpp | 1 + 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/client.cpp b/client.cpp index ec60bde9c7..0172a10c85 100644 --- a/client.cpp +++ b/client.cpp @@ -194,6 +194,10 @@ Client::Client(Workspace* ws) ready_for_painting = false; // wait for first damage or sync reply #endif + connect(this, SIGNAL(clientGeometryShapeChanged(KWin::Client*,QRect)), SIGNAL(geometryChanged())); + connect(this, SIGNAL(clientMaximizedStateChanged(KWin::Client*,KDecorationDefines::MaximizeMode)), SIGNAL(geometryChanged())); + connect(this, SIGNAL(clientStepUserMovedResized(KWin::Client*,QRect)), SIGNAL(geometryChanged())); + // SELI TODO: Initialize xsizehints?? } diff --git a/shadow.cpp b/shadow.cpp index 309a146b18..9e9179a608 100644 --- a/shadow.cpp +++ b/shadow.cpp @@ -31,7 +31,9 @@ namespace KWin Shadow::Shadow(Toplevel *toplevel) : m_topLevel(toplevel) + , m_cachedSize(toplevel->geometry().size()) { + connect(m_topLevel, SIGNAL(geometryChanged()), SLOT(geometryChanged())); } Shadow::~Shadow() @@ -99,14 +101,18 @@ bool Shadow::init(const QVector< long > &data) m_rightOffset = data[ShadowElementsCount+1]; m_bottomOffset = data[ShadowElementsCount+2]; m_leftOffset = data[ShadowElementsCount+3]; - // prepare shadow region + updateShadowRegion(); + buildQuads(); + return true; +} + +void Shadow::updateShadowRegion() +{ const QRect topRect(0, - m_topOffset, m_topLevel->width(), m_topOffset); const QRect rightRect(m_topLevel->width(), - m_topOffset, m_rightOffset, m_topLevel->height() + m_topOffset + m_bottomOffset); const QRect bottomRect(0, m_topLevel->height(), m_topLevel->width(), m_bottomOffset); const QRect leftRect(- m_leftOffset, - m_topOffset, m_leftOffset, m_topLevel->height() + m_topOffset + m_bottomOffset); m_shadowRegion = QRegion(topRect).united(rightRect).united(bottomRect).united(leftRect); - buildQuads(); - return true; } void Shadow::buildQuads() @@ -184,6 +190,16 @@ bool Shadow::updateShadow() void Shadow::setToplevel(Toplevel *topLevel) { m_topLevel = topLevel; + connect(m_topLevel, SIGNAL(geometryChanged()), SLOT(geometryChanged())); +} +void Shadow::geometryChanged() +{ + if (m_cachedSize == m_topLevel->geometry().size()) { + return; + } + m_cachedSize = m_topLevel->geometry().size(); + updateShadowRegion(); + buildQuads(); } } // namespace diff --git a/shadow.h b/shadow.h index ee6dec35dc..7127db95ae 100644 --- a/shadow.h +++ b/shadow.h @@ -92,6 +92,9 @@ public: **/ void setToplevel(Toplevel *toplevel); +public Q_SLOTS: + void geometryChanged(); + protected: Shadow(Toplevel *toplevel); enum ShadowElements { @@ -121,6 +124,7 @@ protected: return m_leftOffset; }; virtual void buildQuads(); + void updateShadowRegion(); private: static QVector readX11ShadowProperty(WId id); @@ -136,6 +140,7 @@ private: // caches QRegion m_shadowRegion; WindowQuadList m_shadowQuads; + QSize m_cachedSize; }; } diff --git a/toplevel.h b/toplevel.h index 49ac824b71..15a9aa361a 100644 --- a/toplevel.h +++ b/toplevel.h @@ -162,6 +162,7 @@ signals: void opacityChanged(KWin::Toplevel* toplevel, qreal oldOpacity); void damaged(KWin::Toplevel* toplevel, const QRect& damage); void propertyNotify(KWin::Toplevel* toplevel, long a); + void geometryChanged(); protected: virtual ~Toplevel(); diff --git a/unmanaged.cpp b/unmanaged.cpp index 7c36451b49..32908aabd2 100644 --- a/unmanaged.cpp +++ b/unmanaged.cpp @@ -32,6 +32,7 @@ namespace KWin Unmanaged::Unmanaged(Workspace* ws) : Toplevel(ws) { + connect(this, SIGNAL(unmanagedGeometryShapeChanged(KWin::Unmanaged*,QRect)), SIGNAL(geometryChanged())); } Unmanaged::~Unmanaged()