Refactoring in column.c

This commit is contained in:
Kris Maglione 2007-02-10 21:02:34 -05:00
parent ced1e98aff
commit 5bd7c64458
5 changed files with 73 additions and 49 deletions

4
README
View File

@ -52,9 +52,9 @@ Credits
The following people have contributed especially to wmii in various ways: The following people have contributed especially to wmii in various ways:
- Christoph Wegscheider <christoph dot wegscheider at wegi dot net> - Christoph Wegscheider <christoph dot wegscheider at wegi dot net>
- Georg Neis <gn at wmii dot de> - Georg Neis <gn at suckless dot org>
- Uwe Zeisberger <zeisberg at informatik dot uni-freiburg dot de> - Uwe Zeisberger <zeisberg at informatik dot uni-freiburg dot de>
- Uriel <uriel at wmii dot de> - Uriel <uriel at suckless dot org>
- Scot Doyle <scot at scotdoyle dot com> - Scot Doyle <scot at scotdoyle dot com>
- Sebastian Hartmann <seb dot wmi at gmx dot de> - Sebastian Hartmann <seb dot wmi at gmx dot de>
- Bernhard Leiner <bleiner at gmail dot com> - Bernhard Leiner <bleiner at gmail dot com>

View File

@ -199,28 +199,35 @@ match_horiz(Area *a, XRectangle *r) {
} }
} }
static void void
drop_resize(Frame *f, XRectangle *new) { resize_column(Client *c, XRectangle *new) {
Area *west = nil, *east = nil, *a = f->area; Area *west, *east, *a;
View *v = a->view; Frame *north, *south, *f;
Frame *north = nil, *south = nil; View *v;
unsigned int min_height = 2 * labelh(&def.font); BlitzAlign sticky;
unsigned int min_width = screen->rect.width/NCOL; unsigned int min_height;
unsigned int min_width;
f = c->sel;
a = f->area;
v = a->view;
min_height = 2 * labelh(&def.font);
min_width = screen->rect.width/NCOL;
for(west=v->area->next; west; west=west->next) for(west=v->area->next; west; west=west->next)
if(west->next == a) break; if(west->next == a) break;
/* first managed area is indexed 1, thus (i > 1) ? ... */
east = a->next; east = a->next;
for(north=a->frame; north; north=north->anext) for(north=a->frame; north; north=north->anext)
if(north->anext == f) break; if(north->anext == f) break;
south = f->anext; south = f->anext;
/* validate (and trim if necessary) horizontal resize */ /* validate (and trim if necessary) horizontal resize */
sticky = get_sticky(&f->rect, new);
if(new->width < min_width) { if(new->width < min_width) {
if((new->x + new->width) == (f->rect.x + f->rect.width)) if(sticky & EAST)
new->x = a->rect.x + a->rect.width - min_width; new->x = r_east(&a->rect) - min_width;
new->width = min_width; new->width = min_width;
} }
if(west && (new->x != f->rect.x)) { if(west && !(sticky & WEST)) {
if(new->x < 0 || new->x < (west->rect.x + min_width)) { if(new->x < 0 || new->x < (west->rect.x + min_width)) {
new->width -= (west->rect.x + min_width) - new->x; new->width -= (west->rect.x + min_width) - new->x;
new->x = west->rect.x + min_width; new->x = west->rect.x + min_width;
@ -229,15 +236,16 @@ drop_resize(Frame *f, XRectangle *new) {
new->width += new->x - a->rect.x; new->width += new->x - a->rect.x;
new->x = a->rect.x; new->x = a->rect.x;
} }
if(east && (new->x + new->width) != (f->rect.x + f->rect.width)) { if(east && !(sticky & EAST)) {
if((new->x + new->width) > (east->rect.x + east->rect.width - min_width)) if(r_east(new) > r_east(&east->rect) - min_width)
new->width = east->rect.x + east->rect.width - min_width - new->x; new->width = r_east(&east->rect) - min_width - new->x;
} else } else
new->width = a->rect.x + a->rect.width - new->x; new->width = r_east(&a->rect) - new->x;
if(new->width < min_width) if(new->width < min_width)
goto AfterHorizontal; goto AfterHorizontal;
/* horizontal resize */ /* horizontal resize */
if(west && (new->x != a->rect.x)) { sticky = get_sticky(&a->rect, new);
if(west && !(sticky & WEST)) {
west->rect.width = new->x - west->rect.x; west->rect.width = new->x - west->rect.x;
a->rect.width += a->rect.x - new->x; a->rect.width += a->rect.x - new->x;
a->rect.x = new->x; a->rect.x = new->x;
@ -245,10 +253,10 @@ drop_resize(Frame *f, XRectangle *new) {
match_horiz(west, &west->rect); match_horiz(west, &west->rect);
relax_column(west); relax_column(west);
} }
if(east && (new->x + new->width) != (a->rect.x + a->rect.width)) { if(east && !(sticky & EAST)) {
east->rect.width -= new->x + new->width - east->rect.x; east->rect.width -= r_east(new) - east->rect.x;
east->rect.x = new->x + new->width; east->rect.x = r_east(new);
a->rect.width = new->x + new->width - a->rect.x; a->rect.width = r_east(new) - a->rect.x;
match_horiz(a, &a->rect); match_horiz(a, &a->rect);
match_horiz(east, &east->rect); match_horiz(east, &east->rect);
relax_column(east); relax_column(east);
@ -258,36 +266,36 @@ AfterHorizontal:
if(a->mode != Coldefault) if(a->mode != Coldefault)
goto AfterVertical; goto AfterVertical;
/* validate (and trim if necessary) vertical resize */ /* validate (and trim if necessary) vertical resize */
sticky = get_sticky(&f->rect, new);
if(new->height < min_height) { if(new->height < min_height) {
if(f->rect.height < min_height if((f->rect.height < min_height) && sticky & (NORTH|SOUTH))
&& (new->y == f->rect.y || (new->y + new->height) == (f->rect.y + f->rect.height)))
goto AfterVertical; goto AfterVertical;
if((new->y + new->height) == (f->rect.y + f->rect.height)) if(sticky & SOUTH)
new->y = f->rect.y + f->rect.height - min_height; new->y = r_south(&f->rect) - min_height;
new->height = min_height; new->height = min_height;
} }
if(north && (new->y != f->rect.y)) if(north && !(sticky & NORTH))
if(new->y < 0 || new->y < (north->rect.y + min_height)) { if(new->y < 0 || new->y < (north->rect.y + min_height)) {
new->height -= (north->rect.y + min_height) - new->y; new->height -= (north->rect.y + min_height) - new->y;
new->y = north->rect.y + min_height; new->y = north->rect.y + min_height;
} }
if(south && (new->y + new->height) != (f->rect.y + f->rect.height)) { if(south && !(sticky & SOUTH)) {
if((new->y + new->height) > (south->rect.y + south->rect.height - min_height)) if(r_south(new) > r_south(&south->rect) - min_height)
new->height = (south->rect.y + south->rect.height - min_height) - new->y; new->height = r_south(&south->rect) - min_height - new->y;
} }
if(new->height < min_height) if(new->height < min_height)
goto AfterVertical; goto AfterVertical;
/* vertical resize */ /* vertical resize */
if(north && (new->y != f->rect.y)) { if(north && !(sticky & NORTH)) {
north->rect.height = new->y - north->rect.y; north->rect.height = new->y - north->rect.y;
f->rect.height += f->rect.y - new->y; f->rect.height += f->rect.y - new->y;
f->rect.y = new->y; f->rect.y = new->y;
resize_frame(north, &north->rect); resize_frame(north, &north->rect);
resize_frame(f, &f->rect); resize_frame(f, &f->rect);
} }
if(south && (new->y + new->height != f->rect.y + f->rect.height)) { if(south && !(sticky & SOUTH)) {
south->rect.height -= new->y + new->height - south->rect.y; south->rect.height -= r_south(new) - south->rect.y;
south->rect.y = new->y + new->height; south->rect.y = r_south(new);
f->rect.y = new->y; f->rect.y = new->y;
f->rect.height = new->height; f->rect.height = new->height;
resize_frame(f, &f->rect); resize_frame(f, &f->rect);
@ -298,11 +306,6 @@ AfterVertical:
focus_view(screen, v); focus_view(screen, v);
} }
void
resize_column(Client *c, XRectangle *r) {
drop_resize(c->sel, r);
}
Area * Area *
new_column(View *v, Area *pos, unsigned int w) { new_column(View *v, Area *pos, unsigned int w) {
Area *a = create_area(v, pos, w); Area *a = create_area(v, pos, w);

12
frame.c
View File

@ -77,19 +77,11 @@ insert_frame(Frame *pos, Frame *f, Bool before) {
void void
resize_frame(Frame *f, XRectangle *r) { resize_frame(Frame *f, XRectangle *r) {
BlitzAlign stickycorner = 0; BlitzAlign stickycorner;
Client *c; Client *c;
c = f->client; c = f->client;
stickycorner = get_sticky(&f->rect, r);
if(f->rect.x != r->x && (f->rect.x + f->rect.width) == (r->x + r->width))
stickycorner |= EAST;
else
stickycorner |= WEST;
if(f->rect.y != r->y && (f->rect.y + f->rect.height) == (r->y + r->height))
stickycorner |= SOUTH;
else
stickycorner |= NORTH;
f->rect = *r; f->rect = *r;
if((f->area->mode != Colstack) || (f->area->sel == f)) if((f->area->mode != Colstack) || (f->area->sel == f))

26
geom.c
View File

@ -40,3 +40,29 @@ strtorect(XRectangle *r, const char *val) {
*r = new; *r = new;
return 0; return 0;
} }
int
r_east(XRectangle *r) {
return r->x + r->width;
}
int
r_south(XRectangle *r) {
return r->y + r->height;
}
BlitzAlign
get_sticky(XRectangle *src, XRectangle *dst) {
BlitzAlign stickycorner = 0;
if(src->x != dst->x && r_east(src) == r_east(dst))
stickycorner |= EAST;
else
stickycorner |= WEST;
if(src->y != dst->y && r_south(src) == r_south(dst))
stickycorner |= SOUTH;
else
stickycorner |= NORTH;
return stickycorner;
}

3
wmii.h
View File

@ -350,6 +350,9 @@ extern void write_event(char *format, ...);
extern Bool ispointinrect(int x, int y, XRectangle * r); extern Bool ispointinrect(int x, int y, XRectangle * r);
extern BlitzAlign quadofcoord(XRectangle *rect, int x, int y); extern BlitzAlign quadofcoord(XRectangle *rect, int x, int y);
extern int strtorect(XRectangle *r, const char *val); extern int strtorect(XRectangle *r, const char *val);
extern BlitzAlign get_sticky(XRectangle *src, XRectangle *dst);
extern int r_east(XRectangle *r);
extern int r_south(XRectangle *r);
/* key.c */ /* key.c */
extern void kpress(Window w, unsigned long mod, KeyCode keycode); extern void kpress(Window w, unsigned long mod, KeyCode keycode);