Add window icons to PresentWindows.

Code stolen from BoxSwitch ;-)

svn path=/trunk/KDE/kdebase/workspace/; revision=683858
This commit is contained in:
Rivo Laks 2007-07-05 11:41:02 +00:00
parent 2c4161bbaa
commit 913d8395d8
2 changed files with 99 additions and 1 deletions

View file

@ -55,6 +55,10 @@ PresentWindowsEffect::PresentWindowsEffect()
effects->reserveElectricBorder( borderActivate );
effects->reserveElectricBorder( borderActivateAll );
#ifdef HAVE_XRENDER
alphaFormat = XRenderFindStandardFormat( display(), PictStandardARGB32 );
#endif
}
PresentWindowsEffect::~PresentWindowsEffect()
@ -178,6 +182,11 @@ void PresentWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion regio
// Call the next effect.
effects->paintWindow( w, mask, region, data );
if(mActiveness > 0.0f && mWindowData.contains(w))
{
paintWindowIcon( w, data );
}
}
void PresentWindowsEffect::postPaintScreen()
@ -785,5 +794,77 @@ void PresentWindowsEffect::updateFilterTexture()
#endif
}
void PresentWindowsEffect::paintWindowIcon( EffectWindow* w, WindowPaintData& paintdata )
{
WindowData& data = mWindowData[ w ];
if( data.icon.serialNumber() != w->icon().serialNumber())
{ // make sure data.icon is the right QPixmap, and rebind
data.icon = w->icon();
#ifdef HAVE_OPENGL
if( effects->compositingType() == OpenGLCompositing )
{
data.iconTexture.load( data.icon );
data.iconTexture.setFilter( GL_LINEAR );
}
#endif
#ifdef HAVE_XRENDER
if( effects->compositingType() == XRenderCompositing )
{
if( data.iconPicture != None )
XRenderFreePicture( display(), data.iconPicture );
data.iconPicture = XRenderCreatePicture( display(),
data.icon.handle(), alphaFormat, 0, NULL );
}
#endif
}
int icon_margin = 8;
int width = data.icon.width();
int height = data.icon.height();
int x = w->x() + paintdata.xTranslate + w->width() * paintdata.xScale * 0.95 - width - icon_margin;
int y = w->y() + paintdata.yTranslate + w->height() * paintdata.yScale * 0.95 - height - icon_margin;
#ifdef HAVE_OPENGL
if( effects->compositingType() == OpenGLCompositing )
{
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
// Render some background
glColor4f( 0, 0, 0, 0.5 * mActiveness );
renderRoundBox( QRect( x-3, y-3, width+6, height+6 ), 3 );
// Render the icon
glColor4f( 1, 1, 1, 1 * mActiveness );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
data.iconTexture.bind();
const float verts[ 4 * 2 ] =
{
x, y,
x, y + height,
x + width, y + height,
x + width, y
};
const float texcoords[ 4 * 2 ] =
{
0, 1,
0, 0,
1, 0,
1, 1
};
renderGLGeometry( 4, verts, texcoords );
data.iconTexture.unbind();
glPopAttrib();
}
#endif
#ifdef HAVE_XRENDER
if( effects->compositingType() == XRenderCompositing )
{
XRenderComposite( display(),
data.icon.depth() == 32 ? PictOpOver : PictOpSrc,
data.iconPicture, None,
effects->xrenderBufferPicture(),
0, 0, 0, 0, x, y, width, height );
}
#endif
}
} // namespace
#include "presentwindows.moc"

View file

@ -15,6 +15,10 @@ License. See the file "COPYING" for the exact licensing terms.
#include <kwineffects.h>
#include <kwinglutils.h>
#ifdef HAVE_XRENDER
#include <X11/extensions/Xrender.h>
#endif
namespace KWin
{
@ -64,7 +68,9 @@ class PresentWindowsEffect
void updateFilterTexture();
void discardFilterTexture();
void paintWindowIcon( EffectWindow* w, WindowPaintData& data );
// Called once the effect is activated (and wasn't activated before)
void effectActivated();
// Called once the effect has terminated
@ -93,6 +99,13 @@ class PresentWindowsEffect
float hover;
int slot;
int slot_distance;
QPixmap icon;
#ifdef HAVE_OPENGL
GLTexture iconTexture;
#endif
#ifdef HAVE_XRENDER
Picture iconPicture;
#endif
};
typedef QHash<EffectWindow*, WindowData> DataHash;
DataHash mWindowData;
@ -106,6 +119,10 @@ class PresentWindowsEffect
ElectricBorder borderActivate;
ElectricBorder borderActivateAll;
#ifdef HAVE_XRENDER
XRenderPictFormat* alphaFormat;
#endif
};
} // namespace