+ // Maybe this should be saved in the class, and set in the setWorkspace
+ // function!!
+ Workspace *w = screen->getWorkspace(getWorkspaceNumber());
+ assert(w);
+
+ // try snap to another window
+ for (unsigned int i = 0, c = w->getCount(); i < c; ++i) {
+ BlackboxWindow *snapwin = w->getWindow(i);
+ if (snapwin == this)
+ continue; // don't snap to self
+
+ const Rect &winrect = snapwin->frameRect();
+ int dleft = std::abs(wright - winrect.left()),
+ dright = std::abs(wleft - winrect.right()),
+ dtop = std::abs(wbottom - winrect.top()),
+ dbottom = std::abs(wtop - winrect.bottom());
+
+ // snap left?
+ if (dleft < snap_distance && dleft <= dright) {
+ dx = winrect.left() - frame.rect.width();
+ continue;
+ }
+ // snap right?
+ else if (dright < snap_distance) {
+ dx = winrect.right() + 1;
+ continue;
+ }
+
+ // snap top?
+ if (dtop < snap_distance && dtop <= dbottom) {
+ dy = winrect.top() - frame.rect.height();
+ continue;
+ }
+ // snap bottom?
+ else if (dbottom < snap_distance) {
+ dy = winrect.bottom() + 1;
+ continue;
+ }
+ }
+
+ // try snap to the screen's available area
+ Rect srect = screen->availableArea();
+