- // try snap to the screen's available area
- Rect srect = screen->availableArea();
-
- int dleft = std::abs(wleft - srect.left()),
- dright = std::abs(wright - srect.right()),
- dtop = std::abs(wtop - srect.top()),
- dbottom = std::abs(wbottom - srect.bottom());
-
- // snap left?
- if (dleft < snap_distance && dleft <= dright)
- dx = srect.left();
- // snap right?
- else if (dright < snap_distance)
- dx = srect.right() - frame.rect.width() + 1;
-
- // snap top?
- if (dtop < snap_distance && dtop <= dbottom)
- dy = srect.top();
- // snap bottom?
- else if (dbottom < snap_distance)
- dy = srect.bottom() - frame.rect.height() + 1;
-
- srect = screen->getRect(); // now get the full screen
-
- dleft = std::abs(wleft - srect.left()),
- dright = std::abs(wright - srect.right()),
- dtop = std::abs(wtop - srect.top()),
- dbottom = std::abs(wbottom - srect.bottom());
-
- // snap left?
- if (dleft < snap_distance && dleft <= dright)
- dx = srect.left();
- // snap right?
- else if (dright < snap_distance)
- dx = srect.right() - frame.rect.width() + 1;
-
- // snap top?
- if (dtop < snap_distance && dtop <= dbottom)
- dy = srect.top();
- // snap bottom?
- else if (dbottom < snap_distance)
- dy = srect.bottom() - frame.rect.height() + 1;
+ RectList snaplist; // the list of rects we will try to snap to
+
+ // snap to the strut (and screen boundaries for xinerama)
+#ifdef XINERAMA
+ if (screen->isXineramaActive() && blackbox->doXineramaSnapping()) {
+ if (! screen->doFullMax())
+ snaplist.insert(snaplist.begin(),
+ screen->allAvailableAreas().begin(),
+ screen->allAvailableAreas().end());
+
+ // always snap to the screen edges
+ snaplist.insert(snaplist.begin(),
+ screen->getXineramaAreas().begin(),
+ screen->getXineramaAreas().end());
+ } else
+#endif // XINERAMA
+ {
+ if (! screen->doFullMax())
+ snaplist.push_back(screen->availableArea());
+
+ // always snap to the screen edges
+ snaplist.push_back(screen->getRect());
+ }
+
+ RectList::const_iterator it, end = snaplist.end();
+ for (it = snaplist.begin(); it != end; ++it) {
+ const Rect &srect = *it;
+
+ // if we're not in the rectangle then don't snap to it.
+ if (! srect.intersects(Rect(wleft, wtop, frame.rect.width(),
+ frame.rect.height())))
+ continue;
+
+ int dleft = std::abs(wleft - srect.left()),
+ dright = std::abs(wright - srect.right()),
+ dtop = std::abs(wtop - srect.top()),
+ dbottom = std::abs(wbottom - srect.bottom());
+
+ // snap left?
+ if (dleft < snap_distance && dleft <= dright)
+ dx = srect.left();
+ // snap right?
+ else if (dright < snap_distance)
+ dx = srect.right() - frame.rect.width() + 1;
+
+ // snap top?
+ if (dtop < snap_distance && dtop <= dbottom)
+ dy = srect.top();
+ // snap bottom?
+ else if (dbottom < snap_distance)
+ dy = srect.bottom() - frame.rect.height() + 1;
+ }