X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2FWorkspace.cc;h=b0cafdfb5c6036c7f95bb5d772f4315eb8d81da0;hb=3f6f897d88d820a7a7e8b388aff12c8d56f96fa4;hp=9c44d7977780a1bb205f3135adce3deff5a7d248;hpb=251dd4034f3a3f11a190c06d7b69670dc87d219d;p=chaz%2Fopenbox diff --git a/src/Workspace.cc b/src/Workspace.cc index 9c44d797..b0cafdfb 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -59,6 +59,7 @@ #endif // HAVE_STRING_H #include +#include typedef vector rectList; Workspace::Workspace(BScreen &scrn, int i) : screen(scrn) { @@ -120,7 +121,7 @@ const int Workspace::removeWindow(OpenboxWindow *w) { if (w->isTransient() && w->getTransientFor() && w->getTransientFor()->isVisible()) { w->getTransientFor()->setInputFocus(); - } else if (screen.isSloppyFocus()) { + } else if (screen.sloppyFocus()) { screen.getOpenbox().setFocusedWindow((OpenboxWindow *) 0); } else { OpenboxWindow *top = stackingList->first(); @@ -321,6 +322,7 @@ void Workspace::setName(char *new_name) { clientmenu->setLabel(name); clientmenu->update(); + screen.saveWorkspaceNames(); } @@ -331,37 +333,37 @@ void Workspace::shutdown(void) { } } -static rectList calcSpace(const OpenboxWindow &win, const rectList &spaces) { +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.area().Intersect(*siter)) { + if(win.Intersect(*siter)) { //Check for space to the left of the window - if(win.origin().x() > siter->x()) + if(win.x() > siter->x()) result.push_back(Rect(siter->x(), siter->y(), - win.origin().x() - siter->x() - 1, + win.x() - siter->x() - 1, siter->h())); //Check for space above the window - if(win.origin().y() > siter->y()) + if(win.y() > siter->y()) result.push_back(Rect(siter->x(), siter->y(), siter->w(), - win.origin().y() - siter->y() - 1)); + win.y() - siter->y() - 1)); //Check for space to the right of the window - if((win.origin().x()+win.size().w()) < + if((win.x()+win.w()) < (siter->x()+siter->w())) - result.push_back(Rect(win.origin().x() + win.size().w() + 1, + result.push_back(Rect(win.x() + win.w() + 1, siter->y(), siter->x() + siter->w() - - win.origin().x() - win.size().w() - 1, + win.x() - win.w() - 1, siter->h())); //Check for space below the window - if((win.origin().y()+win.size().h()) < + if((win.y()+win.h()) < (siter->y()+siter->h())) result.push_back(Rect(siter->x(), - win.origin().y() + win.size().h() + 1, + win.y() + win.h() + 1, siter->w(), siter->y() + siter->h()- - win.origin().y() - win.size().h() - 1)); + win.y() - win.h() - 1)); } else @@ -370,11 +372,35 @@ static rectList calcSpace(const OpenboxWindow &win, const rectList &spaces) { return result; } + +bool incWidth(const Rect &first, const Rect &second) { + return first.x() < second.x(); +} + + +bool decWidth(const Rect &first, const Rect &second) { + if (second.x() == first.x()) + return second.w() < first.w(); + return second.x() < first.x(); +} + + +bool incHeight(const Rect &first, const Rect &second) { + return first.y() < second.y(); +} + + +bool decHeight(const Rect &first, const Rect &second) { + if (second.y() == first.y()) + return second.h() < first.h(); + return second.y() < first.y(); +} + + //BestFitPlacement finds the smallest free space that fits the window //to be placed. It currentl ignores whether placement is right to left or top //to bottom. -Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) -{ +Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) { const Rect *best; rectList spaces; LinkedListIterator it(windowList); @@ -384,57 +410,75 @@ Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) //Find Free Spaces for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current()) - spaces = calcSpace(*cur, spaces); + spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4), + spaces); + //Sort the spaces by placement choice + if (screen.rowPlacementDirection() == BScreen::TopBottom) + sort(spaces.begin(), spaces.end(), decHeight); + else + sort(spaces.begin(), spaces.end(), incHeight); + if (screen.colPlacementDirection() == BScreen::TopBottom) + stable_sort(spaces.begin(), spaces.end(), incHeight); + else + stable_sort(spaces.begin(), spaces.end(), decHeight); + //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; + if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) { + if (best==NULL) + best = siter; + else if(siter->w()*siter->h()h()*best->w()) + best = siter; + } } - - if (best != NULL) - return new Point(best->origin()); - else + if (best != NULL) { + Point *pt = new Point(best->origin()); + if (screen.colPlacementDirection() != BScreen::TopBottom) + pt->setY(pt->y() + (best->h() - win_size.h())); + if (screen.rowPlacementDirection() != BScreen::LeftRight) + pt->setX(pt->x() + (best->w() - win_size.w())); + return pt; + } else return NULL; //fall back to cascade } -inline Point *Workspace::rowSmartPlacement(const Size &win_size, - const Rect &space){ + +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.getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1); + ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1); int change_x = - ((screen.getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); + ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); int delta_x = 8, delta_y = 8; LinkedListIterator it(windowList); - test_y = (screen.getColPlacementDirection() == BScreen::TopBottom) ? + test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? start_pos : screen.size().h() - win_size.h() - start_pos; while(!placed && - ((screen.getColPlacementDirection() == BScreen::BottomTop) ? + ((screen.colPlacementDirection() == BScreen::BottomTop) ? test_y > 0 : test_y + win_size.h() < (signed) space.h())) { - test_x = (screen.getRowPlacementDirection() == BScreen::LeftRight) ? + test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? start_pos : space.w() - win_size.w() - start_pos; while (!placed && - ((screen.getRowPlacementDirection() == BScreen::RightLeft) ? + ((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->size().w() + (screen.getBorderWidth() * 4); - int curr_h = curr->size().h() + (screen.getBorderWidth() * 4); + int curr_w = curr->area().w() + (screen.getBorderWidth() * 4); + int curr_h = curr->area().h() + (screen.getBorderWidth() * 4); - if (curr->origin().x() < test_x + win_size.w() && - curr->origin().x() + curr_w > test_x && - curr->origin().y() < test_y + win_size.h() && - curr->origin().y() + curr_h > test_y) { + 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; } } @@ -460,30 +504,29 @@ inline Point *Workspace::rowSmartPlacement(const Size &win_size, return NULL; // fall back to cascade } -inline Point * Workspace::colSmartPlacement(const Size &win_size, - const Rect &space){ +Point *Workspace::colSmartPlacement(const Size &win_size, const Rect &space) { Point *pt; bool placed=false; int test_x, test_y; int start_pos = 0; int change_y = - ((screen.getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1); + ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1); int change_x = - ((screen.getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); + ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); int delta_x = 8, delta_y = 8; LinkedListIterator it(windowList); - test_x = (screen.getRowPlacementDirection() == BScreen::LeftRight) ? + test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? start_pos : screen.size().w() - win_size.w() - start_pos; while(!placed && - ((screen.getRowPlacementDirection() == BScreen::RightLeft) ? + ((screen.rowPlacementDirection() == BScreen::RightLeft) ? test_x > 0 : test_x + win_size.w() < (signed) space.w())) { - test_y = (screen.getColPlacementDirection() == BScreen::TopBottom) ? + test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? start_pos : screen.size().h() - win_size.h() - start_pos; while(!placed && - ((screen.getColPlacementDirection() == BScreen::BottomTop) ? + ((screen.colPlacementDirection() == BScreen::BottomTop) ? test_y > 0 : test_y + win_size.h() < (signed) space.h())){ placed = true; @@ -491,13 +534,13 @@ inline Point * Workspace::colSmartPlacement(const Size &win_size, it.reset(); for (OpenboxWindow *curr = it.current(); placed && curr; it++, curr = it.current()) { - int curr_w = curr->size().w() + (screen.getBorderWidth() * 4); - int curr_h = curr->size().h() + (screen.getBorderWidth() * 4); + int curr_w = curr->area().w() + (screen.getBorderWidth() * 4); + int curr_h = curr->area().h() + (screen.getBorderWidth() * 4); - if (curr->origin().x() < test_x + win_size.w() && - curr->origin().x() + curr_w > test_x && - curr->origin().y() < test_y + win_size.h() && - curr->origin().y() + curr_h > test_y) { + 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; } } @@ -522,6 +565,7 @@ inline Point * Workspace::colSmartPlacement(const Size &win_size, return NULL; } + Point *const Workspace::cascadePlacement(const OpenboxWindow *const win){ if (((unsigned) cascade_x > (screen.size().w() / 2)) || ((unsigned) cascade_y > (screen.size().h() / 2))) @@ -537,40 +581,111 @@ Point *const Workspace::cascadePlacement(const OpenboxWindow *const win){ void Workspace::placeWindow(OpenboxWindow *win) { ASSERT(win != NULL); - const int win_w = win->size().w() + (screen.getBorderWidth() * 4), - win_h = win->size().h() + (screen.getBorderWidth() * 4), + // 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_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), + Slit *slit = screen.getSlit(); + int slit_x = slit->autoHide() ? slit->hiddenOrigin().x() : slit->area().x(), + slit_y = slit->autoHide() ? slit->hiddenOrigin().y() : slit->area().y(); + Toolbar *toolbar = screen.getToolbar(); + int tbarh = screen.hideToolbar() ? 0 : + toolbar->getExposedHeight() + screen.getBorderWidth() * 2; + bool tbartop; + switch (toolbar->placement()) { + case Toolbar::TopLeft: + case Toolbar::TopCenter: + case Toolbar::TopRight: + tbartop = true; + break; + case Toolbar::BottomLeft: + case Toolbar::BottomCenter: + case Toolbar::BottomRight: + tbartop = false; + break; + default: + ASSERT(false); // unhandled placement + } + if ((slit->direction() == Slit::Horizontal && + (slit->placement() == Slit::TopLeft || + slit->placement() == Slit::TopRight)) || + slit->placement() == Slit::TopCenter) { + // exclude top + if (tbartop && slit_y + slit->area().h() < tbarh) { + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } else { + space.setY(space.y() + (slit_y + slit->area().h() + + screen.getBorderWidth() * 2)); + space.setH(space.h() - (slit_y + slit->area().h() + + screen.getBorderWidth() * 2)); + if (!tbartop) + space.setH(space.h() - tbarh); + } + } else if ((slit->direction() == Slit::Vertical && + (slit->placement() == Slit::TopRight || + slit->placement() == Slit::BottomRight)) || + slit->placement() == Slit::CenterRight) { + // exclude right + space.setW(space.w() - (screen.size().w() - slit_x)); + if (tbartop) + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } else if ((slit->direction() == Slit::Horizontal && + (slit->placement() == Slit::BottomLeft || + slit->placement() == Slit::BottomRight)) || + slit->placement() == Slit::BottomCenter) { + // exclude bottom + if (!tbartop && (screen.size().h() - slit_y) < tbarh) { + space.setH(space.h() - tbarh); + } else { + space.setH(space.h() - (screen.size().h() - slit_y)); + if (tbartop) { + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } + } + } else {// if ((slit->direction() == Slit::Vertical && + // (slit->placement() == Slit::TopLeft || + // slit->placement() == Slit::BottomLeft)) || + // slit->placement() == Slit::CenterLeft) + // exclude left + space.setX(slit_x + slit->area().w() + + screen.getBorderWidth() * 2); + space.setW(space.w() - (slit_x + slit->area().w() + + screen.getBorderWidth() * 2)); + if (tbartop) + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } +#else // !SLIT + 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: + space.setY(toolbar->getExposedHeight()); + space.setH(space.h() - toolbar->getExposedHeight()); + break; + case Toolbar::BottomLeft: + case Toolbar::BottomCenter: + case Toolbar::BottomRight: + space.setH(space.h() - tbarh); + break; + default: + ASSERT(false); // unhandled placement + } #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; - - LinkedListIterator it(windowList); - Rect space(0, 0, - screen.size().w(), - screen.size().h() - ); - Size window_size(win->size().w()+screen.getBorderWidth() * 4, - win->size().h()+screen.getBorderWidth() * 4); + const Size window_size(win->area().w()+screen.getBorderWidth() * 4, + win->area().h()+screen.getBorderWidth() * 4); Point *place = NULL; + LinkedListIterator it(windowList); - switch (screen.getPlacementPolicy()) { + switch (screen.placementPolicy()) { case BScreen::BestFitPlacement: place = bestFitPlacement(window_size, space); break; @@ -586,11 +701,11 @@ void Workspace::placeWindow(OpenboxWindow *win) { 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); + if (place->x() + window_size.w() > (signed) screen.size().w()) + place->setX(((signed) screen.size().w() - window_size.w()) / 2); + if (place->y() + window_size.h() > (signed) screen.size().h()) + place->setY(((signed) screen.size().h() - window_size.h()) / 2); - win->configure(place->x(), place->y(), win->size().w(), win->size().h()); + win->configure(place->x(), place->y(), win->area().w(), win->area().h()); delete place; }