new row/col Smart Placement from colophon

This commit is contained in:
Dana Jansens 2002-04-28 01:05:12 +00:00
parent 20cd70c466
commit ad7f61121c

View file

@ -372,28 +372,52 @@ static rectList calcSpace(const Rect &win, const rectList &spaces) {
return result; return result;
} }
bool rowRLBT(const Rect &first, const Rect &second){
bool incWidth(const Rect &first, const Rect &second) { if (first.y()+first.h()==second.y()+second.h())
return first.x() < second.x(); return first.x()+first.w()>second.x()+second.w();
return first.y()+first.h()>second.y()+second.h();
}
bool rowRLTB(const Rect &first, const Rect &second){
if (first.y()==second.y())
return first.x()+first.w()>second.x()+second.w();
return first.y()<second.y();
} }
bool rowLRBT(const Rect &first, const Rect &second){
bool decWidth(const Rect &first, const Rect &second) { if (first.y()+first.h()==second.y()+second.h())
if (second.x() == first.x()) return first.x()<second.x();
return second.w() < first.w(); return first.y()+first.h()>second.y()+second.h();
return second.x() < first.x(); }
bool rowLRTB(const Rect &first, const Rect &second){
if (first.y()==second.y())
return first.x()<second.x();
return first.y()<second.y();
}
bool colLRTB(const Rect &first, const Rect &second){
if (first.x()==second.x())
return first.y()<second.y();
return first.x()<second.y();
}
bool colLRBT(const Rect &first, const Rect &second){
if (first.x()==second.x())
return first.y()+first.h()>second.y()+second.h();
return first.x()<second.y();
} }
bool colRLTB(const Rect &first, const Rect &second){
bool incHeight(const Rect &first, const Rect &second) { if (first.x()+first.w()==second.x()+second.w())
return first.y() < second.y(); return first.y()<second.y();
return first.x()+first.w()>second.x()+second.w();
} }
bool colRLBT(const Rect &first, const Rect &second){
bool decHeight(const Rect &first, const Rect &second) { if (first.x()+first.w()==second.x()+second.w())
if (second.y() == first.y()) return first.y()+first.h()>second.y()+second.h();
return second.h() < first.h(); return first.x()+first.w()>second.x()+second.w();
return second.y() < first.y();
} }
@ -413,16 +437,6 @@ Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) {
spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4), spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
spaces); 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 //Find first space that fits the window
best = NULL; best = NULL;
for (siter=spaces.begin(); siter!=spaces.end(); ++siter) { for (siter=spaces.begin(); siter!=spaces.end(); ++siter) {
@ -466,123 +480,92 @@ Point *Workspace::underMousePlacement(const Size &win_size, const Rect &space) {
} }
Point *Workspace::rowSmartPlacement(const Size &win_size, const Rect &space) { Point *Workspace::rowSmartPlacement(const Size &win_size, const Rect &space) {
bool placed=false; const Rect *best;
int test_x, test_y, place_x = 0, place_y = 0; rectList spaces;
int start_pos = 0;
int change_y =
((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1);
int change_x =
((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1);
int delta_x = 8, delta_y = 8;
LinkedListIterator<OpenboxWindow> it(windowList); LinkedListIterator<OpenboxWindow> it(windowList);
test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? rectList::const_iterator siter;
start_pos : screen.size().h() - win_size.h() - start_pos; spaces.push_back(space); //initially the entire screen is free
it.reset();
while(!placed &&
((screen.colPlacementDirection() == BScreen::BottomTop) ? //Find Free Spaces
test_y > 0 : test_y + win_size.h() < (signed) space.h())) { for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
start_pos : space.w() - win_size.w() - start_pos; spaces);
while (!placed && //Sort spaces by preference
((screen.rowPlacementDirection() == BScreen::RightLeft) ? if(screen.rowPlacementDirection() == BScreen::RightLeft)
test_x > 0 : test_x + win_size.w() < (signed) space.w())) { if(screen.colPlacementDirection() == BScreen::TopBottom)
placed = true; sort(spaces.begin(),spaces.end(),rowRLTB);
else
it.reset(); sort(spaces.begin(),spaces.end(),rowRLBT);
for (OpenboxWindow *curr = it.current(); placed && curr; else
it++, curr = it.current()) { if(screen.colPlacementDirection() == BScreen::TopBottom)
int curr_w = curr->area().w() + (screen.getBorderWidth() * 4); sort(spaces.begin(),spaces.end(),rowLRTB);
int curr_h = curr->area().h() + (screen.getBorderWidth() * 4); else
sort(spaces.begin(),spaces.end(),rowLRBT);
if (curr->area().x() < test_x + win_size.w() && best = NULL;
curr->area().x() + curr_w > test_x && for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
curr->area().y() < test_y + win_size.h() && if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
curr->area().y() + curr_h > test_y) { best = siter;
placed = false; break;
}
}
// Removed code for checking toolbar and slit
// The space passed in should not include either
if (placed) {
place_x = test_x;
place_y = test_y;
break;
}
test_x += (change_x * delta_x);
} }
test_y += (change_y * delta_y); if (best != NULL) {
} Point *pt = new Point(best->origin());
if (placed) if (screen.colPlacementDirection() != BScreen::TopBottom)
return new Point(place_x, place_y); pt->setY(best->y() + best->h() - win_size.h());
else if (screen.rowPlacementDirection() != BScreen::LeftRight)
return NULL; // fall back to cascade 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) { Point *Workspace::colSmartPlacement(const Size &win_size, const Rect &space) {
Point *pt; const Rect *best;
bool placed=false; rectList spaces;
int test_x, test_y;
int start_pos = 0;
int change_y =
((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1);
int change_x =
((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1);
int delta_x = 8, delta_y = 8;
LinkedListIterator<OpenboxWindow> it(windowList); LinkedListIterator<OpenboxWindow> it(windowList);
test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? rectList::const_iterator siter;
start_pos : screen.size().w() - win_size.w() - start_pos; spaces.push_back(space); //initially the entire screen is free
it.reset();
while(!placed &&
((screen.rowPlacementDirection() == BScreen::RightLeft) ? //Find Free Spaces
test_x > 0 : test_x + win_size.w() < (signed) space.w())) { for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
start_pos : screen.size().h() - win_size.h() - start_pos; spaces);
//Sort spaces by user preference
while(!placed && if(screen.colPlacementDirection() == BScreen::TopBottom)
((screen.colPlacementDirection() == BScreen::BottomTop) ? if(screen.rowPlacementDirection() == BScreen::LeftRight)
test_y > 0 : test_y + win_size.h() < (signed) space.h())){ sort(spaces.begin(),spaces.end(),colLRTB);
else
placed = true; sort(spaces.begin(),spaces.end(),colRLTB);
else
it.reset(); if(screen.rowPlacementDirection() == BScreen::LeftRight)
for (OpenboxWindow *curr = it.current(); placed && curr; sort(spaces.begin(),spaces.end(),colLRBT);
it++, curr = it.current()) { else
int curr_w = curr->area().w() + (screen.getBorderWidth() * 4); sort(spaces.begin(),spaces.end(),colRLBT);
int curr_h = curr->area().h() + (screen.getBorderWidth() * 4); fprintf(stderr,"Spaces after sorting\n");
for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
if (curr->area().x() < test_x + win_size.w() && fprintf(stderr,"space(%d,%d)(%d,%d)\n",siter->x(),siter->y(),
curr->area().x() + curr_w > test_x && siter->x()+siter->w(),siter->y()+siter->h());
curr->area().y() < test_y + win_size.h() && //Find first space that fits the window
curr->area().y() + curr_h > test_y) { best = NULL;
placed = False; for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
} if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
} best = siter;
break;
// 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);
} }
test_x += (change_x * delta_x); if (best != NULL) {
} Point *pt = new Point(best->origin());
if (placed) 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; return pt;
else } else
return NULL; return NULL; //fall back to cascade
} }