+ //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, const Rect &availableArea) {
+ int x, y, rx, ry;
+ Window c, r;
+ unsigned int m;
+ XQueryPointer(screen->getBlackbox()->getXDisplay(), screen->getRootWindow(),
+ &r, &c, &rx, &ry, &x, &y, &m);
+ x = rx - win.width() / 2;
+ y = ry - win.height() / 2;
+
+ if (x < availableArea.x())
+ x = availableArea.x();
+ if (y < availableArea.y())
+ y = availableArea.y();
+ if (x + win.width() > availableArea.x() + availableArea.width())
+ x = availableArea.x() + availableArea.width() - win.width();
+ if (y + win.height() > availableArea.y() + availableArea.height())
+ y = availableArea.y() + availableArea.height() - win.height();
+
+ win.setX(x);
+ win.setY(y);
+
+ return True;
+}
+
+
+bool Workspace::cascadePlacement(Rect &win, const Rect &availableArea) {
+ if ((cascade_x > static_cast<signed>(availableArea.width() / 2)) ||
+ (cascade_y > static_cast<signed>(availableArea.height() / 2)))
+ cascade_x = cascade_y = 32;
+
+ if (cascade_x == 32) {
+ cascade_x += availableArea.x();
+ cascade_y += availableArea.y();
+ }
+
+ win.setPos(cascade_x, cascade_y);
+
+ return True;
+}
+
+
+void Workspace::placeWindow(BlackboxWindow *win) {
+ Rect availableArea(screen->availableArea()),
+ new_win(availableArea.x(), availableArea.y(),
+ win->frameRect().width(), win->frameRect().height());
+ bool placed = False;
+
+ switch (screen->getPlacementPolicy()) {
+ case BScreen::RowSmartPlacement:
+ case BScreen::ColSmartPlacement:
+ placed = smartPlacement(new_win, availableArea);
+ break;
+ case BScreen::UnderMousePlacement:
+ placed = underMousePlacement(new_win, availableArea);
+ default:
+ break; // handled below
+ } // switch