2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
2010-01-21 14:56:24 +00:00
|
|
|
Copyright (C) 2010 Jorge Mata <matamax123@gmail.com>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "trackmouse.h"
|
|
|
|
|
2008-04-15 12:54:17 +00:00
|
|
|
#include <QTime>
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2007-05-13 17:47:20 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
|
2010-01-21 14:56:24 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( trackmouse, TrackMouseEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
const int STARS = 5;
|
|
|
|
const int DIST = 50;
|
|
|
|
|
|
|
|
TrackMouseEffect::TrackMouseEffect()
|
|
|
|
: active( false )
|
|
|
|
, angle( 0 )
|
|
|
|
, texture( NULL )
|
|
|
|
{
|
2010-01-21 14:56:24 +00:00
|
|
|
mousePolling = false;
|
|
|
|
actionCollection = new KActionCollection( this );
|
|
|
|
action = static_cast< KAction* >( actionCollection->addAction( "TrackMouse" ));
|
|
|
|
action->setText( i18n( "Track mouse" ) );
|
|
|
|
action->setGlobalShortcut( KShortcut() );
|
|
|
|
connect( action, SIGNAL( triggered( bool ) ), this, SLOT( toggle() ) );
|
|
|
|
reconfigure( ReconfigureAll );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackMouseEffect::~TrackMouseEffect()
|
|
|
|
{
|
2010-01-21 14:56:24 +00:00
|
|
|
if( mousePolling )
|
|
|
|
effects->stopMousePolling();
|
2007-04-29 17:35:43 +00:00
|
|
|
delete texture;
|
|
|
|
}
|
|
|
|
|
2010-01-21 14:56:24 +00:00
|
|
|
void TrackMouseEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig( "TrackMouse" );
|
|
|
|
bool shift = conf.readEntry( "Shift", false );
|
|
|
|
bool alt = conf.readEntry( "Alt", false );
|
|
|
|
bool control = conf.readEntry( "Control", true );
|
|
|
|
bool meta = conf.readEntry( "Meta", true );
|
|
|
|
modifier = 0;
|
|
|
|
if( meta )
|
|
|
|
modifier |= Qt::MetaModifier;
|
|
|
|
if( control )
|
|
|
|
modifier |= Qt::ControlModifier;
|
|
|
|
if( alt )
|
|
|
|
modifier |= Qt::AltModifier;
|
|
|
|
if( shift )
|
|
|
|
modifier |= Qt::ShiftModifier;
|
|
|
|
if( modifier != 0 && action != NULL )
|
|
|
|
{
|
2010-01-22 05:01:05 +00:00
|
|
|
if( !mousePolling )
|
|
|
|
effects->startMousePolling();
|
2010-01-21 14:56:24 +00:00
|
|
|
mousePolling = true;
|
|
|
|
}
|
|
|
|
else if( action != NULL )
|
|
|
|
{
|
|
|
|
if( mousePolling )
|
|
|
|
effects->stopMousePolling();
|
|
|
|
mousePolling = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void TrackMouseEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-04-15 12:54:17 +00:00
|
|
|
if( active ) {
|
|
|
|
QTime t = QTime::currentTime();
|
|
|
|
angle = ((t.second() % 4) * 90.0) + (t.msec() / 1000.0 * 90.0);
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintScreen( data, time );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
|
|
|
{
|
|
|
|
effects->paintScreen( mask, region, data ); // paint normal screen
|
|
|
|
if( !active )
|
|
|
|
return;
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
if( texture )
|
|
|
|
{
|
|
|
|
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
|
|
|
|
texture->bind();
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
for( int i = 0;
|
|
|
|
i < STARS;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
QRect r = starRect( i );
|
2008-02-25 11:32:21 +00:00
|
|
|
texture->render( region, r );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
texture->unbind();
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackMouseEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( active )
|
|
|
|
{
|
|
|
|
for( int i = 0;
|
|
|
|
i < STARS;
|
|
|
|
++i )
|
|
|
|
effects->addRepaint( starRect( i ));
|
|
|
|
}
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2010-01-21 14:56:24 +00:00
|
|
|
void TrackMouseEffect::toggle()
|
|
|
|
{
|
2010-01-22 05:01:05 +00:00
|
|
|
if( mousePolling )
|
|
|
|
return;
|
2010-01-21 14:56:24 +00:00
|
|
|
if( !active )
|
|
|
|
{
|
|
|
|
if( texture == NULL )
|
|
|
|
loadTexture();
|
|
|
|
if( texture == NULL )
|
|
|
|
return;
|
|
|
|
active = true;
|
|
|
|
angle = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
active = false;
|
|
|
|
for( int i = 0; i < STARS; ++i )
|
|
|
|
effects->addRepaint( starRect( i ));
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void TrackMouseEffect::mouseChanged( const QPoint&, const QPoint&, Qt::MouseButtons,
|
2008-01-02 15:34:12 +00:00
|
|
|
Qt::MouseButtons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2010-01-21 14:56:24 +00:00
|
|
|
if( modifier != 0 && modifiers == modifier )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( !active )
|
|
|
|
{
|
|
|
|
if( texture == NULL )
|
|
|
|
loadTexture();
|
|
|
|
if( texture == NULL )
|
|
|
|
return;
|
|
|
|
active = true;
|
|
|
|
angle = 0;
|
|
|
|
}
|
2010-01-21 14:56:24 +00:00
|
|
|
for( int i = 0; i < STARS; ++i )
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->addRepaint( starRect( i ));
|
|
|
|
}
|
2010-01-21 14:56:24 +00:00
|
|
|
else if( active )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2010-01-21 14:56:24 +00:00
|
|
|
for( int i = 0; i < STARS; ++i )
|
|
|
|
effects->addRepaint( starRect( i ));
|
|
|
|
active = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect TrackMouseEffect::starRect( int num ) const
|
|
|
|
{
|
|
|
|
int a = angle + 360 / STARS * num;
|
|
|
|
int x = cursorPos().x() + int( DIST * cos( a * ( 2 * M_PI / 360 )));
|
|
|
|
int y = cursorPos().y() + int( DIST * sin( a * ( 2 * M_PI / 360 )));
|
|
|
|
return QRect( QPoint( x - textureSize.width() / 2,
|
|
|
|
y - textureSize.height() / 2 ), textureSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackMouseEffect::loadTexture()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
QString file = KGlobal::dirs()->findResource( "appdata", "trackmouse.png" );
|
|
|
|
if( file.isEmpty())
|
|
|
|
return;
|
|
|
|
QImage im( file );
|
|
|
|
texture = new GLTexture( im );
|
|
|
|
textureSize = im.size();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|