2007-01-25 11:48:07 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "minimizeanimation.h"
|
|
|
|
|
|
|
|
#include <workspace.h>
|
|
|
|
#include <client.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Note that currently effects need to be manually enabled in the EffectsHandler
|
|
|
|
// class constructor (in effects.cpp).
|
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2007-01-25 11:48:07 +00:00
|
|
|
{
|
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
MinimizeAnimationEffect::MinimizeAnimationEffect()
|
2007-01-25 11:48:07 +00:00
|
|
|
{
|
|
|
|
mActiveAnimations = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
if( mActiveAnimations > 0 )
|
2007-02-11 17:35:10 +00:00
|
|
|
// We need to mark the screen windows as transformed. Otherwise the
|
|
|
|
// whole screen won't be repainted, resulting in artefacts
|
|
|
|
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2007-01-25 11:48:07 +00:00
|
|
|
|
|
|
|
effects->prePaintScreen(mask, region, time);
|
|
|
|
}
|
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
2007-01-25 11:48:07 +00:00
|
|
|
{
|
|
|
|
const float changeTime = 500;
|
|
|
|
if( mAnimationProgress.contains( w ))
|
|
|
|
{
|
|
|
|
Client* c = static_cast< Client* >( w->window() );
|
|
|
|
if( c->isMinimized() )
|
|
|
|
{
|
|
|
|
mAnimationProgress[w] += time / changeTime;
|
|
|
|
if( mAnimationProgress[w] >= 1.0f )
|
|
|
|
mAnimationProgress.remove( w );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mAnimationProgress[w] -= time / changeTime;
|
|
|
|
if( mAnimationProgress[w] <= 0.0f )
|
|
|
|
mAnimationProgress.remove( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schedule window for transformation if the animation is still in
|
|
|
|
// progress
|
|
|
|
if( mAnimationProgress.contains( w ))
|
|
|
|
{
|
|
|
|
// We'll transform this window
|
|
|
|
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
|
2007-02-11 17:36:32 +00:00
|
|
|
w->enablePainting( Scene::Window::PAINT_DISABLED_BY_MINIMIZE );
|
2007-01-25 11:48:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// Animation just finished
|
|
|
|
mActiveAnimations--;
|
|
|
|
}
|
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
2007-01-25 11:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
if( mAnimationProgress.contains( w ))
|
|
|
|
{
|
|
|
|
// 0 = not minimized, 1 = fully minimized
|
|
|
|
float progress = mAnimationProgress[w];
|
|
|
|
|
|
|
|
Client* c = static_cast< Client* >( w->window() );
|
|
|
|
QRect geo = c->geometry();
|
|
|
|
QRect icon = c->iconGeometry();
|
2007-01-29 19:28:53 +00:00
|
|
|
// If there's no icon geometry, minimize to the center of the screen
|
2007-01-25 21:23:27 +00:00
|
|
|
if( !icon.isValid() )
|
|
|
|
icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
|
2007-01-25 11:48:07 +00:00
|
|
|
|
|
|
|
data.xScale *= interpolate(1.0, icon.width() / (float)geo.width(), progress);
|
|
|
|
data.yScale *= interpolate(1.0, icon.height() / (float)geo.height(), progress);
|
|
|
|
data.xTranslate = (int)interpolate(data.xTranslate, icon.x() - geo.x(), progress);
|
|
|
|
data.yTranslate = (int)interpolate(data.yTranslate, icon.y() - geo.y(), progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( mActiveAnimations > 0 )
|
2007-02-12 15:22:43 +00:00
|
|
|
// Repaint the workspace so that everything would be repainted next time
|
|
|
|
workspace()->addRepaintFull();
|
2007-01-25 11:48:07 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowMinimized( EffectWindow* w )
|
|
|
|
{
|
2007-01-25 21:23:27 +00:00
|
|
|
if( !mAnimationProgress.contains(w) )
|
2007-01-25 11:48:07 +00:00
|
|
|
{
|
|
|
|
mAnimationProgress[w] = 0.0f;
|
|
|
|
mActiveAnimations++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowUnminimized( EffectWindow* w )
|
|
|
|
{
|
2007-01-25 21:23:27 +00:00
|
|
|
if( !mAnimationProgress.contains(w) )
|
2007-01-25 11:48:07 +00:00
|
|
|
{
|
|
|
|
mAnimationProgress[w] = 1.0f;
|
|
|
|
mActiveAnimations++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|