make minimum column width resolution dependent, fix some off-by-one's

This commit is contained in:
Sander van Dijk 2006-07-13 21:58:26 +00:00
parent 407ec20d14
commit d4451fc320
4 changed files with 30 additions and 25 deletions

View File

@ -19,21 +19,24 @@ Area *
create_area(View *v, Area *pos, unsigned int w)
{
static unsigned short id = 1;
unsigned int area_size;
unsigned int area_size, col_size;
unsigned int min_width = screen->rect.width/NCOL;
Area *a, **p = pos ? &pos->next : &v->area;
for(area_size = 0, a=v->area; a; a=a->next, area_size++);
col_size = area_size ? area_size - 1 : 0;
if(!w) {
if(area_size > 1)
w = screen->rect.width / area_size - 1;
if(col_size)
w = screen->rect.width / (col_size + 1);
else
w = screen->rect.width;
}
if(w < MIN_COLWIDTH)
w = MIN_COLWIDTH;
if(w < min_width)
w = min_width;
if(area_size >= 2 && (area_size - 1) * MIN_COLWIDTH + w > screen->rect.width)
if(col_size && col_size * min_width + w > screen->rect.width)
return nil;
if(area_size > 1)

View File

@ -136,7 +136,7 @@ scale_column(Area *a, float h)
if(frame_size * min_height > h)
return;
yoff = 0;
for(f=a->frame; f; f=f->anext, frame_size--) {
for(f=a->frame, frame_size--; f; f=f->anext, frame_size--) {
if(f->rect.height < min_height)
f->rect.height = min_height;
else if((hdiff = yoff + f->rect.height - h + frame_size * min_height) > 0)
@ -228,6 +228,7 @@ drop_resize(Frame *f, XRectangle *new)
View *v = a->view;
Frame *north = nil, *south = nil;
unsigned int min_height = 2 * blitz_labelh(&def.font);
unsigned int min_width = screen->rect.width/NCOL;
for(west=v->area->next; west && west->next != a; west=west->next);
/* first managed area is indexed 1, thus (i > 1) ? ... */
@ -237,26 +238,26 @@ drop_resize(Frame *f, XRectangle *new)
south = f->anext;
/* validate (and trim if necessary) horizontal resize */
if(new->width < MIN_COLWIDTH) {
if(new->width < min_width) {
if(new->x + new->width == f->rect.x + f->rect.width)
new->x = a->rect.x + a->rect.width - MIN_COLWIDTH;
new->width = MIN_COLWIDTH;
new->x = a->rect.x + a->rect.width - min_width;
new->width = min_width;
}
if(west && (new->x != f->rect.x)) {
if(new->x < 0 || new->x < (west->rect.x + MIN_COLWIDTH)) {
new->width -= (west->rect.x + MIN_COLWIDTH) - new->x;
new->x = west->rect.x + MIN_COLWIDTH;
if(new->x < 0 || new->x < (west->rect.x + min_width)) {
new->width -= (west->rect.x + min_width) - new->x;
new->x = west->rect.x + min_width;
}
} else {
new->width += new->x - a->rect.x;
new->x = a->rect.x;
}
if(east && (new->x + new->width != f->rect.x + f->rect.width)) {
if((new->x + new->width) > (east->rect.x + east->rect.width - MIN_COLWIDTH))
new->width = (east->rect.x + east->rect.width - MIN_COLWIDTH) - new->x;
if((new->x + new->width) > (east->rect.x + east->rect.width - min_width))
new->width = (east->rect.x + east->rect.width - min_width) - new->x;
} else
new->width = (a->rect.x + a->rect.width) - new->x;
if(new->width < MIN_COLWIDTH)
if(new->width < min_width)
goto AfterHorizontal;
/* horizontal resize */

View File

@ -215,7 +215,8 @@ restack_view(View *v)
void
scale_view(View *v, float w)
{
unsigned int xoff, i=0;
unsigned int xoff, col_size = 0;
unsigned int min_width = screen->rect.width/NCOL;
Area *a;
float scale, dx = 0;
int wdiff = 0;
@ -223,7 +224,7 @@ scale_view(View *v, float w)
if(!v->area->next)
return;
for(a=v->area->next; a; a=a->next, i++)
for(a=v->area->next; a; a=a->next, col_size++)
dx += a->rect.width;
scale = w / dx;
xoff = 0;
@ -234,14 +235,14 @@ scale_view(View *v, float w)
xoff += a->rect.width;
}
/* MIN_COLWIDTH can only be respected when there is enough space; the caller should guarantee this */
if(i * MIN_COLWIDTH > w)
/* min_width can only be respected when there is enough space; the caller should guarantee this */
if(col_size * min_width > w)
return;
xoff = 0;
for(a=v->area->next; a; a=a->next, i--) {
if(a->rect.width < MIN_COLWIDTH)
a->rect.width = MIN_COLWIDTH;
else if((wdiff = xoff + a->rect.width - w + i * MIN_COLWIDTH) > 0)
for(a=v->area->next, col_size--; a; a=a->next, col_size--) {
if(a->rect.width < min_width)
a->rect.width = min_width;
else if((wdiff = xoff + a->rect.width - w + col_size * min_width) > 0)
a->rect.width -= wdiff;
if(!a->next)
a->rect.width = w - xoff;

View File

@ -41,7 +41,7 @@ enum {
CurLast
};
enum { MIN_COLWIDTH = 64 };
enum { NCOL = 16 };
enum { WM_PROTOCOL_DELWIN = 1 };
/* Data Structures */