Dim the screen if kdesu or kdesudo ask for the password for adminstrator mode
svn path=/trunk/KDE/kdebase/workspace/; revision=782196
This commit is contained in:
parent
58972fbe5c
commit
5e44946ee7
4 changed files with 249 additions and 0 deletions
|
@ -38,6 +38,7 @@ SET(kwin4_effect_builtins_sources
|
|||
desktopgrid.cpp
|
||||
dialogparent.cpp
|
||||
diminactive.cpp
|
||||
dimscreen.cpp
|
||||
fade.cpp
|
||||
fallapart.cpp
|
||||
login.cpp
|
||||
|
@ -56,6 +57,7 @@ install( FILES
|
|||
desktopgrid.desktop
|
||||
dialogparent.desktop
|
||||
diminactive.desktop
|
||||
dimscreen.desktop
|
||||
fade.desktop
|
||||
fallapart.desktop
|
||||
login.desktop
|
||||
|
|
168
effects/dimscreen.cpp
Normal file
168
effects/dimscreen.cpp
Normal file
|
@ -0,0 +1,168 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com
|
||||
|
||||
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/>.
|
||||
*********************************************************************/
|
||||
#include "dimscreen.h"
|
||||
|
||||
#include <kwinglutils.h>
|
||||
|
||||
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
KWIN_EFFECT( dimscreen, DimScreenEffect )
|
||||
|
||||
DimScreenEffect::DimScreenEffect()
|
||||
: mActivated( false )
|
||||
, animationDuration( 300 )
|
||||
, animation( false )
|
||||
, deactivate( false )
|
||||
{
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
alphaFormat = XRenderFindStandardFormat( display(), PictStandardARGB32 );
|
||||
#endif
|
||||
}
|
||||
|
||||
DimScreenEffect::~DimScreenEffect()
|
||||
{
|
||||
}
|
||||
|
||||
void DimScreenEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
||||
{
|
||||
effects->prePaintScreen( data, time );
|
||||
}
|
||||
|
||||
void DimScreenEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
||||
{
|
||||
effects->paintScreen( mask, region, data );
|
||||
if( mActivated || deactivate )
|
||||
{
|
||||
float opacity = 0.4;
|
||||
int height = Effect::displayHeight();
|
||||
if( animation )
|
||||
{
|
||||
int elapsed = animationTime.elapsed();
|
||||
float timeFactor = (float)((float)elapsed/(float)animationDuration);
|
||||
if( timeFactor > 1.0 )
|
||||
timeFactor = 1.0;
|
||||
if( deactivate )
|
||||
{
|
||||
opacity = opacity - opacity * timeFactor;
|
||||
}
|
||||
else
|
||||
{
|
||||
opacity = opacity * timeFactor;
|
||||
}
|
||||
}
|
||||
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
||||
if( effects->compositingType() == OpenGLCompositing )
|
||||
{
|
||||
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA );
|
||||
glPolygonMode( GL_FRONT, GL_FILL );
|
||||
glColor4f( 0.0, 0.0, 0.0, opacity );
|
||||
float vertices[] = { 0.0, 0.0, 0.0, height, Effect::displayWidth(), height, Effect::displayWidth(), 0.0 };
|
||||
renderGLGeometry( 4, vertices );
|
||||
glDisable( GL_BLEND );
|
||||
glPopAttrib();
|
||||
}
|
||||
#endif
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
if( effects->compositingType() == XRenderCompositing )
|
||||
{
|
||||
Pixmap pixmap = XCreatePixmap( display(), rootWindow(),
|
||||
Effect::displayWidth(), Effect::displayHeight(), 32 );
|
||||
Picture pic = XRenderCreatePicture( display(), pixmap, alphaFormat, 0, NULL );
|
||||
XFreePixmap( display(), pixmap );
|
||||
XRenderColor col;
|
||||
col.alpha = int( opacity * 0xffff );
|
||||
col.red = int( 0.0 * opacity * 0xffff );
|
||||
col.green = int( 0.0 * opacity * 0xffff );
|
||||
col.blue = int( 0.0 * opacity * 0xffff );
|
||||
XRenderFillRectangle( display(), PictOpSrc, pic, &col, 0, 0,
|
||||
Effect::displayWidth(), height );
|
||||
XRenderComposite( display(), PictOpOver,
|
||||
pic, None, effects->xrenderBufferPicture(),
|
||||
0, 0, 0, 0, 0, 0, Effect::displayWidth(), height );
|
||||
XRenderFreePicture( display(), pic );
|
||||
}
|
||||
#endif
|
||||
// re-paint active window
|
||||
EffectWindow* activeWindow = effects->activeWindow();
|
||||
if( activeWindow )
|
||||
{
|
||||
WindowPaintData data( activeWindow );
|
||||
effects->drawWindow( activeWindow, 0, activeWindow->geometry(), data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DimScreenEffect::postPaintScreen()
|
||||
{
|
||||
if( animation )
|
||||
{
|
||||
if( animationTime.elapsed() >= animationDuration )
|
||||
{
|
||||
animation = false;
|
||||
deactivate = false;
|
||||
}
|
||||
effects->addRepaintFull();
|
||||
}
|
||||
effects->postPaintScreen();
|
||||
}
|
||||
|
||||
void DimScreenEffect::paintWindow( EffectWindow *w, int mask, QRegion region, WindowPaintData &data )
|
||||
{
|
||||
if( mActivated && ( w == effects->activeWindow() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
effects->paintWindow( w, mask, region, data );
|
||||
}
|
||||
|
||||
void DimScreenEffect::windowActivated( EffectWindow *w )
|
||||
{
|
||||
if( !w ) return;
|
||||
QStringList check;
|
||||
check << "kdesu kdesu";
|
||||
check << "kdesudo kdesudo";
|
||||
bool before = mActivated;
|
||||
if( check.contains( w->windowClass() ) )
|
||||
{
|
||||
mActivated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mActivated = false;
|
||||
}
|
||||
if( before != mActivated )
|
||||
{
|
||||
if( !mActivated )
|
||||
{
|
||||
deactivate = true;
|
||||
}
|
||||
animation = true;
|
||||
animationTime.restart();
|
||||
effects->addRepaintFull();
|
||||
}
|
||||
}
|
||||
} // namespace
|
17
effects/dimscreen.desktop
Normal file
17
effects/dimscreen.desktop
Normal file
|
@ -0,0 +1,17 @@
|
|||
[Desktop Entry]
|
||||
Name=Dim Screen for Administrator Mode
|
||||
Icon=preferences-system-windows-effect-dimscreen
|
||||
Comment=Dims the screen if a window asks for root password
|
||||
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=KWin/Effect
|
||||
X-KDE-PluginInfo-Author=Martin Gräßlin
|
||||
X-KDE-PluginInfo-Email=ubuntu@martin-graesslin.com
|
||||
X-KDE-PluginInfo-Name=kwin4_effect_dimscreen
|
||||
X-KDE-PluginInfo-Version=0.1.0
|
||||
X-KDE-PluginInfo-Category=Appearance
|
||||
X-KDE-PluginInfo-Depends=
|
||||
X-KDE-PluginInfo-License=GPL
|
||||
X-KDE-PluginInfo-EnabledByDefault=false
|
||||
X-KDE-Library=kwin4_effect_builtins
|
||||
X-Ordering=50
|
62
effects/dimscreen.h
Normal file
62
effects/dimscreen.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com
|
||||
|
||||
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/>.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef KWIN_DIMSCREEN_H
|
||||
#define KWIN_DIMSCREEN_H
|
||||
|
||||
#include <kwineffects.h>
|
||||
|
||||
#include <QTime>
|
||||
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
#include <X11/extensions/Xrender.h>
|
||||
#endif
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class DimScreenEffect
|
||||
: public Effect
|
||||
{
|
||||
public:
|
||||
DimScreenEffect();
|
||||
~DimScreenEffect();
|
||||
|
||||
virtual void prePaintScreen( ScreenPrePaintData& data, int time );
|
||||
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
|
||||
virtual void postPaintScreen();
|
||||
virtual void paintWindow( EffectWindow *w, int mask, QRegion region, WindowPaintData &data );
|
||||
virtual void windowActivated( EffectWindow *w );
|
||||
|
||||
private:
|
||||
bool mActivated;
|
||||
QTime animationTime;
|
||||
int animationDuration;
|
||||
bool animation;
|
||||
bool deactivate;
|
||||
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
XRenderPictFormat* alphaFormat;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue