- cout << "space: x: " << space.x() << " y: " << space.y() << " w: " << space.w() << " h: " << space.h() << endl;
-
- const int win_w = win->size().w() + (screen.getBorderWidth() * 4),
- win_h = win->size().h() + (screen.getBorderWidth() * 4),
- start_pos = 0,
- change_y =
- ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1),
- change_x =
- ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1),
- delta_x = 8, delta_y = 8;
-
- LinkedListIterator<OpenboxWindow> it(windowList);
-
- Size window_size(win->size().w()+screen.getBorderWidth() * 4,
- win->size().h()+screen.getBorderWidth() * 4);
- Point *place = NULL;
-
- switch (screen.placementPolicy()) {
- case BScreen::BestFitPlacement:
- place = bestFitPlacement(window_size, space);
- break;
+
+ if (sit == spaces_end)
+ return False;
+
+ //set new position based on the empty space found
+ const Rect& where = *sit;
+ win.setX(where.x());
+ win.setY(where.y());
+
+ // adjust the location() based on left/right and top/bottom placement
+ if (screen->getPlacementPolicy() == BScreen::RowSmartPlacement) {
+ if (screen->getRowPlacementDirection() == BScreen::RightLeft)
+ win.setX(where.right() - win.width());
+ if (screen->getColPlacementDirection() == BScreen::BottomTop)
+ win.setY(where.bottom() - win.height());
+ } else {
+ if (screen->getColPlacementDirection() == BScreen::BottomTop)
+ win.setY(win.y() + where.height() - win.height());
+ if (screen->getRowPlacementDirection() == BScreen::RightLeft)
+ win.setX(win.x() + where.width() - win.width());
+ }
+ return True;
+}
+
+
+bool Workspace::underMousePlacement(Rect &win) {
+ int x, y, rx, ry;
+ Window c, r;
+ unsigned int m;
+ XQueryPointer(screen->getBlackbox()->getXDisplay(), screen->getRootWindow(),
+ &r, &c, &rx, &ry, &x, &y, &m);
+
+ Rect area;
+#ifdef XINERAMA
+ if (screen->isXineramaActive() &&
+ screen->getBlackbox()->doXineramaPlacement()) {
+ RectList availableAreas = screen->allAvailableAreas();
+ RectList::iterator it, end = availableAreas.end();
+
+ for (it = availableAreas.begin(); it != end; ++it)
+ if (it->contains(rx, ry)) break;
+ assert(it != end); // the mouse isn't inside an area?
+ area = *it;
+ } else
+#endif // XINERAMA
+ area = screen->availableArea();
+
+ x = rx - win.width() / 2;
+ y = ry - win.height() / 2;
+
+ if (x < area.x())
+ x = area.x();
+ if (y < area.y())
+ y = area.y();
+ if (x + win.width() > area.x() + area.width())
+ x = area.x() + area.width() - win.width();
+ if (y + win.height() > area.y() + area.height())
+ y = area.y() + area.height() - win.height();
+
+ win.setX(x);
+ win.setY(y);
+
+ return True;
+}
+
+
+bool Workspace::cascadePlacement(Rect &win, const int offset) {
+ Rect area;
+
+#ifdef XINERAMA
+ if (screen->isXineramaActive() &&
+ screen->getBlackbox()->doXineramaPlacement()) {
+ area = screen->allAvailableAreas()[cascade_region];
+ } else
+#endif // XINERAMA
+ area = screen->availableArea();
+
+ if ((static_cast<signed>(cascade_x + win.width()) > area.right() + 1) ||
+ (static_cast<signed>(cascade_y + win.height()) > area.bottom() + 1)) {
+ cascade_x = cascade_y = 0;
+#ifdef XINERAMA
+ if (screen->isXineramaActive() &&
+ screen->getBlackbox()->doXineramaPlacement()) {
+ // go to the next xinerama region, and use its area
+ if (++cascade_region >= screen->allAvailableAreas().size())
+ cascade_region = 0;
+ area = screen->allAvailableAreas()[cascade_region];
+ }
+#endif // XINERAMA
+ }
+
+ if (cascade_x == 0) {
+ cascade_x = area.x() + offset;
+ cascade_y = area.y() + offset;
+ }
+
+ win.setPos(cascade_x, cascade_y);
+
+ cascade_x += offset;
+ cascade_y += offset;
+
+ return True;
+}
+
+
+void Workspace::placeWindow(BlackboxWindow *win) {
+ Rect new_win(0, 0, win->frameRect().width(), win->frameRect().height());
+ bool placed = False;
+
+ switch (screen->getPlacementPolicy()) {