shod

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7b77825ef35fe40255e744cbc31c265aeef2d9bc
parent 77b72f66a3f578fdb71b7742e8ed988116c0f65e
Author: Lucas de Sena <lucas@seninha.org>
Date:   Sat, 22 Apr 2023 07:56:58 -0300

add functions to compute content width and height

Diffstat:
Mshod.h | 2++
Mxcontainer.c | 19+++++++++++++++++--
Mxevents.c | 11+++--------
3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/shod.h b/shod.h @@ -731,6 +731,8 @@ void dialogmoveresize(struct Dialog *dial); int tabattach(struct Container *c, struct Tab *t, int x, int y); int containerisshaded(struct Container *c); int containerisvisible(struct Container *c, struct Monitor *mon, int desk); +int columncontentheight(struct Column *col); +int containercontentwidth(struct Container *c); /* menu */ void menufocus(struct Menu *menu); diff --git a/xcontainer.c b/xcontainer.c @@ -244,7 +244,7 @@ colcalcrows(struct Column *col, int recalcfact) } /* check if rows sum up the height of the container */ - content = c->h - col->nrows * config.titlewidth - (col->nrows - 1) * config.divwidth - 2 * c->b; + content = columncontentheight(col); sumh = 0; recalc = 0; TAILQ_FOREACH(row, &col->rowq, entry) { @@ -1096,7 +1096,7 @@ containercalccols(struct Container *c) } /* check if columns sum up the width of the container */ - content = c->w - (c->ncols - 1) * config.divwidth - 2 * c->b; + content = containercontentwidth(c); sumw = 0; recalc = 0; TAILQ_FOREACH(col, &c->colq, entry) { @@ -1997,3 +1997,18 @@ unmanagedialog(struct Object *obj, int ignoreunmap) free(dial); return 1; } + +/* get height of column without borders, divisors, title bars, etc */ +int +columncontentheight(struct Column *col) +{ + return col->c->h - col->nrows * config.titlewidth + - (col->nrows - 1) * config.divwidth - 2 * col->c->b; +} + +/* get width of container without borders, divisors, etc */ +int +containercontentwidth(struct Container *c) +{ + return c->w - (c->ncols - 1) * config.divwidth - 2 * c->b; +} diff --git a/xevents.c b/xevents.c @@ -1135,9 +1135,7 @@ mouseretile(struct Container *c, struct Column *cdiv, struct Row *rdiv, int xpre if (cdiv != NULL && ((x < 0 && ev.xmotion.x < TAILQ_NEXT(cdiv, entry)->x) || (x > 0 && ev.xmotion.x > TAILQ_NEXT(cdiv, entry)->x))) { - len = cdiv->c->w; - len -= 2 * cdiv->c->b; - len -= (cdiv->c->ncols - 1) * config.divwidth; + len = containercontentwidth(cdiv->c); fact = (double)x / (double)len; if ((cdiv->fact + fact) * len >= wm.minsize && (TAILQ_NEXT(cdiv, entry)->fact - fact) * @@ -1146,11 +1144,8 @@ mouseretile(struct Container *c, struct Column *cdiv, struct Row *rdiv, int xpre TAILQ_NEXT(cdiv, entry)->fact -= fact; } } - if (rdiv != NULL) { - len = rdiv->col->c->h; - len -= 2 * rdiv->col->c->b; - len -= (rdiv->col->nrows - 1) * config.divwidth; - } + if (rdiv != NULL) + len = columncontentheight(rdiv->col); for (row = rdiv; row != NULL && y < 0 && ev.xmotion.y < TAILQ_NEXT(row, entry)->y; row = TAILQ_PREV(row, RowQueue, entry)) {