diff --git a/effects.cpp b/effects.cpp index 924af0b4ab..f529f79a6a 100644 --- a/effects.cpp +++ b/effects.cpp @@ -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 ); diff --git a/effects.h b/effects.h index ae017e7a2c..7472d75ff7 100644 --- a/effects.h +++ b/effects.h @@ -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; diff --git a/effects/desktopgrid.cpp b/effects/desktopgrid.cpp index c50c732241..23e681ec97 100644 --- a/effects/desktopgrid.cpp +++ b/effects/desktopgrid.cpp @@ -13,6 +13,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include #include +#include 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" diff --git a/effects/desktopgrid.h b/effects/desktopgrid.h index f196c83f5a..4d95daa781 100644 --- a/effects/desktopgrid.h +++ b/effects/desktopgrid.h @@ -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 diff --git a/lib/kwineffects.h b/lib/kwineffects.h index 04b837264f..f4ae1251fd 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -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;