Dump the old taskbar thumbnail effect, replace it with a new one
that renders the thumbnail directly into another window (taskbar's tooltip). svn path=/trunk/KDE/kdebase/workspace/; revision=756636master
parent
41c2b3923d
commit
52e8207d5f
@ -1,123 +0,0 @@
|
||||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
||||
|
||||
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 "demo_taskbarthumbnail.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
KWIN_EFFECT( demo_taskbarthumbnail, TaskbarThumbnailEffect )
|
||||
|
||||
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
|
||||
{
|
||||
mLastCursorPos = QPoint(-1, -1);
|
||||
}
|
||||
|
||||
|
||||
void TaskbarThumbnailEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
||||
{
|
||||
// We might need to paint thumbnails if cursor has moved since last
|
||||
// painting or some thumbnails were painted the last time
|
||||
QPoint cpos = cursorPos();
|
||||
if(cpos != mLastCursorPos || mThumbnails.count() > 0)
|
||||
{
|
||||
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
||||
mThumbnails.clear();
|
||||
mLastCursorPos = cpos;
|
||||
}
|
||||
|
||||
effects->prePaintScreen(data, time);
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
||||
{
|
||||
QRect iconGeo = w->iconGeometry();
|
||||
if(iconGeo.contains( mLastCursorPos ))
|
||||
mThumbnails.append( w );
|
||||
|
||||
effects->prePaintWindow( w, data, time );
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::postPaintScreen()
|
||||
{
|
||||
// Paint the thumbnails. They need to be painted after other windows
|
||||
// because we want them on top of everything else
|
||||
int space = 4;
|
||||
foreach( EffectWindow* w, mThumbnails )
|
||||
{
|
||||
QRect thumb = getThumbnailPosition( w, &space);
|
||||
WindowPaintData thumbdata( w );
|
||||
thumbdata.xTranslate = thumb.x() - w->x();
|
||||
thumbdata.yTranslate = thumb.y() - w->y();
|
||||
thumbdata.xScale = thumb.width() / (double)w->width();
|
||||
thumbdata.yScale = thumb.height() / (double)w->height();
|
||||
// From Scene::Window::infiniteRegion()
|
||||
QRegion infRegion = QRegion( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
|
||||
effects->paintWindow( w, PAINT_WINDOW_TRANSFORMED, infRegion, thumbdata );
|
||||
}
|
||||
|
||||
// Call the next effect.
|
||||
effects->postPaintScreen();
|
||||
}
|
||||
|
||||
QRect TaskbarThumbnailEffect::getThumbnailPosition( EffectWindow* c, int* space ) const
|
||||
{
|
||||
QRect thumb;
|
||||
QRect icon = c->iconGeometry();
|
||||
|
||||
// Try to figure out if taskbar is horizontal or vertical
|
||||
if( icon.right() < 40 || ( displayWidth() - icon.left()) < 40 )
|
||||
{
|
||||
// Vertical taskbar...
|
||||
double scale = qMin(qMax(icon.height(), 100) / (double)c->height(), 200.0 / c->width());
|
||||
thumb.setSize( QSize( int(scale * c->width()),int(scale * c->height()) ));
|
||||
if( icon.right() < 40 ) // ...on the left
|
||||
thumb.moveTopLeft( QPoint( icon.right() + *space, icon.top() ));
|
||||
else // ...on the right
|
||||
thumb.moveTopRight( QPoint( icon.left() - *space, icon.top()));
|
||||
*space += thumb.width() + 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Horizontal taskbar...
|
||||
double scale = qMin(qMax(icon.width(), 75) / (double)c->width(), 200.0 / c->height());
|
||||
thumb.setSize( QSize( int(scale * c->width()),int(scale * c->height()) ));
|
||||
if( icon.top() < ( displayHeight() - icon.bottom())) // ...at the top
|
||||
thumb.moveTopLeft( QPoint( icon.left(), icon.bottom() + *space ));
|
||||
else // ...at the bottom
|
||||
thumb.moveBottomLeft( QPoint( icon.left(), icon.top() - *space ));
|
||||
*space += thumb.height() + 8;
|
||||
}
|
||||
return thumb;
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::mouseChanged( const QPoint& pos, const QPoint&,
|
||||
Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers )
|
||||
{
|
||||
// this should check if the mouse position change actually means something
|
||||
// (just like it should be done in prePaintScreen()), but since this effect
|
||||
// will be replaced in the future, just trigger a repaint
|
||||
if( pos != mLastCursorPos )
|
||||
effects->addRepaintFull();
|
||||
}
|
||||
|
||||
} // namespace
|
@ -0,0 +1,123 @@
|
||||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
||||
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
||||
|
||||
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 "taskbarthumbnail.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
|
||||
// This effect shows a preview inside a window that has a special property set
|
||||
// on it that says which window and where to render. It is used by the taskbar
|
||||
// to show window previews in tooltips.
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
KWIN_EFFECT( taskbarthumbnail, TaskbarThumbnailEffect )
|
||||
|
||||
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
|
||||
{
|
||||
atom = XInternAtom( display(), "_KDE_WINDOW_PREVIEW", False );
|
||||
effects->registerPropertyType( atom, true );
|
||||
// TODO hackish way to announce support, make better after 4.0
|
||||
unsigned char dummy = 0;
|
||||
XChangeProperty( display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1 );
|
||||
}
|
||||
|
||||
TaskbarThumbnailEffect::~TaskbarThumbnailEffect()
|
||||
{
|
||||
XDeleteProperty( display(), rootWindow(), atom );
|
||||
effects->registerPropertyType( atom, false );
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
||||
{
|
||||
// if( thumbnails.count() > 0 )
|
||||
// // TODO this should not be needed (it causes whole screen repaint)
|
||||
// data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
||||
effects->prePaintScreen(data, time);
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
||||
{
|
||||
// TODO what if of the windows is translucent and one not? change data.mask?
|
||||
effects->prePaintWindow( w, data, time );
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
||||
{
|
||||
effects->paintWindow( w, mask, region, data ); // paint window first
|
||||
if( thumbnails.contains( w ))
|
||||
{ // paint thumbnails on it
|
||||
foreach( const Data thumb, thumbnails.values( w ))
|
||||
{
|
||||
EffectWindow* thumbw = effects->findWindow( thumb.window );
|
||||
WindowPaintData data( thumbw );
|
||||
QRect r;
|
||||
setPositionTransformations( data, r,
|
||||
thumbw, thumb.rect.translated( w->pos()), Qt::KeepAspectRatio );
|
||||
effects->drawWindow( thumbw,
|
||||
PAINT_WINDOW_OPAQUE | PAINT_WINDOW_TRANSFORMED,
|
||||
r, data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::windowAdded( EffectWindow* w )
|
||||
{
|
||||
propertyNotify( w, atom ); // read initial value
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::windowRemoved( EffectWindow* w )
|
||||
{
|
||||
thumbnails.remove( w );
|
||||
}
|
||||
|
||||
void TaskbarThumbnailEffect::propertyNotify( EffectWindow* w, long a )
|
||||
{
|
||||
if( a != atom )
|
||||
return;
|
||||
thumbnails.remove( w );
|
||||
QByteArray data = w->readProperty( atom, atom, 32 );
|
||||
if( data.length() < 1 )
|
||||
return;
|
||||
long* d = reinterpret_cast< long* >( data.data());
|
||||
int len = data.length() / 4;
|
||||
int pos = 0;
|
||||
int cnt = d[ 0 ];
|
||||
++pos;
|
||||
for( int i = 0;
|
||||
i < cnt;
|
||||
++i )
|
||||
{
|
||||
int size = d[ pos ];
|
||||
if( len - pos < size )
|
||||
return; // format error
|
||||
++pos;
|
||||
Data data;
|
||||
data.window = d[ pos ];
|
||||
data.rect = QRect( d[ pos + 1 ], d[ pos + 2 ], d[ pos + 3 ], d[ pos + 4 ] );
|
||||
thumbnails.insert( w, data );
|
||||
pos += size;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
Loading…
Reference in New Issue