- test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ?
- start_pos : screen.size().w() - win_size.w() - start_pos;
-
- while(!placed &&
- ((screen.rowPlacementDirection() == BScreen::RightLeft) ?
- test_x > 0 : test_x + win_size.w() < (signed) space.w())) {
- 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())){
-
- 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 checking for intersection with Toolbar and Slit
- // The space passed to this method should not include either
-
- if (placed) {
- pt= new Point(test_x,test_y);
-
- break;
- }
-
- test_y += (change_y * delta_y);
+ rectList::const_iterator siter;
+ spaces.push_back(space); //initially the entire screen is free
+ it.reset();
+
+ //Find Free Spaces
+ for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
+ spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
+ spaces);
+ //Sort spaces by user preference
+ if(screen.colPlacementDirection() == BScreen::TopBottom)
+ if(screen.rowPlacementDirection() == BScreen::LeftRight)
+ sort(spaces.begin(),spaces.end(),colLRTB);
+ else
+ sort(spaces.begin(),spaces.end(),colRLTB);
+ else
+ if(screen.rowPlacementDirection() == BScreen::LeftRight)
+ sort(spaces.begin(),spaces.end(),colLRBT);
+ else
+ sort(spaces.begin(),spaces.end(),colRLBT);
+ fprintf(stderr,"Spaces after sorting\n");
+ for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
+ fprintf(stderr,"space(%d,%d)(%d,%d)\n",siter->x(),siter->y(),
+ siter->x()+siter->w(),siter->y()+siter->h());
+ //Find first space that fits the window
+ best = NULL;
+ for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
+ if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
+ best = siter;
+ break;