Added support for inter-effect communication through the use of proxy

classes. Example code has been added to present windows and desktop
grid, if this code is not to be used by KDE 4.3 it should be removed and
added to a test effect instead.

svn path=/trunk/KDE/kdebase/workspace/; revision=922039
This commit is contained in:
Lucas Murray 2009-02-06 10:15:06 +00:00
parent 502fdbb751
commit a1c82cd52b
10 changed files with 140 additions and 1 deletions

View file

@ -355,6 +355,18 @@ void EffectsHandlerImpl::grabbedKeyboardEvent( QKeyEvent* e )
keyboard_grab_effect->grabbedKeyboardEvent( e );
}
const void* EffectsHandlerImpl::getProxy( QString name )
{
// All effects start with "kwin4_effect_", prepend it to the name
name.prepend( "kwin4_effect_" );
for( QVector< EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it)
if ( (*it).first == name )
return (*it).second->proxy();
return NULL;
}
void EffectsHandlerImpl::startMousePolling()
{
if( !mouse_poll_ref_count ) // Start timer if required

View file

@ -65,6 +65,7 @@ class EffectsHandlerImpl : public EffectsHandler
virtual QPoint cursorPos() const;
virtual bool grabKeyboard( Effect* effect );
virtual void ungrabKeyboard();
virtual const void* getProxy( QString name );
virtual void startMousePolling();
virtual void stopMousePolling();
virtual EffectWindow* findWindow( WId id ) const;

View file

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "desktopgrid.h"
#include "../presentwindows/presentwindows_proxy.h"
#include <math.h>
#include <kaction.h>
@ -712,6 +714,15 @@ void DesktopGridEffect::setActive( bool active )
if( activated == active )
return; // Already in that state
// Example proxy code, TODO: Use or remove
//const PresentWindowsEffectProxy* proxy =
// static_cast<const PresentWindowsEffectProxy*>( effects->getProxy( "presentwindows" ));
//if( proxy )
// kDebug() << "Retrieved PresentWindowsEffectProxy, is present windows activate?"
// << proxy->isActive();
//else
// kDebug() << "Failed to retrieve PresentWindowsEffectProxy. Maybe present windows isn't enabled?";
activated = active;
if( activated && timeline.value() == 0 )
setup();

View file

@ -4,6 +4,7 @@
# Source files
set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
presentwindows/presentwindows.cpp
presentwindows/presentwindows_proxy.cpp
)
# .desktop files

View file

@ -41,7 +41,8 @@ namespace KWin
KWIN_EFFECT( presentwindows, PresentWindowsEffect )
PresentWindowsEffect::PresentWindowsEffect()
: m_borderActivate( ElectricNone )
: m_proxy( this )
, m_borderActivate( ElectricNone )
, m_borderActivateAll( ElectricNone )
, m_activated( false )
, m_allDesktops( false )
@ -100,6 +101,11 @@ void PresentWindowsEffect::reconfigure( ReconfigureFlags )
m_showPanel = conf.readEntry( "ShowPanel", false );
}
const void* PresentWindowsEffect::proxy() const
{
return &m_proxy;
}
//-----------------------------------------------------------------------------
// Screen painting

View file

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_PRESENTWINDOWS_H
#define KWIN_PRESENTWINDOWS_H
#include "presentwindows_proxy.h"
// Include with base class for effects.
#include <kwineffects.h>
#include <kwinglutils.h>
@ -69,6 +71,8 @@ class PresentWindowsEffect
virtual ~PresentWindowsEffect();
virtual void reconfigure( ReconfigureFlags );
virtual const void* proxy() const;
// Screen painting
virtual void prePaintScreen( ScreenPrePaintData &data, int time );
virtual void paintScreen( int mask, QRegion region, ScreenPaintData &data );
@ -129,6 +133,9 @@ class PresentWindowsEffect
void paintWindowIcon( EffectWindow *w, WindowPaintData &data ); // TODO: Do we need this?
private:
PresentWindowsEffectProxy m_proxy;
friend class PresentWindowsEffectProxy;
// User configuration settings
ElectricBorder m_borderActivate;
ElectricBorder m_borderActivateAll;

View file

@ -0,0 +1,41 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "presentwindows_proxy.h"
#include "presentwindows.h"
namespace KWin
{
PresentWindowsEffectProxy::PresentWindowsEffectProxy( PresentWindowsEffect* effect )
: m_effect( effect )
{
}
PresentWindowsEffectProxy::~PresentWindowsEffectProxy()
{
}
bool PresentWindowsEffectProxy::isActive() const
{
return m_effect->m_activated;
}
} // namespace

View file

@ -0,0 +1,44 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_PRESENTWINDOWS_PROXY_H
#define KWIN_PRESENTWINDOWS_PROXY_H
namespace KWin
{
class PresentWindowsEffect;
// Example proxy code, TODO: Use or remove
class PresentWindowsEffectProxy
{
public:
PresentWindowsEffectProxy( PresentWindowsEffect* effect );
~PresentWindowsEffectProxy();
bool isActive() const;
private:
PresentWindowsEffect* m_effect;
};
} // namespace
#endif

View file

@ -112,6 +112,11 @@ void Effect::reconfigure( ReconfigureFlags )
{
}
const void* Effect::proxy() const
{
return NULL;
}
void Effect::windowUserMovedResized( EffectWindow* , bool, bool )
{
}

View file

@ -296,6 +296,11 @@ class KWIN_EXPORT Effect
*/
virtual void reconfigure( ReconfigureFlags flags );
/**
* Called when another effect requests the proxy for this effect.
*/
virtual const void* proxy() const;
/**
* Called before starting to paint the screen.
* In this method you can:
@ -522,6 +527,12 @@ class KWIN_EXPORT EffectsHandler
virtual bool grabKeyboard( Effect* effect ) = 0;
virtual void ungrabKeyboard() = 0;
/**
* Retrieve the proxy class for an effect if it has one. Will return NULL if
* the effect isn't loaded or doesn't have a proxy class.
*/
virtual const void* getProxy( QString name ) = 0;
// Mouse polling
virtual void startMousePolling() = 0;
virtual void stopMousePolling() = 0;