Add window snapping to the desktop grid effect.

Patch by Caio Marcelo de Oliveira Filho.
FEATURE: 188743

svn path=/trunk/KDE/kdebase/workspace/; revision=1031428
This commit is contained in:
Lucas Murray 2009-10-05 04:06:20 +00:00
parent b5da07a822
commit ca9df8caae
6 changed files with 24 additions and 13 deletions

View file

@ -409,10 +409,15 @@ EffectWindow* EffectsHandlerImpl::activeWindow() const
return Workspace::self()->activeClient() ? Workspace::self()->activeClient()->effectWindow() : NULL;
}
void EffectsHandlerImpl::moveWindow( EffectWindow* w, const QPoint& pos )
void EffectsHandlerImpl::moveWindow( EffectWindow* w, const QPoint& pos, bool snap, double snapAdjust )
{
Client* cl = dynamic_cast< Client* >( static_cast<EffectWindowImpl*>(w)->window());
if( cl && cl->isMovable())
if (!cl || !cl->isMovable())
return;
if (snap)
cl->move(Workspace::self()->adjustClientPosition(cl, pos, true, snapAdjust));
else
cl->move( pos );
}

View file

@ -53,7 +53,7 @@ class EffectsHandlerImpl : public EffectsHandler
virtual void activateWindow( EffectWindow* c );
virtual EffectWindow* activeWindow() const;
virtual void moveWindow( EffectWindow* w, const QPoint& pos );
virtual void moveWindow( EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0 );
virtual void windowToDesktop( EffectWindow* w, int desktop );
virtual void setShowingDesktop( bool showing );

View file

@ -329,8 +329,10 @@ void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
effects->activateWindow( windowMove );
wasWindowMove = true;
if( windowMove->isMovable() )
effects->moveWindow( windowMove, unscalePos( me->pos(), NULL ) + windowMoveDiff );
// TODO: Window snap
{
int screen = effects->screenNumber( me->pos() );
effects->moveWindow( windowMove, unscalePos( me->pos(), NULL ) + windowMoveDiff, true, 1.0 / scale[screen] );
}
if( d != highlightedDesktop && !windowMove->isOnAllDesktops() )
effects->windowToDesktop( windowMove, d ); // Not true all desktop move
}

View file

@ -334,8 +334,12 @@ QRegion Workspace::previousRestrictedMoveArea( int desktop, StrutAreas areas ) c
Client \a c is moved around to position \a pos. This gives the
workspace the opportunity to interveniate and to implement
snap-to-windows functionality.
The parameter \a snapAdjust is a multiplier used to calculate the
effective snap zones. When 1.0, it means that the snap zones will be
used without change.
*/
QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted )
QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted, double snapAdjust )
{
//CT 16mar98, 27May98 - magics: BorderSnapZone, WindowSnapZone
//CT adapted for kwin on 25Nov1999
@ -363,7 +367,7 @@ QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted
int lx, ly, lrx, lry; //coords and size for the comparison client, l
// border snap
int snap = options->borderSnapZone; //snap trigger
int snap = options->borderSnapZone * snapAdjust; //snap trigger
if (snap)
{
if ((sOWO?(cx<xmin):true) && (qAbs(xmin-cx)<snap))
@ -390,13 +394,13 @@ QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted
}
// windows snap
snap = options->windowSnapZone;
snap = options->windowSnapZone * snapAdjust;
if (snap)
{
QList<Client *>::ConstIterator l;
for (l = clients.constBegin();l != clients.constEnd();++l )
{
if ((*l)->isOnDesktop(currentDesktop()) &&
if ((*l)->isOnDesktop(c->desktop()) &&
!(*l)->isMinimized()
&& (*l) != c )
{
@ -470,7 +474,7 @@ QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted
}
// center snap
snap = options->centerSnapZone; //snap trigger
snap = options->centerSnapZone * snapAdjust; //snap trigger
if (snap)
{
int diffX = qAbs( (xmin + xmax)/2 - (cx + cw/2) );

View file

@ -170,7 +170,7 @@ X-KDE-Library=kwin4_effect_cooleffect
#define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
#define KWIN_EFFECT_API_VERSION_MAJOR 0
#define KWIN_EFFECT_API_VERSION_MINOR 103
#define KWIN_EFFECT_API_VERSION_MINOR 104
#define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
@ -555,7 +555,7 @@ class KWIN_EXPORT EffectsHandler
// functions that allow controlling windows/desktop
virtual void activateWindow( EffectWindow* c ) = 0;
virtual EffectWindow* activeWindow() const = 0 ;
virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
virtual void moveWindow( EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0 ) = 0;
virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
virtual void setShowingDesktop( bool showing ) = 0;

View file

@ -144,7 +144,7 @@ class Workspace : public QObject, public KDecorationDefines
void place( Client* c, QRect& area );
void placeSmart( Client* c, const QRect& area );
QPoint adjustClientPosition( Client* c, QPoint pos, bool unrestricted );
QPoint adjustClientPosition( Client* c, QPoint pos, bool unrestricted, double snapAdjust = 1.0 );
QRect adjustClientSize( Client* c, QRect moveResizeGeom, int mode );
void raiseClient( Client* c, bool nogroup = false );
void lowerClient( Client* c, bool nogroup = false );