2007-11-27 22:40:25 +03:00
|
|
|
/********************************************************************
|
2007-11-14 03:09:14 +03:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
2009-02-08 19:04:02 +03:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
2009-02-08 17:07:00 +03:00
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
|
2007-11-14 03:09:14 +03:00
|
|
|
|
2007-11-27 22:40:25 +03:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-11-14 03:09:14 +03:00
|
|
|
|
|
|
|
#include "logout.h"
|
|
|
|
|
2007-11-14 16:48:16 +03:00
|
|
|
#include "kwinglutils.h"
|
|
|
|
|
2009-03-06 09:10:00 +03:00
|
|
|
#include <kconfiggroup.h>
|
2007-11-14 03:09:14 +03:00
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_EFFECT( logout, LogoutEffect )
|
|
|
|
|
|
|
|
LogoutEffect::LogoutEffect()
|
2009-02-08 19:04:02 +03:00
|
|
|
: progress( 0.0 )
|
|
|
|
, logoutWindow( NULL )
|
|
|
|
, logoutWindowClosed( true )
|
2009-05-11 16:14:41 +04:00
|
|
|
, logoutWindowPassed( false )
|
2007-11-14 03:09:14 +03:00
|
|
|
{
|
2008-01-26 22:36:04 +03:00
|
|
|
char net_wm_cm_name[ 100 ];
|
|
|
|
sprintf( net_wm_cm_name, "_NET_WM_CM_S%d", DefaultScreen( display()));
|
|
|
|
Atom net_wm_cm = XInternAtom( display(), net_wm_cm_name, False );
|
|
|
|
Window sel = XGetSelectionOwner( display(), net_wm_cm );
|
|
|
|
Atom hack = XInternAtom( display(), "_KWIN_LOGOUT_EFFECT", False );
|
|
|
|
XChangeProperty( display(), sel, hack, hack, 8, PropModeReplace, (unsigned char*)&hack, 1 );
|
|
|
|
// the atom is not removed when effect is destroyed, this is temporary anyway
|
2009-07-27 16:54:02 +04:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
blurTexture = NULL;
|
|
|
|
blurTarget = NULL;
|
|
|
|
#endif
|
2009-03-06 09:10:00 +03:00
|
|
|
reconfigure( ReconfigureAll );
|
|
|
|
}
|
|
|
|
|
|
|
|
LogoutEffect::~LogoutEffect()
|
|
|
|
{
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
delete blurTexture;
|
|
|
|
delete blurTarget;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogoutEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
2009-08-09 20:04:39 +04:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2009-03-06 09:10:00 +03:00
|
|
|
KConfigGroup conf = effects->effectConfig( "Logout" );
|
2009-07-27 16:54:02 +04:00
|
|
|
useBlur = conf.readEntry( "UseBlur", true );
|
|
|
|
delete blurTexture;
|
2009-02-15 13:34:41 +03:00
|
|
|
blurTexture = NULL;
|
2009-07-27 16:54:02 +04:00
|
|
|
delete blurTarget;
|
2009-02-15 13:34:41 +03:00
|
|
|
blurTarget = NULL;
|
2009-07-27 16:54:02 +04:00
|
|
|
blurSupported = false;
|
2009-02-08 17:07:00 +03:00
|
|
|
#endif
|
2007-11-14 03:09:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogoutEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
|
|
|
{
|
2009-07-27 16:54:02 +04:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
if ( !logoutWindow )
|
|
|
|
{
|
|
|
|
if (blurTexture)
|
|
|
|
{
|
|
|
|
delete blurTexture;
|
|
|
|
blurTexture = NULL;
|
|
|
|
delete blurTarget;
|
|
|
|
blurTarget = NULL;
|
|
|
|
blurSupported = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( !blurTexture )
|
|
|
|
{
|
|
|
|
blurSupported = false;
|
|
|
|
delete blurTarget; // catch as we just tested the texture ;-P
|
|
|
|
if( effects->compositingType() == OpenGLCompositing && GLTexture::NPOTTextureSupported() && useBlur )
|
|
|
|
{ // TODO: It seems that it is not possible to create a GLRenderTarget that has
|
|
|
|
// a different size than the display right now. Most likely a KWin core bug.
|
|
|
|
// Create texture and render target
|
|
|
|
blurTexture = new GLTexture( displayWidth(), displayHeight() );
|
|
|
|
blurTexture->setFilter( GL_LINEAR_MIPMAP_LINEAR );
|
|
|
|
blurTexture->setWrapMode( GL_CLAMP_TO_EDGE );
|
|
|
|
|
|
|
|
blurTarget = new GLRenderTarget( blurTexture );
|
|
|
|
if( blurTarget->valid() )
|
|
|
|
blurSupported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-08 19:04:02 +03:00
|
|
|
if( logoutWindow != NULL && !logoutWindowClosed )
|
|
|
|
progress = qMin( 1.0, progress + time / animationTime( 2000.0 ));
|
|
|
|
else if( progress > 0.0 )
|
|
|
|
progress = qMax( 0.0, progress - time / animationTime( 500.0 ));
|
2009-02-08 17:07:00 +03:00
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
if( blurSupported && progress > 0.0 )
|
|
|
|
{
|
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-14 03:09:14 +03:00
|
|
|
effects->prePaintScreen( data, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogoutEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
if( progress > 0.0 )
|
2007-11-14 03:09:14 +03:00
|
|
|
{
|
2009-02-15 19:04:29 +03:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
if( blurSupported && w == logoutWindow )
|
2007-11-14 16:48:16 +03:00
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
windowOpacity = data.opacity;
|
|
|
|
data.opacity = 0.0; // Cheat, we need the opacity for later but don't want to blur it
|
2007-11-14 16:48:16 +03:00
|
|
|
}
|
2009-02-08 19:04:02 +03:00
|
|
|
else
|
|
|
|
{
|
2009-02-15 19:04:29 +03:00
|
|
|
#endif
|
2009-05-11 16:14:41 +04:00
|
|
|
if( w != logoutWindow && !logoutWindowPassed )
|
2009-02-08 19:04:02 +03:00
|
|
|
{
|
2009-02-15 19:12:43 +03:00
|
|
|
if( effects->saturationSupported() )
|
|
|
|
{
|
|
|
|
data.saturation *= ( 1.0 - progress * 0.8 );
|
|
|
|
data.brightness *= ( 1.0 - progress * 0.3 );
|
|
|
|
}
|
|
|
|
else // When saturation isn't supported then reduce brightness a bit more
|
|
|
|
data.brightness *= ( 1.0 - progress * 0.6 );
|
2009-02-08 19:04:02 +03:00
|
|
|
}
|
2009-02-15 19:04:29 +03:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2009-05-11 16:14:41 +04:00
|
|
|
if( blurSupported && logoutWindowPassed )
|
|
|
|
{
|
|
|
|
windows.append( w );
|
|
|
|
windowsOpacities[ w ] = data.opacity;
|
|
|
|
data.opacity = 0.0;
|
|
|
|
}
|
2007-11-14 16:48:16 +03:00
|
|
|
}
|
2009-02-15 19:04:29 +03:00
|
|
|
#endif
|
2009-05-11 16:14:41 +04:00
|
|
|
if( w == logoutWindow )
|
|
|
|
{
|
|
|
|
// logout window - all following windows are on top and should not be altered
|
|
|
|
logoutWindowPassed = true;
|
|
|
|
}
|
2007-11-14 03:09:14 +03:00
|
|
|
}
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
2009-02-08 19:04:02 +03:00
|
|
|
void LogoutEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
2007-11-14 03:09:14 +03:00
|
|
|
{
|
2009-05-28 15:37:02 +04:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
if( blurSupported && progress > 0.0 )
|
|
|
|
{
|
|
|
|
effects->pushRenderTarget( blurTarget );
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-08 19:04:02 +03:00
|
|
|
effects->paintScreen( mask, region, data );
|
2009-02-08 17:07:00 +03:00
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
if( blurSupported && progress > 0.0 )
|
|
|
|
{
|
2009-04-28 19:00:56 +04:00
|
|
|
GLRenderTarget* target = effects->popRenderTarget();
|
|
|
|
assert( target == blurTarget );
|
2009-02-08 17:07:00 +03:00
|
|
|
|
|
|
|
// Render the blurred scene
|
|
|
|
blurTexture->bind();
|
|
|
|
GLfloat bias[1];
|
|
|
|
glGetTexEnvfv( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, bias );
|
|
|
|
glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, progress * 2.75 );
|
2009-02-08 19:04:02 +03:00
|
|
|
glBegin( GL_QUADS );
|
2009-02-08 17:07:00 +03:00
|
|
|
glTexCoord2f( 0.0, 0.0 );
|
|
|
|
glVertex2f( 0.0, displayHeight() );
|
|
|
|
glTexCoord2f( 1.0, 0.0 );
|
|
|
|
glVertex2f( displayWidth(), displayHeight() );
|
|
|
|
glTexCoord2f( 1.0, 1.0 );
|
|
|
|
glVertex2f( displayWidth(), 0.0 );
|
|
|
|
glTexCoord2f( 0.0, 1.0 );
|
|
|
|
glVertex2f( 0.0, 0.0 );
|
|
|
|
glEnd();
|
|
|
|
glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, bias[0] );
|
|
|
|
blurTexture->unbind();
|
|
|
|
|
|
|
|
// Render the logout window
|
2009-02-08 19:04:02 +03:00
|
|
|
if( logoutWindow )
|
2009-02-08 17:07:00 +03:00
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
int winMask = logoutWindow->hasAlpha() ? PAINT_WINDOW_TRANSLUCENT : PAINT_WINDOW_OPAQUE;
|
|
|
|
WindowPaintData winData( logoutWindow );
|
|
|
|
winData.opacity = windowOpacity;
|
|
|
|
effects->drawWindow( logoutWindow, winMask, region, winData );
|
2009-02-08 17:07:00 +03:00
|
|
|
}
|
2009-05-11 16:14:41 +04:00
|
|
|
|
|
|
|
// Render all windows on top of logout window
|
|
|
|
foreach( EffectWindow* w, windows )
|
|
|
|
{
|
|
|
|
int winMask = w->hasAlpha() ? PAINT_WINDOW_TRANSLUCENT : PAINT_WINDOW_OPAQUE;
|
|
|
|
WindowPaintData winData( w );
|
|
|
|
winData.opacity = windowsOpacities[ w ];
|
|
|
|
effects->drawWindow( w, winMask, region, winData );
|
|
|
|
}
|
|
|
|
|
|
|
|
windows.clear();
|
|
|
|
windowsOpacities.clear();
|
2009-02-08 17:07:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
2007-11-14 03:09:14 +03:00
|
|
|
}
|
|
|
|
|
2009-02-08 19:04:02 +03:00
|
|
|
void LogoutEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( progress != 0.0 && progress != 1.0 )
|
2009-05-11 16:14:41 +04:00
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
effects->addRepaintFull();
|
2009-05-26 02:00:30 +04:00
|
|
|
}
|
|
|
|
if( progress > 0.0 )
|
|
|
|
{
|
2009-05-11 16:14:41 +04:00
|
|
|
logoutWindowPassed = false;
|
|
|
|
}
|
2009-02-08 19:04:02 +03:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2007-11-14 03:09:14 +03:00
|
|
|
void LogoutEffect::windowAdded( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( isLogoutDialog( w ))
|
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
logoutWindow = w;
|
|
|
|
logoutWindowClosed = false; // So we don't blur the window on close
|
|
|
|
progress = 0.0;
|
2007-11-14 03:09:14 +03:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogoutEffect::windowClosed( EffectWindow* w )
|
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
if( w == logoutWindow )
|
2007-11-14 03:09:14 +03:00
|
|
|
{
|
2009-02-08 19:04:02 +03:00
|
|
|
logoutWindowClosed = true;
|
2007-11-14 03:09:14 +03:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-08 19:04:02 +03:00
|
|
|
void LogoutEffect::windowDeleted( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( w == logoutWindow )
|
|
|
|
logoutWindow = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-14 03:09:14 +03:00
|
|
|
bool LogoutEffect::isLogoutDialog( EffectWindow* w )
|
|
|
|
{ // TODO there should be probably a better way (window type?)
|
2007-11-14 18:58:57 +03:00
|
|
|
if( w->windowClass() == "ksmserver ksmserver"
|
|
|
|
&& ( w->windowRole() == "logoutdialog" || w->windowRole() == "logouteffect" ))
|
|
|
|
{
|
2007-11-14 03:09:14 +03:00
|
|
|
return true;
|
2007-11-14 18:58:57 +03:00
|
|
|
}
|
2007-11-14 03:09:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|