- test_y += (change_y * delta_y);
- }
- return new Point(place_x, place_y);
-}
-
-void Workspace::placeWindow(OpenboxWindow *win) {
- ASSERT(win != NULL);
-
- Bool placed = False;
-
- const int win_w = win->size().w() + (screen.getBorderWidth() * 4),
- win_h = win->size().h() + (screen.getBorderWidth() * 4),
-#ifdef SLIT
- slit_x = screen.getSlit()->area().x() - screen.getBorderWidth(),
- slit_y = screen.getSlit()->area().y() - screen.getBorderWidth(),
- slit_w = screen.getSlit()->area().w() +
- (screen.getBorderWidth() * 4),
- slit_h = screen.getSlit()->area().h() +
- (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);
-
- Rect space(0, 0,
- screen.size().w(),
- screen.size().h()
- );
- Size window_size(win_w, win_h);
-
- switch (screen.getPlacementPolicy()) {
- case BScreen::BestFitPlacement: {
- Point *spot = bestFitPlacement(window_size, space);
- if (spot != NULL) {
- place_x=spot->x();
- place_y=spot->y();
- delete spot;
- placed=true;
- }
- break;
- }
- case BScreen::RowSmartPlacement: {
- Point *spot=rowSmartPlacement(window_size, space);
- if (spot != NULL) {
- place_x=spot->x();
- place_y=spot->y();
- delete spot;
- placed=true;
+ if (best != NULL) {
+ Point *pt = new Point(best->origin());
+ if (screen.colPlacementDirection() != BScreen::TopBottom)
+ pt->setY(best->y() + best->h() - win_size.h());
+ if (screen.rowPlacementDirection() != BScreen::LeftRight)
+ pt->setX(best->x()+best->w()-win_size.w());
+ return pt;
+ } else
+ return NULL; //fall back to cascade
+}
+
+Point *Workspace::colSmartPlacement(const Size &win_size, const Rect &space) {
+ const Rect *best;
+ rectList spaces;
+
+ rectList::const_iterator siter;
+ spaces.push_back(space); //initially the entire screen is free
+
+ //Find Free Spaces
+ winVect::iterator it;
+ for (it = _windows.begin(); it != _windows.end(); ++it)
+ spaces = calcSpace((*it)->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);
+
+ //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;