add more spacing
[personal-kdebase.git] / workspace / kwin / effects / logout.cpp
blob7d0c3e42283b7b738e85b96b6e50e4a46f46e6f9
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "logout.h"
23 #include "kwinglutils.h"
25 #include <kdebug.h>
27 namespace KWin
30 KWIN_EFFECT( logout, LogoutEffect )
32 LogoutEffect::LogoutEffect()
33 : progress( 0 )
34 , logout_window( NULL )
36 char net_wm_cm_name[ 100 ];
37 sprintf( net_wm_cm_name, "_NET_WM_CM_S%d", DefaultScreen( display()));
38 Atom net_wm_cm = XInternAtom( display(), net_wm_cm_name, False );
39 Window sel = XGetSelectionOwner( display(), net_wm_cm );
40 Atom hack = XInternAtom( display(), "_KWIN_LOGOUT_EFFECT", False );
41 XChangeProperty( display(), sel, hack, hack, 8, PropModeReplace, (unsigned char*)&hack, 1 );
42 // the atom is not removed when effect is destroyed, this is temporary anyway
45 void LogoutEffect::prePaintScreen( ScreenPrePaintData& data, int time )
47 if( logout_window != NULL )
48 progress = qBound( 0., progress + time / animationTime( 2000. ), 1. );
49 else if( progress != 0 )
50 progress = qBound( 0., progress - time / animationTime( 500. ), 1. );
51 effects->prePaintScreen( data, time );
54 void LogoutEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
56 if( w != logout_window && progress != 0 )
58 if( effects->saturationSupported() )
60 data.saturation *= ( 1 - progress * 0.8 );
61 data.brightness *= ( 1 - progress * 0.3 );
63 else // When saturation isn't supported then reduce brightness a bit more
65 data.brightness *= ( 1 - progress * 0.6 );
68 effects->paintWindow( w, mask, region, data );
71 void LogoutEffect::postPaintScreen()
73 if( progress != 0 && progress != 1 )
74 effects->addRepaintFull();
75 effects->postPaintScreen();
78 void LogoutEffect::windowAdded( EffectWindow* w )
80 if( isLogoutDialog( w ))
82 logout_window = w;
83 progress = 0;
84 effects->addRepaintFull();
88 void LogoutEffect::windowClosed( EffectWindow* w )
90 if( w == logout_window )
92 logout_window = NULL;
93 effects->addRepaintFull();
97 bool LogoutEffect::isLogoutDialog( EffectWindow* w )
98 { // TODO there should be probably a better way (window type?)
99 if( w->windowClass() == "ksmserver ksmserver"
100 && ( w->windowRole() == "logoutdialog" || w->windowRole() == "logouteffect" ))
102 return true;
104 return false;
107 } // namespace