Fix center snapping algorithm for unrestricted moves

Also don't snap when another snap zone is closer

svn path=/trunk/KDE/kdebase/workspace/; revision=837639
icc-effect-5.14.5
Lucas Murray 2008-07-25 10:16:09 +00:00
parent f56fd92540
commit 79a8f87268
2 changed files with 17 additions and 15 deletions

View File

@ -292,7 +292,7 @@ QRect Workspace::clientArea( clientAreaOption opt, const Client* c ) const
workspace the opportunity to interveniate and to implement
snap-to-windows functionality.
*/
QPoint Workspace::adjustClientPosition( Client* c, QPoint pos )
QPoint Workspace::adjustClientPosition( Client* c, QPoint pos, bool unrestricted )
{
//CT 16mar98, 27May98 - magics: BorderSnapZone, WindowSnapZone
//CT adapted for kwin on 25Nov1999
@ -404,7 +404,7 @@ QPoint Workspace::adjustClientPosition( Client* c, QPoint pos )
{
int diffX = qAbs( (xmin + xmax)/2 - (cx + cw/2) );
int diffY = qAbs( (ymin + ymax)/2 - (cy + ch/2) );
if (diffX < snap && diffY < snap)
if (diffX < snap && diffY < snap && diffX < deltaX && diffY < deltaY)
{ // Snap to center of screen
deltaX = diffX;
deltaY = diffY;
@ -413,12 +413,13 @@ QPoint Workspace::adjustClientPosition( Client* c, QPoint pos )
}
else if ( options->borderSnapZone )
{ // Enhance border snap
if( ( nx == xmin || nx == xmax - cw ) && diffY < snap)
if( ( nx == xmin || nx == xmax - cw ) && diffY < snap && diffY < deltaY)
{ // Snap to vertical center on screen edge
deltaY = diffY;
ny = (ymin + ymax)/2 - ch/2;
}
else if ( ( ( ny <= ymin && ny > ymin - snap ) || ny == ymax - ch ) && diffX < snap) // Extra snap on the top of screen to prevent misses
else if ( (( unrestricted ? ny == ymin : ny <= ymin) || ny == ymax - ch ) &&
diffX < snap && diffX < deltaX)
{ // Snap to horizontal center on screen edge
deltaX = diffX;
nx = (xmin + xmax)/2 - cw/2;
@ -2693,7 +2694,8 @@ void Client::handleMoveResize( int x, int y, int x_root, int y_root )
assert( mode == PositionCenter );
// first move, then snap, then check bounds
moveResizeGeom.moveTopLeft( topleft );
moveResizeGeom.moveTopLeft( workspace()->adjustClientPosition( this, moveResizeGeom.topLeft() ) );
moveResizeGeom.moveTopLeft( workspace()->adjustClientPosition( this, moveResizeGeom.topLeft(),
unrestrictedMoveResize ) );
// NOTE: This is duped in checkUnrestrictedMoveResize().
if( moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1 ) // titlebar mustn't go out
moveResizeGeom.moveBottom( desktopArea.top() + titlebar_marge - 1 );

View File

@ -127,7 +127,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 );
QPoint adjustClientPosition( Client* c, QPoint pos, bool unrestricted );
QRect adjustClientSize( Client* c, QRect moveResizeGeom, int mode );
void raiseClient( Client* c, bool nogroup = false );
void lowerClient( Client* c, bool nogroup = false );