From edd0950f96364e6a555dcc8c256713a0c311f796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 6 Mar 2011 10:30:23 +0100 Subject: [PATCH] WindowOpacityChanged becomes a signal --- effects.cpp | 14 ++++++++------ effects.h | 2 +- effects/fade/fade.cpp | 3 ++- effects/fade/fade.h | 2 +- events.cpp | 6 ++---- libkwineffects/kwineffects.cpp | 4 ---- libkwineffects/kwineffects.h | 9 ++++++++- toplevel.cpp | 3 +-- toplevel.h | 3 +++ 9 files changed, 26 insertions(+), 20 deletions(-) diff --git a/effects.cpp b/effects.cpp index e145e4e2f5..b0dfdd0421 100644 --- a/effects.cpp +++ b/effects.cpp @@ -105,9 +105,11 @@ EffectsHandlerImpl::EffectsHandlerImpl(CompositingType type) foreach (Client *c, ws->clientList()) { connect(c, SIGNAL(clientClosed(KWin::Client*)), this, SLOT(slotClientClosed(KWin::Client*))); connect(c, SIGNAL(clientMaximizedStateChanged(KWin::Client*,KDecorationDefines::MaximizeMode)), this, SLOT(slotClientMaximized(KWin::Client*,KDecorationDefines::MaximizeMode))); + connect(c, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); } foreach (Unmanaged *u, ws->unmanagedList()) { connect(u, SIGNAL(unmanagedClosed(KWin::Unmanaged*)), this, SLOT(slotUnmanagedClosed(KWin::Unmanaged*))); + connect(u, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); } reconfigure(); } @@ -287,26 +289,26 @@ void EffectsHandlerImpl::windowMoveResizeGeometryUpdate(EffectWindow* c, const Q ep.second->windowMoveResizeGeometryUpdate(c, geometry); } -void EffectsHandlerImpl::windowOpacityChanged(EffectWindow* c, double old_opacity) +void EffectsHandlerImpl::slotOpacityChanged(Toplevel *t, qreal oldOpacity) { - if (!c) + if (t->opacity() == oldOpacity) { return; - if (static_cast(c)->window()->opacity() == old_opacity) - return; - foreach (const EffectPair & ep, loaded_effects) - ep.second->windowOpacityChanged(c, old_opacity); + } + emit windowOpacityChanged(t->effectWindow(), oldOpacity, (qreal)t->opacity()); } void EffectsHandlerImpl::slotClientAdded(Client *c) { connect(c, SIGNAL(clientClosed(KWin::Client*)), this, SLOT(slotClientClosed(KWin::Client*))); connect(c, SIGNAL(clientMaximizedStateChanged(KWin::Client*,KDecorationDefines::MaximizeMode)), this, SLOT(slotClientMaximized(KWin::Client*,KDecorationDefines::MaximizeMode))); + connect(c, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); emit windowAdded(c->effectWindow()); } void EffectsHandlerImpl::slotUnmanagedAdded(Unmanaged *u) { connect(u, SIGNAL(unmanagedClosed(KWin::Unmanaged*)), this, SLOT(slotUnmanagedClosed(KWin::Unmanaged*))); + connect(u, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); emit windowAdded(u->effectWindow()); } diff --git a/effects.h b/effects.h index 28ab72f8d2..bcca72788d 100644 --- a/effects.h +++ b/effects.h @@ -159,7 +159,6 @@ public: // internal (used by kwin core or compositing code) void startPaint(); void windowMoveResizeGeometryUpdate(EffectWindow* c, const QRect& geometry); - void windowOpacityChanged(EffectWindow* c, double old_opacity); void windowMinimized(EffectWindow* c); void windowUnminimized(EffectWindow* c); void clientGroupItemSwitched(EffectWindow* from, EffectWindow* to); @@ -202,6 +201,7 @@ protected Q_SLOTS: void slotClientActivated(KWin::Client *c); void slotDeletedRemoved(KWin::Deleted *d); void slotClientMaximized(KWin::Client *c, KDecorationDefines::MaximizeMode maxMode); + void slotOpacityChanged(KWin::Toplevel *t, qreal oldOpacity); protected: KLibrary* findEffectLibrary(KService* service); diff --git a/effects/fade/fade.cpp b/effects/fade/fade.cpp index ef92feb98e..52f0e3758f 100644 --- a/effects/fade/fade.cpp +++ b/effects/fade/fade.cpp @@ -33,6 +33,7 @@ FadeEffect::FadeEffect() connect(effects, SIGNAL(windowAdded(EffectWindow*)), this, SLOT(slotWindowAdded(EffectWindow*))); connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*))); connect(effects, SIGNAL(windowDeleted(EffectWindow*)), this, SLOT(slotWindowDeleted(EffectWindow*))); + connect(effects, SIGNAL(windowOpacityChanged(EffectWindow*,qreal,qreal)), this, SLOT(slotWindowOpacityChanged(EffectWindow*,qreal))); } void FadeEffect::reconfigure(ReconfigureFlags) @@ -147,7 +148,7 @@ void FadeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa effects->paintWindow(w, mask, region, data); } -void FadeEffect::windowOpacityChanged(EffectWindow* w, double old_opacity) +void FadeEffect::slotWindowOpacityChanged(EffectWindow* w, qreal old_opacity) { if (!windows.contains(w)) windows[ w ].opacity = old_opacity; diff --git a/effects/fade/fade.h b/effects/fade/fade.h index 487dd2ddd2..c26298adff 100644 --- a/effects/fade/fade.h +++ b/effects/fade/fade.h @@ -38,7 +38,6 @@ public: virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); // TODO react also on virtual desktop changes - virtual void windowOpacityChanged(EffectWindow* c, double old_opacity); bool isFadeWindow(EffectWindow* w); @@ -46,6 +45,7 @@ public Q_SLOTS: void slotWindowAdded(EffectWindow* c); void slotWindowClosed(EffectWindow *c); void slotWindowDeleted(EffectWindow *w); + void slotWindowOpacityChanged(EffectWindow *w, qreal oldOpacity); private: class WindowInfo; QHash< const EffectWindow*, WindowInfo > windows; diff --git a/events.cpp b/events.cpp index 390313f92a..e4b595afe1 100644 --- a/events.cpp +++ b/events.cpp @@ -576,9 +576,8 @@ bool Client::windowEvent(XEvent* e) if (dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2Opacity) { if (compositing()) { addRepaintFull(); + emit opacityChanged(this, old_opacity); scene->windowOpacityChanged(this); - if (effects) - static_cast(effects)->windowOpacityChanged(effectWindow(), old_opacity); } else { // forward to the frame if there's possibly another compositing manager running NETWinInfo2 i(display(), frameId(), rootWindow(), 0); @@ -1613,9 +1612,8 @@ bool Unmanaged::windowEvent(XEvent* e) if (dirty[ NETWinInfo::PROTOCOLS2 ] & NET::WM2Opacity) { if (compositing()) { addRepaintFull(); + emit opacityChanged(this, old_opacity); scene->windowOpacityChanged(this); - if (effects) - static_cast(effects)->windowOpacityChanged(effectWindow(), old_opacity); } } switch(e->type) { diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp index 8749d2a3c8..7e980b6da8 100644 --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -123,10 +123,6 @@ void Effect::windowMoveResizeGeometryUpdate(EffectWindow* , const QRect&) { } -void Effect::windowOpacityChanged(EffectWindow*, double) -{ -} - void Effect::windowMinimized(EffectWindow*) { } diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index ad72827be9..4ec9555f0a 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -442,7 +442,6 @@ public: /** called when the geometry changed during moving/resizing. */ virtual void windowMoveResizeGeometryUpdate(EffectWindow* c, const QRect& geometry); - virtual void windowOpacityChanged(EffectWindow* c, double old_opacity); virtual void windowMinimized(EffectWindow* c); virtual void windowUnminimized(EffectWindow* c); virtual void clientGroupItemSwitched(EffectWindow* from, EffectWindow* to); @@ -874,6 +873,14 @@ Q_SIGNALS: * @since 4.7 **/ void windowUserMovedResized(EffectWindow *w, bool first, bool last); + /** + * Signal emitted when the windows opacity is changed. + * @param w The window whose opacity level is changed. + * @param oldOpacity The previous opacity level + * @param newOpacity The new opacity level + * @since 4.7 + **/ + void windowOpacityChanged(EffectWindow *w, qreal oldOpacity, qreal newOpacity); protected: QVector< EffectPair > loaded_effects; diff --git a/toplevel.cpp b/toplevel.cpp index fd6298c695..c19a228328 100644 --- a/toplevel.cpp +++ b/toplevel.cpp @@ -318,9 +318,8 @@ void Toplevel::setOpacity(double new_opacity) info->setOpacity(static_cast< unsigned long >(new_opacity * 0xffffffff)); if (compositing()) { addRepaintFull(); + emit opacityChanged(this, old_opacity); scene->windowOpacityChanged(this); - if (effects) - static_cast(effects)->windowOpacityChanged(effectWindow(), old_opacity); } } diff --git a/toplevel.h b/toplevel.h index ef0168a916..8e3dce270a 100644 --- a/toplevel.h +++ b/toplevel.h @@ -135,6 +135,9 @@ public: void resetDamage(const QRect& r); EffectWindowImpl* effectWindow(); +signals: + void opacityChanged(KWin::Toplevel* toplevel, qreal oldOpacity); + protected: virtual ~Toplevel(); void setWindowHandles(Window client, Window frame);