Allow changing the desktop in DesktopGridEffect by clicking.

svn path=/branches/work/kwin_composite/; revision=654680
icc-effect-5.14.5
Luboš Luňák 2007-04-16 19:09:21 +00:00
parent f8fd7b7ff1
commit 40002ec325
5 changed files with 104 additions and 5 deletions

View File

@ -288,6 +288,11 @@ int EffectsHandlerImpl::numberOfDesktops() const
return Workspace::self()->numberOfDesktops();
}
void EffectsHandlerImpl::setCurrentDesktop( int desktop )
{
Workspace::self()->setCurrentDesktop( desktop );
}
QString EffectsHandlerImpl::desktopName( int desktop ) const
{
return Workspace::self()->desktopName( desktop );

View File

@ -39,6 +39,7 @@ class EffectsHandlerImpl : public EffectsHandler
virtual int currentDesktop() const;
virtual int numberOfDesktops() const;
virtual void setCurrentDesktop( int desktop );
virtual QString desktopName( int desktop ) const;
virtual int displayWidth() const;
virtual int displayHeight() const;

View File

@ -13,6 +13,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include <kaction.h>
#include <kactioncollection.h>
#include <klocale.h>
#include <qevent.h>
namespace KWin
{
@ -22,6 +23,7 @@ KWIN_EFFECT( DesktopGrid, DesktopGridEffect )
DesktopGridEffect::DesktopGridEffect()
: progress( 0 )
, activated( false )
, keyboard_grab( false )
{
KActionCollection* actionCollection = new KActionCollection( this );
KAction* a = static_cast< KAction* >( actionCollection->addAction( "ShowDesktopGrid" ));
@ -42,6 +44,15 @@ void DesktopGridEffect::prePaintScreen( int* mask, QRegion* region, int time )
// so with normal screen painting second screen paint would erase parts of the first paint
if( progress != 0 )
*mask |= PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_BACKGROUND_FIRST;
if( !activated && progress == 0 )
finish();
int d = posToDesktop( cursorPos());
if( d != hover_desktop )
{
*region |= desktopRect( hover_desktop, true );
hover_desktop = d;
*region |= desktopRect( hover_desktop, true );
}
}
effects->prePaintScreen( mask, region, time );
}
@ -85,6 +96,16 @@ void DesktopGridEffect::paintScreen( int mask, QRegion region, ScreenPaintData&
}
}
void DesktopGridEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
if( progress != 0 )
{
if( painting_desktop != hover_desktop )
data.brightness *= 0.7;
}
effects->paintWindow( w, mask, region, data );
}
void DesktopGridEffect::postPaintScreen()
{
if( activated ? progress != 1 : progress != 0 )
@ -93,7 +114,7 @@ void DesktopGridEffect::postPaintScreen()
}
// Gives a position of the given desktop when all desktops are arranged in a grid
QRect DesktopGridEffect::desktopRect( int desktop, bool scaled )
QRect DesktopGridEffect::desktopRect( int desktop, bool scaled ) const
{
int x, y;
Qt::Orientation orientation;
@ -116,18 +137,79 @@ QRect DesktopGridEffect::desktopRect( int desktop, bool scaled )
return rect;
}
int DesktopGridEffect::posToDesktop( const QPoint& pos ) const
{
for( int desktop = 1; // TODO could be perhaps optimized
desktop <= effects->numberOfDesktops();
++desktop )
{
if( desktopRect( desktop, true ).contains( pos ))
return desktop;
}
return 0;
}
void DesktopGridEffect::desktopChanged( int )
{
if( activated )
toggle();
setActive( false );
}
void DesktopGridEffect::toggle()
{
activated = !activated;
setActive( !activated );
}
void DesktopGridEffect::setActive( bool active )
{
if( activated == active )
return;
activated = active;
if( activated && progress == 0 )
setup();
effects->addRepaintFull();
}
void DesktopGridEffect::setup()
{
keyboard_grab = effects->grabKeyboard( this );
input = effects->createInputWindow( this, 0, 0, displayWidth(), displayHeight(),
Qt::PointingHandCursor );
hover_desktop = effects->currentDesktop();
}
void DesktopGridEffect::finish()
{
if( keyboard_grab )
effects->ungrabKeyboard();
keyboard_grab = false;
effects->destroyInputWindow( input );
effects->addRepaintFull(); // to get rid of hover
}
void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
{
if( e->type() == QEvent::MouseButtonPress )
{
effects->setCurrentDesktop( posToDesktop( static_cast< QMouseEvent* >( e )->pos()));
setActive( false );
}
if( e->type() == QEvent::MouseMove )
{
int d = posToDesktop( static_cast< QMouseEvent* >( e )->pos());
if( d != hover_desktop )
{
effects->addRepaint( desktopRect( hover_desktop, true ));
hover_desktop = d;
effects->addRepaint( desktopRect( hover_desktop, true ));
}
}
}
void DesktopGridEffect::grabbedKeyboardEvent( QKeyEvent* e )
{
// TODO
}
} // namespace
#include "desktopgrid.moc"

View File

@ -27,14 +27,24 @@ class DesktopGridEffect
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void postPaintScreen();
virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time );
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
virtual void desktopChanged( int old );
virtual void windowInputMouseEvent( Window w, QEvent* e );
virtual void grabbedKeyboardEvent( QKeyEvent* e );
private slots:
void toggle();
private:
QRect desktopRect( int desktop, bool scaled );
QRect desktopRect( int desktop, bool scaled ) const;
int posToDesktop( const QPoint& pos ) const;
void setActive( bool active );
void setup();
void finish();
float progress;
bool activated;
int painting_desktop;
int hover_desktop;
Window input;
bool keyboard_grab;
};
} // namespace

View File

@ -188,6 +188,7 @@ class KWIN_EXPORT EffectsHandler
//
virtual int currentDesktop() const = 0;
virtual int numberOfDesktops() const = 0;
virtual void setCurrentDesktop( int desktop ) = 0;
virtual QString desktopName( int desktop ) const = 0;
virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;