1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com
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 *********************************************************************/
20 #include "dimscreen.h"
22 #include <kwinglutils.h>
24 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
31 KWIN_EFFECT( dimscreen
, DimScreenEffect
)
33 DimScreenEffect::DimScreenEffect()
38 reconfigure( ReconfigureAll
);
39 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
40 alphaFormat
= XRenderFindStandardFormat( display(), PictStandardARGB32
);
44 DimScreenEffect::~DimScreenEffect()
48 void DimScreenEffect::reconfigure( ReconfigureFlags
)
50 animationDuration
= Effect::animationTime( 300 );
53 void DimScreenEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
55 effects
->prePaintScreen( data
, time
);
58 void DimScreenEffect::paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
)
60 effects
->paintScreen( mask
, region
, data
);
61 if( mActivated
|| deactivate
)
64 int height
= Effect::displayHeight();
67 int elapsed
= animationTime
.elapsed();
68 float timeFactor
= (float)((float)elapsed
/(float)animationDuration
);
69 if( timeFactor
> 1.0 )
73 opacity
= opacity
- opacity
* timeFactor
;
77 opacity
= opacity
* timeFactor
;
80 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
81 if( effects
->compositingType() == OpenGLCompositing
)
83 glPushAttrib( GL_CURRENT_BIT
| GL_ENABLE_BIT
);
85 glBlendFunc( GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);
86 glPolygonMode( GL_FRONT
, GL_FILL
);
87 glColor4f( 0.0, 0.0, 0.0, opacity
);
88 float vertices
[] = { 0.0, 0.0, 0.0, height
, Effect::displayWidth(), height
, Effect::displayWidth(), 0.0 };
89 renderGLGeometry( 4, vertices
);
90 glDisable( GL_BLEND
);
94 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
95 if( effects
->compositingType() == XRenderCompositing
)
97 Pixmap pixmap
= XCreatePixmap( display(), rootWindow(),
98 Effect::displayWidth(), Effect::displayHeight(), 32 );
99 Picture pic
= XRenderCreatePicture( display(), pixmap
, alphaFormat
, 0, NULL
);
100 XFreePixmap( display(), pixmap
);
102 col
.alpha
= int( opacity
* 0xffff );
103 col
.red
= int( 0.0 * opacity
* 0xffff );
104 col
.green
= int( 0.0 * opacity
* 0xffff );
105 col
.blue
= int( 0.0 * opacity
* 0xffff );
106 XRenderFillRectangle( display(), PictOpSrc
, pic
, &col
, 0, 0,
107 Effect::displayWidth(), height
);
108 XRenderComposite( display(), PictOpOver
,
109 pic
, None
, effects
->xrenderBufferPicture(),
110 0, 0, 0, 0, 0, 0, Effect::displayWidth(), height
);
111 XRenderFreePicture( display(), pic
);
114 // re-paint active window
115 EffectWindow
* activeWindow
= effects
->activeWindow();
118 WindowPaintData
data( activeWindow
);
119 effects
->drawWindow( activeWindow
, 0, activeWindow
->geometry(), data
);
124 void DimScreenEffect::postPaintScreen()
128 if( animationTime
.elapsed() >= animationDuration
)
133 effects
->addRepaintFull();
135 effects
->postPaintScreen();
138 void DimScreenEffect::paintWindow( EffectWindow
*w
, int mask
, QRegion region
, WindowPaintData
&data
)
140 if( mActivated
&& ( w
== effects
->activeWindow() ) )
144 effects
->paintWindow( w
, mask
, region
, data
);
147 void DimScreenEffect::windowActivated( EffectWindow
*w
)
151 check
<< "kdesu kdesu";
152 check
<< "kdesudo kdesudo";
153 check
<< "polkit-kde-manager polkit-kde-manager";
154 bool before
= mActivated
;
155 if( check
.contains( w
->windowClass() ) )
163 if( before
!= mActivated
)
170 animationTime
.restart();
171 effects
->addRepaintFull();