diff --git a/CMakeLists.txt b/CMakeLists.txt index fac858338e..1c5cf341d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,6 @@ install(TARGETS kwin DESTINATION bin) install( FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) install( FILES kwin.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kwin ) -install( FILES effects/data/explosion.frag effects/data/explosion.vert effects/data/explosion-start.png effects/data/explosion-end.png DESTINATION ${DATA_INSTALL_DIR}/kwin ) - kde4_install_icons( ${ICON_INSTALL_DIR} ) diff --git a/COMPOSITE_TODO b/COMPOSITE_TODO index a452fc6501..79b670403b 100644 --- a/COMPOSITE_TODO +++ b/COMPOSITE_TODO @@ -245,3 +245,7 @@ Effects TODO - or whatever * DimInactive flickers when switching between windows (temporarily no window becomes active) + ++ TrackMouse needs a better way of activating + - LMB+RMB is problematic, some systems handle that as MMB, and LMB+RMB press is still + two consequent events diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 83e1f234ca..a54f60f96e 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -41,13 +41,23 @@ if(OPENGL_FOUND) SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} magnifier.cpp shadow.cpp + trackmouse.cpp wavywindows.cpp ) install( FILES magnifier.desktop shadow.desktop + trackmouse.desktop wavywindows.desktop DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) + + install( FILES + data/trackmouse.png + data/explosion.frag + data/explosion.vert + data/explosion-start.png + data/explosion-end.png + DESTINATION ${DATA_INSTALL_DIR}/kwin ) endif(OPENGL_FOUND) if (X11_Xrender_FOUND) @@ -108,3 +118,4 @@ if( HAVE_CAPTURY ) target_link_libraries(kwin4_effect_videorecord ${CAPTURY_LDFLAGS}) install( FILES videorecord.desktop DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) endif( HAVE_CAPTURY ) + diff --git a/effects/data/trackmouse.png b/effects/data/trackmouse.png new file mode 100644 index 0000000000..f9cdb99448 Binary files /dev/null and b/effects/data/trackmouse.png differ diff --git a/effects/trackmouse.cpp b/effects/trackmouse.cpp new file mode 100644 index 0000000000..44aa80b6b9 --- /dev/null +++ b/effects/trackmouse.cpp @@ -0,0 +1,162 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2006 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#include + +#include "trackmouse.h" + +#include +#include + +#include + +#ifdef HAVE_OPENGL +#include +#endif + +#include + +namespace KWin +{ + +KWIN_EFFECT( TrackMouse, TrackMouseEffect ) + +const int STARS = 5; +const int DIST = 50; + +TrackMouseEffect::TrackMouseEffect() + : active( false ) + , angle( 0 ) + , texture( NULL ) + { + } + +TrackMouseEffect::~TrackMouseEffect() + { + delete texture; + } + +void TrackMouseEffect::prePaintScreen( int* mask, QRegion* region, int time ) + { + if( active ) + angle = ( angle + time / 10 ) % 360; + effects->prePaintScreen( mask, region, time ); + } + +void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) + { + effects->paintScreen( mask, region, data ); // paint normal screen + if( !active ) + return; +#ifdef HAVE_OPENGL + 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 ); + glEnableClientState( GL_VERTEX_ARRAY ); + int verts[ 4 * 2 ] = + { + r.x(), r.y(), + r.x(), r.y() + r.height(), + r.x() + r.width(), r.y() + r.height(), + r.x() + r.width(), r.y() + }; + glVertexPointer( 2, GL_INT, 0, verts ); + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + int texcoords[ 4 * 2 ] = + { + 0, 1, + 0, 0, + 1, 0, + 1, 1 + }; + glTexCoordPointer( 2, GL_INT, 0, texcoords ); + glDrawArrays( GL_QUADS, 0, 4 ); + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); + } + texture->unbind(); + glPopAttrib(); + } +#endif + } + +void TrackMouseEffect::postPaintScreen() + { + if( active ) + { + for( int i = 0; + i < STARS; + ++i ) + effects->addRepaint( starRect( i )); + } + effects->postPaintScreen(); + } + +void TrackMouseEffect::cursorMoved( const QPoint&, Qt::MouseButtons buttons ) + { + if( buttons == ( Qt::LeftButton | Qt::RightButton )) + { + if( !active ) + { + if( texture == NULL ) + loadTexture(); + if( texture == NULL ) + return; + active = true; + angle = 0; + } + for( int i = 0; + i < STARS; + ++i ) + effects->addRepaint( starRect( i )); + } + else + { + if( active ) + { + for( int i = 0; + i < STARS; + ++i ) + effects->addRepaint( starRect( i )); + active = false; + } + } + } + +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() + { +#ifdef HAVE_OPENGL + QString file = KGlobal::dirs()->findResource( "appdata", "trackmouse.png" ); + if( file.isEmpty()) + return; + QImage im( file ); + texture = new GLTexture( im ); + textureSize = im.size(); +#endif + } + +} // namespace diff --git a/effects/trackmouse.desktop b/effects/trackmouse.desktop new file mode 100644 index 0000000000..f5ef9a5810 --- /dev/null +++ b/effects/trackmouse.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=TrackMouse +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/trackmouse.h b/effects/trackmouse.h new file mode 100644 index 0000000000..28b1d350dd --- /dev/null +++ b/effects/trackmouse.h @@ -0,0 +1,41 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_TRACKMOUSE_H +#define KWIN_TRACKMOUSE_H + +#include +#include + +namespace KWin +{ + +class TrackMouseEffect + : public Effect + { + public: + TrackMouseEffect(); + virtual ~TrackMouseEffect(); + virtual void prePaintScreen( int* mask, QRegion* region, int time ); + virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); + virtual void postPaintScreen(); + virtual void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons ); + private: + QRect starRect( int num ) const; + void loadTexture(); + bool active; + int angle; + GLTexture* texture; + QSize textureSize; + }; + +} // namespace + +#endif