EffectsHandler emits desktopChanged signal

The first signal used between EffectsHandler and Effects.
The signal is actually emitted by the EffectsHandlerImpl and only
the interested effects connect to this signal.
EffectsHandlerImpl itself is also notified by a signal from Workspace,
allowing to remove one of the many if (effects) checks.
icc-effect-5.14.5
Martin Gräßlin 2011-02-25 20:41:10 +01:00
parent b3a5639967
commit c3a076b6a5
11 changed files with 39 additions and 20 deletions

View File

@ -95,6 +95,8 @@ EffectsHandlerImpl::EffectsHandlerImpl(CompositingType type)
, mouse_poll_ref_count(0) , mouse_poll_ref_count(0)
, current_paint_effectframe(0) , current_paint_effectframe(0)
{ {
Workspace *ws = Workspace::self();
connect(ws, SIGNAL(currentDesktopChanged(int)), this, SLOT(slotDesktopChanged(int)));
reconfigure(); reconfigure();
} }
@ -334,10 +336,12 @@ void EffectsHandlerImpl::clientGroupItemRemoved(EffectWindow* c, EffectWindow* g
ep.second->clientGroupItemRemoved(c, group); ep.second->clientGroupItemRemoved(c, group);
} }
void EffectsHandlerImpl::desktopChanged(int old) void EffectsHandlerImpl::slotDesktopChanged(int old)
{ {
foreach (const EffectPair & ep, loaded_effects) const int newDesktop = Workspace::self()->currentDesktop();
ep.second->desktopChanged(old); if (old != 0 && newDesktop != old) {
emit desktopChanged(old, newDesktop);
}
} }
void EffectsHandlerImpl::windowDamaged(EffectWindow* w, const QRect& r) void EffectsHandlerImpl::windowDamaged(EffectWindow* w, const QRect& r)

View File

@ -38,6 +38,7 @@ namespace KWin
class EffectsHandlerImpl : public EffectsHandler class EffectsHandlerImpl : public EffectsHandler
{ {
Q_OBJECT
public: public:
EffectsHandlerImpl(CompositingType type); EffectsHandlerImpl(CompositingType type);
virtual ~EffectsHandlerImpl(); virtual ~EffectsHandlerImpl();
@ -165,7 +166,6 @@ public:
void clientGroupItemSwitched(EffectWindow* from, EffectWindow* to); void clientGroupItemSwitched(EffectWindow* from, EffectWindow* to);
void clientGroupItemAdded(EffectWindow* from, EffectWindow* to); void clientGroupItemAdded(EffectWindow* from, EffectWindow* to);
void clientGroupItemRemoved(EffectWindow* c, EffectWindow* group); void clientGroupItemRemoved(EffectWindow* c, EffectWindow* group);
void desktopChanged(int old);
void windowDamaged(EffectWindow* w, const QRect& r); void windowDamaged(EffectWindow* w, const QRect& r);
void windowGeometryShapeChanged(EffectWindow* w, const QRect& old); void windowGeometryShapeChanged(EffectWindow* w, const QRect& old);
void tabBoxAdded(int mode); void tabBoxAdded(int mode);
@ -191,6 +191,9 @@ public:
QList<EffectWindow*> elevatedWindows() const; QList<EffectWindow*> elevatedWindows() const;
protected Q_SLOTS:
void slotDesktopChanged(int old);
protected: protected:
KLibrary* findEffectLibrary(KService* service); KLibrary* findEffectLibrary(KService* service);
void effectsChanged(); void effectsChanged();

View File

@ -38,6 +38,7 @@ CubeSlideEffect::CubeSlideEffect()
, desktopChangedWhileMoving(false) , desktopChangedWhileMoving(false)
, progressRestriction(0.0f) , progressRestriction(0.0f)
{ {
connect(effects, SIGNAL(desktopChanged(int, int)), this, SLOT(slotDesktopChanged(int, int)));
reconfigure(ReconfigureAll); reconfigure(ReconfigureAll);
} }
@ -417,7 +418,7 @@ void CubeSlideEffect::postPaintScreen()
} }
} }
void CubeSlideEffect::desktopChanged(int old) void CubeSlideEffect::slotDesktopChanged(int old, int current)
{ {
if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this)
return; return;
@ -499,10 +500,10 @@ void CubeSlideEffect::desktopChanged(int old)
} }
} else { } else {
// ignore pager layout // ignore pager layout
int left = old - effects->currentDesktop(); int left = old - current;
if (left < 0) if (left < 0)
left = effects->numberOfDesktops() + left; left = effects->numberOfDesktops() + left;
int right = effects->currentDesktop() - old; int right = current - old;
if (right < 0) if (right < 0)
right = effects->numberOfDesktops() + right; right = effects->numberOfDesktops() + right;
if (left < right) { if (left < right) {

View File

@ -41,10 +41,13 @@ public:
virtual void postPaintScreen(); virtual void postPaintScreen();
virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
virtual void desktopChanged(int old);
virtual void windowUserMovedResized(EffectWindow* c, bool first, bool last); virtual void windowUserMovedResized(EffectWindow* c, bool first, bool last);
static bool supported(); static bool supported();
private Q_SLOTS:
void slotDesktopChanged(int old, int current);
private: private:
enum RotationDirection { enum RotationDirection {
Left, Left,

View File

@ -30,6 +30,7 @@ KWIN_EFFECT(fadedesktop, FadeDesktopEffect)
FadeDesktopEffect::FadeDesktopEffect() FadeDesktopEffect::FadeDesktopEffect()
: m_fading(false) : m_fading(false)
{ {
connect(effects, SIGNAL(desktopChanged(int,int)), this, SLOT(slotDesktopChanged(int)));
m_timeline.setCurveShape(TimeLine::LinearCurve); m_timeline.setCurveShape(TimeLine::LinearCurve);
reconfigure(ReconfigureAll); reconfigure(ReconfigureAll);
} }
@ -88,7 +89,7 @@ void FadeDesktopEffect::paintWindow(EffectWindow *w, int mask, QRegion region, W
effects->paintWindow(w, mask, region, data); effects->paintWindow(w, mask, region, data);
} }
void FadeDesktopEffect::desktopChanged(int old) void FadeDesktopEffect::slotDesktopChanged(int old)
{ {
if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this)
return; return;

View File

@ -38,7 +38,9 @@ public:
virtual void postPaintScreen(); virtual void postPaintScreen();
virtual void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time); virtual void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time);
virtual void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data); virtual void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data);
virtual void desktopChanged(int old);
private Q_SLOTS:
void slotDesktopChanged(int old);
private: private:
bool m_fading; bool m_fading;

View File

@ -31,6 +31,7 @@ KWIN_EFFECT(slide, SlideEffect)
SlideEffect::SlideEffect() SlideEffect::SlideEffect()
: slide(false) : slide(false)
{ {
connect(effects, SIGNAL(desktopChanged(int,int)), this, SLOT(slotDesktopChanged(int,int)));
mTimeLine.setCurveShape(TimeLine::EaseInOutCurve); mTimeLine.setCurveShape(TimeLine::EaseInOutCurve);
reconfigure(ReconfigureAll); reconfigure(ReconfigureAll);
} }
@ -168,7 +169,7 @@ QRect SlideEffect::desktopRect(int desktop) const
return rect; return rect;
} }
void SlideEffect::desktopChanged(int old) void SlideEffect::slotDesktopChanged(int old, int current)
{ {
if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this)
return; return;
@ -198,7 +199,7 @@ void SlideEffect::desktopChanged(int old)
currentRegion |= (currentRegion & QRect(w, 0, w, h)).translated(-w, 0); currentRegion |= (currentRegion & QRect(w, 0, w, h)).translated(-w, 0);
currentRegion |= (currentRegion & QRect(0, h, w, h)).translated(0, -h); currentRegion |= (currentRegion & QRect(0, h, w, h)).translated(0, -h);
} }
QRect rect = desktopRect(effects->currentDesktop()); QRect rect = desktopRect(current);
if (currentRegion.contains(rect)) { if (currentRegion.contains(rect)) {
// current position is in new current desktop (e.g. quickly changing back), // current position is in new current desktop (e.g. quickly changing back),
// don't do full progress // don't do full progress

View File

@ -40,7 +40,10 @@ public:
virtual void postPaintScreen(); virtual void postPaintScreen();
virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
virtual void desktopChanged(int old);
private Q_SLOTS:
void slotDesktopChanged(int old, int current);
private: private:
QRect desktopRect(int desktop) const; QRect desktopRect(int desktop) const;
TimeLine mTimeLine; TimeLine mTimeLine;

View File

@ -179,10 +179,6 @@ void Effect::propertyNotify(EffectWindow* , long)
{ {
} }
void Effect::desktopChanged(int)
{
}
void Effect::windowDamaged(EffectWindow*, const QRect&) void Effect::windowDamaged(EffectWindow*, const QRect&)
{ {
} }

View File

@ -455,7 +455,6 @@ public:
virtual void clientGroupItemAdded(EffectWindow* from, EffectWindow* to); // from merged with to virtual void clientGroupItemAdded(EffectWindow* from, EffectWindow* to); // from merged with to
virtual void clientGroupItemRemoved(EffectWindow* c, EffectWindow* group); // c removed from group virtual void clientGroupItemRemoved(EffectWindow* c, EffectWindow* group); // c removed from group
virtual void windowInputMouseEvent(Window w, QEvent* e); virtual void windowInputMouseEvent(Window w, QEvent* e);
virtual void desktopChanged(int old);
virtual void windowDamaged(EffectWindow* w, const QRect& r); virtual void windowDamaged(EffectWindow* w, const QRect& r);
virtual void windowGeometryShapeChanged(EffectWindow* w, const QRect& old); virtual void windowGeometryShapeChanged(EffectWindow* w, const QRect& old);
virtual void mouseChanged(const QPoint& pos, const QPoint& oldpos, virtual void mouseChanged(const QPoint& pos, const QPoint& oldpos,
@ -832,6 +831,14 @@ public:
**/ **/
static KConfigGroup effectConfig(const QString& effectname); static KConfigGroup effectConfig(const QString& effectname);
Q_SIGNALS:
/**
* Signal emitted when the current desktop changed.
* @param oldDesktop The previously current desktop
* @param newDesktop The new current desktop
* @since 4.7
**/
void desktopChanged(int oldDesktop, int newDesktop);
protected: protected:
QVector< EffectPair > loaded_effects; QVector< EffectPair > loaded_effects;

View File

@ -1463,8 +1463,6 @@ bool Workspace::setCurrentDesktop(int new_desktop)
if (old_desktop != 0 && old_desktop != new_desktop && numberOfDesktops() > 1) if (old_desktop != 0 && old_desktop != new_desktop && numberOfDesktops() > 1)
desktop_change_osd->desktopChanged(old_desktop); desktop_change_osd->desktopChanged(old_desktop);
if (effects != NULL && old_desktop != 0 && old_desktop != new_desktop)
static_cast<EffectsHandlerImpl*>(effects)->desktopChanged(old_desktop);
if (compositing()) if (compositing())
addRepaintFull(); addRepaintFull();