CT: snap. Thanks to Matthias for the adjustClientPosition(). Clean
svn path=/trunk/kdebase/kwin/; revision=35049
This commit is contained in:
parent
d6c573987e
commit
9c2fd4530e
3 changed files with 107 additions and 1 deletions
|
@ -17,6 +17,7 @@ Options::Options()
|
|||
placement = Smart;
|
||||
animate_shade = true;
|
||||
anim_steps = 100;
|
||||
border_snap_zone = window_snap_zone = 10;
|
||||
|
||||
connect( kapp, SIGNAL( appearanceChanged() ), this, SLOT(reload() ) );
|
||||
}
|
||||
|
@ -154,4 +155,8 @@ void Options::reload()
|
|||
animate_shade = config->readBoolEntry("AnimateShade", true);
|
||||
|
||||
anim_steps = config->readNumEntry("AnimSteps", 100);
|
||||
|
||||
border_snap_zone = config->readNumEntry("BorderSnapZone", 10);
|
||||
window_snap_zone = config->readNumEntry("WindowSnapZone", 10);
|
||||
|
||||
}
|
||||
|
|
|
@ -90,6 +90,14 @@ public:
|
|||
* Return the number of animation steps (would this be general?)
|
||||
*/
|
||||
const int animSteps() { return anim_steps; };
|
||||
/**
|
||||
* Return the size of the zone that triggers snapping on desktop borders
|
||||
*/
|
||||
const int borderSnapZone() { return border_snap_zone; };
|
||||
/**
|
||||
* Return the number of animation steps (would this be general?)
|
||||
*/
|
||||
const int windowSnapZone() { return window_snap_zone; };
|
||||
|
||||
public slots:
|
||||
void reload();
|
||||
|
@ -102,6 +110,7 @@ protected:
|
|||
private:
|
||||
bool animate_shade;
|
||||
int anim_steps;
|
||||
int border_snap_zone, window_snap_zone;
|
||||
};
|
||||
|
||||
extern Options* options;
|
||||
|
|
|
@ -1550,5 +1550,97 @@ void Workspace::slotWindowClose()
|
|||
*/
|
||||
QPoint Workspace::adjustClientPosition( Client* c, QPoint pos )
|
||||
{
|
||||
return pos;
|
||||
//CT 16mar98, 27May98 - magics: BorderSnapZone, WindowSnapZone
|
||||
//CT adapted for kwin on 25Nov1999
|
||||
if (options->windowSnapZone() || options->borderSnapZone()) {
|
||||
|
||||
int snap; //snap trigger
|
||||
|
||||
QRect maxRect = clientArea();
|
||||
int xmin = maxRect.left();
|
||||
int xmax = maxRect.right(); //desk size
|
||||
int ymin = maxRect.top();
|
||||
int ymax = maxRect.bottom();
|
||||
int cx, cy, rx, ry, cw, ch; //these don't change
|
||||
|
||||
int nx, ny; //buffers
|
||||
int deltaX = xmax, deltaY = ymax; //minimum distance to other clients
|
||||
|
||||
int lx, ly, lrx, lry; //coords and size for the comparison client, l
|
||||
|
||||
nx = cx = pos.x();
|
||||
ny = cy = pos.y();
|
||||
rx = cx + (cw = c->width());
|
||||
ry = cy + (ch = c->height());
|
||||
|
||||
// border snap
|
||||
snap = options->borderSnapZone();
|
||||
if (snap) {
|
||||
if ( QABS(cx-xmin) < snap ){
|
||||
deltaX = QABS(cx - xmin);
|
||||
nx = xmin;
|
||||
}
|
||||
if ((QABS(xmax-rx) < snap) && (QABS(xmax-rx) < deltaX)) {
|
||||
deltaX = abs(xmax-rx);
|
||||
nx = xmax - cw;
|
||||
}
|
||||
|
||||
if ( QABS(cy-ymin) < snap ){
|
||||
deltaY = QABS(cy-ymin);
|
||||
ny = ymin;
|
||||
}
|
||||
if ((QABS(ymax-ry) < snap) && (QABS(ymax-ry) < deltaY)) {
|
||||
deltaY = QABS(ymax-ry);
|
||||
ny = ymax - ch;
|
||||
}
|
||||
}
|
||||
|
||||
// windows snap
|
||||
snap = options->windowSnapZone();
|
||||
if (snap) {
|
||||
QValueList<Client *>::ConstIterator l;
|
||||
for (l = clients.begin();l != clients.end();++l ) {
|
||||
if((*l)->isOnDesktop(currentDesktop()) && (*l) != desktop_client &&
|
||||
!(*l)->isIconified() && (*l)->transientFor() == None &&
|
||||
(*l) != c ) {
|
||||
lx = (*l)->x();
|
||||
ly = (*l)->y();
|
||||
lrx = lx + (*l)->width();
|
||||
lry = ly + (*l)->height();
|
||||
|
||||
if( ( ( cy <= lry ) && ( cy >= ly ) ) ||
|
||||
( ( ry >= ly ) && ( ry <= lry ) ) ||
|
||||
( ( ly >= cy ) && ( lry <= ry ) ) ) {
|
||||
if ( ( QABS( lrx - cx ) < snap ) &&
|
||||
( QABS( lrx -cx ) < deltaX ) ) {
|
||||
deltaX = QABS( lrx - cx );
|
||||
nx = lrx;
|
||||
}
|
||||
if ( ( QABS( rx - lx ) < snap ) &&
|
||||
( QABS( rx - lx ) < deltaX ) ) {
|
||||
deltaX = abs(rx - lx);
|
||||
nx = lx - cw;
|
||||
}
|
||||
}
|
||||
|
||||
if( ( ( cx <= lrx ) && ( cx >= lx ) ) ||
|
||||
( ( rx >= lx ) && ( rx <= lrx ) ) ||
|
||||
( ( lx >= cx ) && ( lrx <= rx ) ) ) {
|
||||
if ( ( QABS( lry - cy ) < snap ) &&
|
||||
( QABS( lry -cy ) < deltaY ) ) {
|
||||
deltaY = QABS( lry - cy );
|
||||
ny = lry;
|
||||
}
|
||||
if ( ( QABS( ry-ly ) < snap ) &&
|
||||
( QABS( ry - ly ) < deltaY ) ) {
|
||||
deltaY = QABS( ry - ly );
|
||||
ny = ly - ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pos = QPoint(nx, ny);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue