- pt = new Point(rx - win_size.w() / 2, ry - win_size.h() / 2);
-
- if (pt->x() < space.x())
- pt->setX(space.x());
- if (pt->y() < space.y())
- pt->setY(space.y());
- if (pt->x() + win_size.w() > space.x() + space.w())
- pt->setX(space.x() + space.w() - win_size.w());
- if (pt->y() + win_size.h() > space.y() + space.h())
- pt->setY(space.y() + space.h() - win_size.h());
- return pt;
-}
-
-Point *Workspace::rowSmartPlacement(const Size &win_size, const Rect &space) {
- bool placed=false;
- int test_x, test_y, place_x = 0, place_y = 0;
- int start_pos = 0;
- int change_y =
- ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1);
- int change_x =
- ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1);
- int delta_x = 8, delta_y = 8;
- LinkedListIterator<OpenboxWindow> it(windowList);
-
- test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ?
- start_pos : screen.size().h() - win_size.h() - start_pos;
-
- while(!placed &&
- ((screen.colPlacementDirection() == BScreen::BottomTop) ?
- test_y > 0 : test_y + win_size.h() < (signed) space.h())) {
- test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ?
- start_pos : space.w() - win_size.w() - start_pos;
- while (!placed &&
- ((screen.rowPlacementDirection() == BScreen::RightLeft) ?
- test_x > 0 : test_x + win_size.w() < (signed) space.w())) {
- placed = true;
-
- it.reset();
- for (OpenboxWindow *curr = it.current(); placed && curr;
- it++, curr = it.current()) {
- int curr_w = curr->area().w() + (screen.getBorderWidth() * 4);
- int curr_h = curr->area().h() + (screen.getBorderWidth() * 4);
-
- if (curr->area().x() < test_x + win_size.w() &&
- curr->area().x() + curr_w > test_x &&
- curr->area().y() < test_y + win_size.h() &&
- curr->area().y() + curr_h > test_y) {
- placed = false;
- }
- }
-
- // Removed code for checking toolbar and slit
- // The space passed in should not include either
-
- if (placed) {
- place_x = test_x;
- place_y = test_y;
-
- break;
- }
-
- test_x += (change_x * delta_x);
- }
+ 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;
+}