Make DesktopGrid useful also from keyboard.

svn path=/trunk/KDE/kdebase/workspace/; revision=739147
icc-effect-5.14.5
Luboš Luňák 2007-11-20 16:17:08 +00:00
parent c83210c60a
commit d18e4933a0
8 changed files with 128 additions and 46 deletions

View File

@ -369,6 +369,26 @@ bool EffectsHandlerImpl::optionRollOverDesktops() const
return options->rollOverDesktops;
}
int EffectsHandlerImpl::desktopToLeft( int desktop, bool wrap ) const
{
return Workspace::self()->desktopToLeft( desktop, wrap );
}
int EffectsHandlerImpl::desktopToRight( int desktop, bool wrap ) const
{
return Workspace::self()->desktopToRight( desktop, wrap );
}
int EffectsHandlerImpl::desktopUp( int desktop, bool wrap ) const
{
return Workspace::self()->desktopUp( desktop, wrap );
}
int EffectsHandlerImpl::desktopDown( int desktop, bool wrap ) const
{
return Workspace::self()->desktopDown( desktop, wrap );
}
int EffectsHandlerImpl::displayWidth() const
{
return KWin::displayWidth();

View File

@ -78,6 +78,10 @@ class EffectsHandlerImpl : public EffectsHandler
virtual QRect clientArea( clientAreaOption opt, const QPoint& p, int desktop ) const;
virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const;
virtual bool optionRollOverDesktops() const;
virtual int desktopToLeft( int desktop, bool wrap ) const;
virtual int desktopToRight( int desktop, bool wrap ) const;
virtual int desktopUp( int desktop, bool wrap ) const;
virtual int desktopDown( int desktop, bool wrap ) const;
virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor );
virtual void destroyInputWindow( Window w );

View File

@ -70,13 +70,6 @@ void DesktopGridEffect::prePaintScreen( ScreenPrePaintData& data, int time )
data.mask |= PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_BACKGROUND_FIRST;
if( !activated && progress == 0 )
finish();
int d = posToDesktop( cursorPos());
if( d != hover_desktop )
{
data.paint |= desktopRect( hover_desktop, true );
hover_desktop = d;
data.paint |= desktopRect( hover_desktop, true );
}
}
effects->prePaintScreen( data, time );
}
@ -249,7 +242,7 @@ void DesktopGridEffect::paintWindow( EffectWindow* w, int mask, QRegion region,
data.xTranslate += window_move_pos.x() * x - ( desktop.x() + w->x());
data.yTranslate += window_move_pos.y() * y - ( desktop.y() + w->y());
}
else if( painting_desktop != hover_desktop )
else if( painting_desktop != highlighted_desktop )
data.brightness *= 0.7;
}
effects->paintWindow( w, mask, region, data );
@ -448,7 +441,7 @@ void DesktopGridEffect::setup()
input = effects->createInputWindow( this, 0, 0, displayWidth(), displayHeight(),
Qt::PointingHandCursor );
effects->setActiveFullScreenEffect( this );
hover_desktop = effects->currentDesktop();
setHighlightedDesktop( effects->currentDesktop());
}
void DesktopGridEffect::finish()
@ -461,7 +454,7 @@ void DesktopGridEffect::finish()
window_move = NULL;
effects->destroyInputWindow( input );
effects->setActiveFullScreenEffect( 0 );
effects->addRepaintFull(); // to get rid of hover
effects->addRepaintFull(); // to get rid of highlight
}
void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
@ -475,12 +468,8 @@ void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
{
// highlight desktop under mouse
int d = posToDesktop( me->pos());
if( d != hover_desktop )
{
effects->addRepaint( desktopRect( hover_desktop, true ));
hover_desktop = d;
effects->addRepaint( desktopRect( hover_desktop, true ));
}
if( d != highlighted_desktop )
setHighlightedDesktop( d );
if( window_move != NULL ) // handle window moving
{
was_window_move = true;
@ -556,9 +545,73 @@ void DesktopGridEffect::windowClosed( EffectWindow* w )
void DesktopGridEffect::grabbedKeyboardEvent( QKeyEvent* e )
{
// TODO
if( e->type() == QEvent::KeyPress )
{
switch( e->key())
{ // wrap only on autorepeat
case Qt::Key_Left:
setHighlightedDesktop( effects->desktopToLeft( highlighted_desktop,
!e->isAutoRepeat()));
break;
case Qt::Key_Right:
setHighlightedDesktop( effects->desktopToRight( highlighted_desktop,
!e->isAutoRepeat()));
break;
case Qt::Key_Up:
setHighlightedDesktop( effects->desktopUp( highlighted_desktop,
!e->isAutoRepeat()));
break;
case Qt::Key_Down:
setHighlightedDesktop( effects->desktopDown( highlighted_desktop,
!e->isAutoRepeat()));
break;
default:
break;
}
}
else if( e->type() == QEvent::KeyRelease )
{
int desktop = -1;
// switch by F<number> or just <number>
if( e->key() >= Qt::Key_F1 && e->key() <= Qt::Key_F35 )
desktop = e->key() - Qt::Key_F1 + 1;
else if( e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9 )
desktop = e->key() == Qt::Key_0 ? 10 : e->key() - Qt::Key_0;
if( desktop != -1 )
{
if( desktop <= effects->numberOfDesktops())
{
setHighlightedDesktop( desktop );
effects->setCurrentDesktop( desktop );
setActive( false );
}
return;
}
switch( e->key())
{
case Qt::Key_Escape:
setActive( false );
return;
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Space:
effects->setCurrentDesktop( highlighted_desktop );
setActive( false );
return;
default:
break;
}
}
}
void DesktopGridEffect::setHighlightedDesktop( int d )
{
if( d == highlighted_desktop || d <= 0 || d > effects->numberOfDesktops())
return;
effects->addRepaint( desktopRect( highlighted_desktop, true ));
highlighted_desktop = d;
effects->addRepaint( desktopRect( highlighted_desktop, true ));
}
} // namespace

View File

@ -45,10 +45,11 @@ class DesktopGridEffect
void paintSlide( int mask, QRegion region, const ScreenPaintData& data );
void paintScreenDesktop( int desktop, int mask, QRegion region, ScreenPaintData data );
void slideDesktopChanged( int old );
void setHighlightedDesktop( int desktop );
double progress;
bool activated;
int painting_desktop;
int hover_desktop;
int highlighted_desktop;
Window input;
bool keyboard_grab;
bool was_window_move;

View File

@ -348,6 +348,10 @@ class KWIN_EXPORT EffectsHandler
virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;
virtual bool optionRollOverDesktops() const = 0;
virtual int desktopToLeft( int desktop, bool wrap ) const = 0;
virtual int desktopToRight( int desktop, bool wrap ) const = 0;
virtual int desktopUp( int desktop, bool wrap ) const = 0;
virtual int desktopDown( int desktop, bool wrap ) const = 0;
virtual EffectWindowList stackingOrder() const = 0;
// window will be temporarily painted as if being at the top of the stack

View File

@ -755,7 +755,7 @@ void Workspace::slotSwitchDesktopPrevious()
void Workspace::slotSwitchDesktopRight()
{
int desktop = desktopToRight( currentDesktop());
int desktop = desktopToRight( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@ -763,7 +763,7 @@ void Workspace::slotSwitchDesktopRight()
void Workspace::slotSwitchDesktopLeft()
{
int desktop = desktopToLeft( currentDesktop());
int desktop = desktopToLeft( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@ -771,7 +771,7 @@ void Workspace::slotSwitchDesktopLeft()
void Workspace::slotSwitchDesktopUp()
{
int desktop = desktopUp( currentDesktop());
int desktop = desktopUp( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@ -779,7 +779,7 @@ void Workspace::slotSwitchDesktopUp()
void Workspace::slotSwitchDesktopDown()
{
int desktop = desktopDown( currentDesktop());
int desktop = desktopDown( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@ -1001,7 +1001,7 @@ void Workspace::windowToPreviousDesktop( Client* c )
void Workspace::slotWindowToDesktopRight()
{
int d = desktopToRight( currentDesktop());
int d = desktopToRight( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;
@ -1016,7 +1016,7 @@ void Workspace::slotWindowToDesktopRight()
void Workspace::slotWindowToDesktopLeft()
{
int d = desktopToLeft( currentDesktop());
int d = desktopToLeft( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;
@ -1031,7 +1031,7 @@ void Workspace::slotWindowToDesktopLeft()
void Workspace::slotWindowToDesktopUp()
{
int d = desktopUp( currentDesktop());
int d = desktopUp( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;
@ -1046,7 +1046,7 @@ void Workspace::slotWindowToDesktopUp()
void Workspace::slotWindowToDesktopDown()
{
int d = desktopDown( currentDesktop());
int d = desktopDown( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;

View File

@ -1387,7 +1387,7 @@ void Workspace::previousDesktop()
setCurrentDesktop(desktop > 0 ? desktop : numberOfDesktops());
}
int Workspace::desktopToRight( int desktop ) const
int Workspace::desktopToRight( int desktop, bool wrap ) const
{
int x,y;
Qt::Orientation orientation;
@ -1398,7 +1398,7 @@ int Workspace::desktopToRight( int desktop ) const
dt += y;
if ( dt >= numberOfDesktops() )
{
if ( options->rollOverDesktops )
if ( wrap )
dt -= numberOfDesktops();
else
return desktop;
@ -1409,7 +1409,7 @@ int Workspace::desktopToRight( int desktop ) const
int d = (dt % x) + 1;
if ( d >= x )
{
if ( options->rollOverDesktops )
if ( wrap )
d -= x;
else
return desktop;
@ -1419,7 +1419,7 @@ int Workspace::desktopToRight( int desktop ) const
return dt+1;
}
int Workspace::desktopToLeft( int desktop ) const
int Workspace::desktopToLeft( int desktop, bool wrap ) const
{
int x,y;
Qt::Orientation orientation;
@ -1430,7 +1430,7 @@ int Workspace::desktopToLeft( int desktop ) const
dt -= y;
if ( dt < 0 )
{
if ( options->rollOverDesktops )
if ( wrap )
dt += numberOfDesktops();
else
return desktop;
@ -1441,7 +1441,7 @@ int Workspace::desktopToLeft( int desktop ) const
int d = (dt % x) - 1;
if ( d < 0 )
{
if ( options->rollOverDesktops )
if ( wrap )
d += x;
else
return desktop;
@ -1451,7 +1451,7 @@ int Workspace::desktopToLeft( int desktop ) const
return dt+1;
}
int Workspace::desktopUp( int desktop ) const
int Workspace::desktopUp( int desktop, bool wrap ) const
{
int x,y;
Qt::Orientation orientation;
@ -1462,7 +1462,7 @@ int Workspace::desktopUp( int desktop ) const
dt -= x;
if ( dt < 0 )
{
if ( options->rollOverDesktops )
if ( wrap )
dt += numberOfDesktops();
else
return desktop;
@ -1473,7 +1473,7 @@ int Workspace::desktopUp( int desktop ) const
int d = (dt % y) - 1;
if ( d < 0 )
{
if ( options->rollOverDesktops )
if ( wrap )
d += y;
else
return desktop;
@ -1483,7 +1483,7 @@ int Workspace::desktopUp( int desktop ) const
return dt+1;
}
int Workspace::desktopDown( int desktop ) const
int Workspace::desktopDown( int desktop, bool wrap ) const
{
int x,y;
Qt::Orientation orientation;
@ -1494,7 +1494,7 @@ int Workspace::desktopDown( int desktop ) const
dt += x;
if ( dt >= numberOfDesktops() )
{
if ( options->rollOverDesktops )
if ( wrap )
dt -= numberOfDesktops();
else
return desktop;
@ -1505,7 +1505,7 @@ int Workspace::desktopDown( int desktop ) const
int d = (dt % y) + 1;
if ( d >= y )
{
if ( options->rollOverDesktops )
if ( wrap )
d -= y;
else
return desktop;
@ -2237,22 +2237,22 @@ void Workspace::electricBorderSwitchDesktop( ElectricBorder border, const QPoint
const int OFFSET = 2;
if( border == ElectricLeft || border == ElectricTopLeft || border == ElectricBottomLeft )
{
desk = desktopToLeft( desk );
desk = desktopToLeft( desk, options->rollOverDesktops );
pos.setX( displayWidth() - 1 - OFFSET );
}
if( border == ElectricRight || border == ElectricTopRight || border == ElectricBottomRight )
{
desk = desktopToRight( desk );
desk = desktopToRight( desk, options->rollOverDesktops );
pos.setX( OFFSET );
}
if( border == ElectricTop || border == ElectricTopLeft || border == ElectricTopRight )
{
desk = desktopUp( desk );
desk = desktopUp( desk, options->rollOverDesktops );
pos.setY( displayHeight() - 1 - OFFSET );
}
if( border == ElectricBottom || border == ElectricBottomLeft || border == ElectricBottomRight )
{
desk = desktopDown( desk );
desk = desktopDown( desk, options->rollOverDesktops );
pos.setY( OFFSET );
}
int desk_before = currentDesktop();

View File

@ -149,6 +149,10 @@ class Workspace : public QObject, public KDecorationDefines
int numberOfDesktops() const;
void setNumberOfDesktops( int n );
void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const;
int desktopToRight( int desktop, bool wrap ) const;
int desktopToLeft( int desktop, bool wrap ) const;
int desktopUp( int desktop, bool wrap ) const;
int desktopDown( int desktop, bool wrap ) const;
int activeScreen() const;
int numScreens() const;
@ -491,10 +495,6 @@ class Workspace : public QObject, public KDecorationDefines
void oneStepThroughDesktopList( bool forward );
bool establishTabBoxGrab();
void removeTabBoxGrab();
int desktopToRight( int desktop ) const;
int desktopToLeft( int desktop ) const;
int desktopUp( int desktop ) const;
int desktopDown( int desktop ) const;
void updateStackingOrder( bool propagate_new_clients = false );
void propagateClients( bool propagate_new_clients ); // called only from updateStackingOrder