+
+
+void Workspace::placeWindow(OpenboxWindow *win) {
+ ASSERT(win != NULL);
+
+ // the following code is temporary and will be taken care of by Screen in the
+ // future (with the NETWM 'strut')
+ Rect space(0, 0, screen.size().w(), screen.size().h());
+
+#ifdef SLIT
+ Slit *slit = screen.getSlit();
+ int remove; // 0 - top/2 - right/2 - bottom/3 - left
+ if ((slit->direction() == Slit::Horizontal &&
+ (slit->placement() == Slit::TopLeft ||
+ slit->placement() == Slit::TopRight)) ||
+ slit->placement() == Slit::TopCenter)
+ // exclude top
+ space.setY(slit->area().h() + screen.getBorderWidth() * 2);
+ else if ((slit->direction() == Slit::Vertical &&
+ (slit->placement() == Slit::TopRight ||
+ slit->placement() == Slit::BottomRight)) ||
+ slit->placement() == Slit::CenterRight)
+ // exclude right
+ space.setW(screen.size().w() -
+ (slit->area().w() + screen.getBorderWidth() * 2));
+ else if ((slit->direction() == Slit::Horizontal &&
+ (slit->placement() == Slit::BottomLeft ||
+ slit->placement() == Slit::BottomRight)) ||
+ slit->placement() == Slit::TopCenter)
+ // exclude bottom
+ space.setH(screen.size().h() -
+ (slit->area().h() + screen.getBorderWidth() * 2));
+ else// if ((slit->direction() == Slit::Vertical &&
+ // (slit->placement() == Slit::TopLeft ||
+ // slit->placement() == Slit::BottomLeft)) ||
+ // slit->placement() == Slit::CenterLeft)
+ // exclude left
+ space.setX(slit->area().w() + screen.getBorderWidth() * 2);
+#endif
+
+ Toolbar *toolbar = screen.getToolbar();
+ int tbarh = screen.hideToolbar() ? 0 :
+ toolbar->getExposedHeight() + screen.getBorderWidth() * 2;
+ switch (toolbar->placement()) {
+ case Toolbar::TopLeft:
+ case Toolbar::TopCenter:
+ case Toolbar::TopRight:
+ if (tbarh > space.y())
+ space.setY(toolbar->getExposedHeight());
+ break;
+ case Toolbar::BottomLeft:
+ case Toolbar::BottomCenter:
+ case Toolbar::BottomRight:
+ if (screen.size().h() - tbarh < space.h())
+ space.setH(screen.size().h() - tbarh);
+ break;
+ default:
+ ASSERT(false); // unhandled placement
+ }
+
+ const int win_w = win->size().w() + (screen.getBorderWidth() * 4),
+ win_h = win->size().h() + (screen.getBorderWidth() * 4),
+ start_pos = 0,
+ change_y =
+ ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1),
+ change_x =
+ ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1),
+ delta_x = 8, delta_y = 8;
+
+ LinkedListIterator<OpenboxWindow> it(windowList);
+
+ Size window_size(win->size().w()+screen.getBorderWidth() * 4,
+ win->size().h()+screen.getBorderWidth() * 4);
+ Point *place = NULL;
+
+ switch (screen.placementPolicy()) {
+ case BScreen::BestFitPlacement:
+ place = bestFitPlacement(window_size, space);
+ break;
+ case BScreen::RowSmartPlacement:
+ place = rowSmartPlacement(window_size, space);
+ break;
+ case BScreen::ColSmartPlacement:
+ place = colSmartPlacement(window_size, space);
+ break;
+ } // switch
+
+ if (place == NULL)
+ place = cascadePlacement(win);
+
+ ASSERT(place != NULL);
+ if (place->x() + win_w > (signed) screen.size().w())
+ place->setX(((signed) screen.size().w() - win_w) / 2);
+ if (place->y() + win_h > (signed) screen.size().h())
+ place->setY(((signed) screen.size().h() - win_h) / 2);
+
+ win->configure(place->x(), place->y(), win->size().w(), win->size().h());
+ delete place;
+}