-void Workspace::placeWindow(OpenboxWindow *win) {
- Bool placed = False;
-
- const int win_w = win->getWidth() + (screen->getBorderWidth() * 4),
- win_h = win->getHeight() + (screen->getBorderWidth() * 4),
-#ifdef SLIT
- slit_x = screen->getSlit()->getX() - screen->getBorderWidth(),
- slit_y = screen->getSlit()->getY() - screen->getBorderWidth(),
- slit_w = screen->getSlit()->getWidth() +
- (screen->getBorderWidth() * 4),
- slit_h = screen->getSlit()->getHeight() +
- (screen->getBorderWidth() * 4),
-#endif // SLIT
- toolbar_x = screen->getToolbar()->getX() - screen->getBorderWidth(),
- toolbar_y = screen->getToolbar()->getY() - screen->getBorderWidth(),
- toolbar_w = screen->getToolbar()->getWidth() +
- (screen->getBorderWidth() * 4),
- toolbar_h = screen->getToolbar()->getHeight() +
- (screen->getBorderWidth() * 4),
- start_pos = 0,
- change_y =
- ((screen->getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1),
- change_x =
- ((screen->getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1),
- delta_x = 8, delta_y = 8;
-
- int test_x, test_y, place_x = 0, place_y = 0;
- LinkedListIterator<OpenboxWindow> it(windowList);
-
- switch (screen->getPlacementPolicy()) {
- case BScreen::RowSmartPlacement: {
- test_y = (screen->getColPlacementDirection() == BScreen::TopBottom) ?
- start_pos : screen->getHeight() - win_h - start_pos;
-
- while (!placed &&
- ((screen->getColPlacementDirection() == BScreen::BottomTop) ?
- test_y > 0 : test_y + win_h < (signed) screen->getHeight())) {
- test_x = (screen->getRowPlacementDirection() == BScreen::LeftRight) ?
- start_pos : screen->getWidth() - win_w - start_pos;
-
- while (!placed &&
- ((screen->getRowPlacementDirection() == BScreen::RightLeft) ?
- test_x > 0 : test_x + win_w < (signed) screen->getWidth())) {
- placed = True;
-
- it.reset();
- for (OpenboxWindow *curr = it.current(); placed && curr;
- it++, curr = it.current()) {
- if (curr->isMaximizedFull()) // fully maximized, ignore it
- continue;
- int curr_w = curr->getWidth() + (screen->getBorderWidth() * 4);
- int curr_h =
- ((curr->isShaded()) ? curr->getTitleHeight() : curr->getHeight()) +
- (screen->getBorderWidth() * 4);
-
- if (curr->getXFrame() < test_x + win_w &&
- curr->getXFrame() + curr_w > test_x &&
- curr->getYFrame() < test_y + win_h &&
- curr->getYFrame() + curr_h > test_y) {
- placed = False;
- }
- }
-
- if (placed &&
- (toolbar_x < test_x + win_w &&
- toolbar_x + toolbar_w > test_x &&
- toolbar_y < test_y + win_h &&
- toolbar_y + toolbar_h > test_y)
-#ifdef SLIT
- ||
- (slit_x < test_x + win_w &&
- slit_x + slit_w > test_x &&
- slit_y < test_y + win_h &&
- slit_y + slit_h > test_y)
-#endif // SLIT
- )
- placed = False;
-
- if (placed) {
- place_x = test_x;
- place_y = test_y;
-
- break;
- }
-
- test_x += (change_x * delta_x);
- }
-
- test_y += (change_y * delta_y);
+static rectList calcSpace(const Rect &win, const rectList &spaces) {
+ rectList result;
+ rectList::const_iterator siter;
+ for(siter=spaces.begin(); siter!=spaces.end(); ++siter) {
+ if(win.Intersect(*siter)) {
+ //Check for space to the left of the window
+ if(win.x() > siter->x())
+ result.push_back(Rect(siter->x(), siter->y(),
+ win.x() - siter->x() - 1,
+ siter->h()));
+ //Check for space above the window
+ if(win.y() > siter->y())
+ result.push_back(Rect(siter->x(), siter->y(),
+ siter->w(),
+ win.y() - siter->y() - 1));
+ //Check for space to the right of the window
+ if((win.x()+win.w()) <
+ (siter->x()+siter->w()))
+ result.push_back(Rect(win.x() + win.w() + 1,
+ siter->y(),
+ siter->x() + siter->w() -
+ win.x() - win.w() - 1,
+ siter->h()));
+ //Check for space below the window
+ if((win.y()+win.h()) <
+ (siter->y()+siter->h()))
+ result.push_back(Rect(siter->x(),
+ win.y() + win.h() + 1,
+ siter->w(),
+ siter->y() + siter->h()-
+ win.y() - win.h() - 1));
+