From 9c2fd4530e533d7f13237825be9aa859af67a3fb Mon Sep 17 00:00:00 2001 From: Cristian Tibirna Date: Thu, 25 Nov 1999 23:12:32 +0000 Subject: [PATCH] CT: snap. Thanks to Matthias for the adjustClientPosition(). Clean svn path=/trunk/kdebase/kwin/; revision=35049 --- options.cpp | 5 +++ options.h | 9 +++++ workspace.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/options.cpp b/options.cpp index 4d7130f59a..473ba41086 100644 --- a/options.cpp +++ b/options.cpp @@ -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); + } diff --git a/options.h b/options.h index ad2952e1d4..2894cf9b6d 100644 --- a/options.h +++ b/options.h @@ -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; diff --git a/workspace.cpp b/workspace.cpp index 44394b43ab..2a4c98f777 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -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::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; }