Change effects->windowOpacityChanged to also pass the old opacity; thanks Lubos!

Clean up FadeEffect a bit, and make it replace FadeOut in the default effects list.

svn path=/branches/work/kwin_composite/; revision=633032
This commit is contained in:
Philip Falkner 2007-02-12 23:14:50 +00:00
parent f3fb636b33
commit a71753e5cd
7 changed files with 65 additions and 60 deletions

View file

@ -48,7 +48,7 @@ void Effect::windowUserMovedResized( EffectWindow* , bool, bool )
{
}
void Effect::windowOpacityChanged( EffectWindow* )
void Effect::windowOpacityChanged( EffectWindow*, double )
{
}
@ -168,10 +168,12 @@ void EffectsHandler::windowUserMovedResized( EffectWindow* c, bool first, bool l
ep.second->windowUserMovedResized( c, first, last );
}
void EffectsHandler::windowOpacityChanged( EffectWindow* c )
void EffectsHandler::windowOpacityChanged( EffectWindow* c, double old_opacity )
{
if( c->window()->opacity() == old_opacity )
return;
foreach( EffectPair ep, loaded_effects )
ep.second->windowOpacityChanged( c );
ep.second->windowOpacityChanged( c, old_opacity );
}
void EffectsHandler::windowAdded( EffectWindow* c )

View file

@ -73,7 +73,7 @@ class Effect
virtual void postPaintWindow( EffectWindow* w );
// called when moved/resized or once after it's finished
virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
virtual void windowOpacityChanged( EffectWindow* c );
virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
virtual void windowAdded( EffectWindow* c );
virtual void windowClosed( EffectWindow* c );
virtual void windowDeleted( EffectWindow* c );
@ -138,7 +138,7 @@ class EffectsHandler
// internal (used by kwin core or compositing code)
void startPaint();
void windowUserMovedResized( EffectWindow* c, bool first, bool last );
void windowOpacityChanged( EffectWindow* c );
void windowOpacityChanged( EffectWindow* c, double old_opacity );
void windowAdded( EffectWindow* c );
void windowClosed( EffectWindow* c );
void windowDeleted( EffectWindow* c );

View file

@ -58,7 +58,7 @@ void FadeEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* region, in
void FadeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
if( windows.contains( w ))
data.opacity = ( data.opacity + ( windows[ w ].opacity_is_zero ? 1 : 0 )) * windows[ w ].current;
data.opacity = ( data.opacity + ( w->window()->opacity() == 0.0 ? 1 : 0 )) * windows[ w ].current;
effects->paintWindow( w, mask, region, data );
}
@ -69,53 +69,37 @@ void FadeEffect::postPaintWindow( EffectWindow* w )
effects->postPaintWindow( w );
}
void FadeEffect::windowOpacityChanged( EffectWindow* c )
void FadeEffect::windowOpacityChanged( EffectWindow* c, double old_opacity )
{
double new_opacity = c->window()->opacity();
if( !windows.contains( c ))
{ // we don't know the old opacity, so don't fade
windows[ c ].current = 1;
windows[ c ].target = 1;
if( new_opacity == 0.0 )
{ // special case; if opacity is 0, we can't just multiply data.opacity
windows[ c ].current = windows[ c ].current * ( old_opacity == 0.0 ? 1 : old_opacity );
windows[ c ].target = 0;
windows[ c ].step_mult = 1;
}
else
{
if( windows[ c ].old_opacity == 0.0 )
windows[ c ].old_opacity = 1;
if( new_opacity == 0.0 )
{ // special case; if opacity is 0, we can't just multiply data.opacity
windows[ c ].opacity_is_zero = true;
windows[ c ].current = windows[ c ].current * windows[ c ].old_opacity;
windows[ c ].target = 0;
windows[ c ].step_mult = 1;
}
else
{
windows[ c ].opacity_is_zero = false;
windows[ c ].current = ( windows[ c ].current * windows[ c ].old_opacity ) / new_opacity;
windows[ c ].target = 1;
windows[ c ].step_mult = 1 / new_opacity;
}
windows[ c ].current = ( windows[ c ].current * ( old_opacity == 0.0 ? 1 : old_opacity )) / new_opacity;
windows[ c ].target = 1;
windows[ c ].step_mult = 1 / new_opacity;
}
windows[ c ].old_opacity = new_opacity;
c->window()->addRepaintFull();
}
void FadeEffect::windowAdded( EffectWindow* c )
{
if( !windows.contains( c ))
{
windows[ c ].old_opacity = c->window()->opacity();
windows[ c ].current = 0;
}
if( c->window()->opacity() == 0.0 )
{
windows[ c ].opacity_is_zero = true;
windows[ c ].target = 0;
windows[ c ].step_mult = 1;
}
else
{
windows[ c ].opacity_is_zero = false;
windows[ c ].target = 1;
windows[ c ].step_mult = 1 / c->window()->opacity();
}
@ -125,22 +109,13 @@ void FadeEffect::windowAdded( EffectWindow* c )
void FadeEffect::windowClosed( EffectWindow* c )
{
if( !windows.contains( c ))
{
windows[ c ].old_opacity = c->window()->opacity();
windows[ c ].current = 1;
}
if( c->window()->opacity() == 0.0 )
{
windows[ c ].opacity_is_zero = true;
windows[ c ].step_mult = 1;
}
else
{
windows[ c ].opacity_is_zero = false;
windows[ c ].step_mult = 1 / c->window()->opacity();
}
windows[ c ].deleted = true;
windows[ c ].target = 0;
windows[ c ].deleted = true;
c->window()->addRepaintFull();
static_cast< Deleted* >( c->window())->refWindow();
}

View file

@ -27,7 +27,7 @@ class FadeEffect
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
virtual void postPaintWindow( EffectWindow* w );
// TODO react also on virtual desktop changes
virtual void windowOpacityChanged( EffectWindow* c );
virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
virtual void windowAdded( EffectWindow* c );
virtual void windowClosed( EffectWindow* c );
virtual void windowDeleted( EffectWindow* c );
@ -41,20 +41,16 @@ class FadeEffect::WindowInfo
{
public:
WindowInfo()
: deleted( false )
, opacity_is_zero( false )
, old_opacity( 0 )
, current( 0 )
: current( 0 )
, target( 0 )
, step_mult( 0 )
, deleted( false )
{};
bool isFading() const;
bool deleted;
bool opacity_is_zero;
double old_opacity;
double current;
double target;
double step_mult;
bool deleted;
};
inline bool FadeEffect::WindowInfo::isFading() const

View file

@ -561,6 +561,7 @@ bool Client::windowEvent( XEvent* e )
if( e->xany.window == window()) // avoid doing stuff on frame or wrapper
{
unsigned long dirty[ 2 ];
double old_opacity = opacity();
info->event( e, dirty, 2 ); // pass through the NET stuff
if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMName ) != 0 )
@ -598,7 +599,7 @@ bool Client::windowEvent( XEvent* e )
addRepaintFull();
scene->windowOpacityChanged( this );
if( effects )
effects->windowOpacityChanged( effectWindow());
effects->windowOpacityChanged( effectWindow(), old_opacity );
}
else
{ // forward to the frame if there's possibly another compositing manager running
@ -1603,14 +1604,18 @@ void Client::keyPressEvent( uint key_code )
bool Unmanaged::windowEvent( XEvent* e )
{
double old_opacity = opacity();
unsigned long dirty[ 2 ];
info->event( e, dirty, 2 ); // pass through the NET stuff
if( dirty[ NETWinInfo::PROTOCOLS2 ] & NET::WM2Opacity )
{
scene->windowOpacityChanged( this );
if( effects )
effects->windowOpacityChanged( effectWindow());
addRepaintFull();
if( compositing())
{
addRepaintFull();
scene->windowOpacityChanged( this );
if( effects )
effects->windowOpacityChanged( effectWindow(), old_opacity );
}
}
switch (e->type)
{

View file

@ -174,9 +174,8 @@ unsigned long Options::updateSettings()
CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel","Nothing"));
//translucency settings - TODO
config->setGroup( "Notification Messages" );
useTranslucency = config->readEntry("UseTranslucency", false);
config->setGroup( "Translucency");
useTranslucency = config->readEntry("UseTranslucency", true);
translucentActiveWindows = config->readEntry("TranslucentActiveWindows", false);
activeWindowOpacity = uint((config->readEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF);
translucentInactiveWindows = config->readEntry("TranslucentInactiveWindows", false);
@ -195,6 +194,27 @@ unsigned long Options::updateSettings()
removeShadowsOnResize = config->readEntry("RemoveShadowsOnResize", true);
onlyDecoTranslucent = config->readEntry("OnlyDecoTranslucent", false);
refreshRate = config->readEntry( "RefreshRate", 0 );
smoothScale = qBound( -1, config->readEntry( "SmoothScale", -1 ), 2 );
QString glmode = config->readEntry("GLMode", "TFP" ).upper();
if( glmode == "TFP" )
glMode = GLTFP;
else if( glmode == "SHM" )
glMode = GLSHM;
else
glMode = GLFallback;
glAlwaysRebind = config->readEntry("GLAlwaysRebind", false );
glDirect = config->readEntry("GLDirect", true );
glVSync = config->readEntry("GLVSync", true );
config->setGroup( "Effects" );
defaultEffects = config->readEntry( "Load", QStringList() << "ShowFps" << "Fade" );
config->setGroup( "EffectShowFps" );
effectShowFpsAlpha = config->readEntry( "Alpha", 0.5 );
effectShowFpsX = config->readEntry( "X", -10000 );
effectShowFpsY = config->readEntry( "Y", 0 );
// Read button tooltip animation effect from kdeglobals
// Since we want to allow users to enable window decoration tooltips
// and not kstyle tooltips and vise-versa, we don't read the

View file

@ -292,11 +292,18 @@ double Toplevel::opacity() const
return info->opacity() * 1.0 / 0xffffffff;
}
void Toplevel::setOpacity( double opacity )
void Toplevel::setOpacity( double new_opacity )
{
opacity = qBound( 0.0, opacity, 1.0 );
info->setOpacity( static_cast< unsigned long >( opacity * 0xffffffff ));
// we'll react on PropertyNotify
double old_opacity = opacity();
new_opacity = qBound( 0.0, new_opacity, 1.0 );
info->setOpacity( static_cast< unsigned long >( new_opacity * 0xffffffff ));
if( compositing())
{
addRepaintFull();
scene->windowOpacityChanged( this );
if( effects )
effects->windowOpacityChanged( effectWindow(), old_opacity );
}
}
} // namespace