commit 77b72f66a3f578fdb71b7742e8ed988116c0f65e
parent 5eb7fac9ad796599e043f3ec1c4e3950d23c1f78
Author: Lucas de Sena <lucas@seninha.org>
Date: Fri, 21 Apr 2023 19:11:41 -0300
testing changing .fact when dragging divisions
Diffstat:
M | shod.h | | | 2 | +- |
M | xcontainer.c | | | 44 | +++++++++++++++++++++----------------------- |
M | xevents.c | | | 92 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | xmon.c | | | 2 | +- |
4 files changed, 79 insertions(+), 61 deletions(-)
diff --git a/shod.h b/shod.h
@@ -712,7 +712,7 @@ void containerdel(struct Container *c);
void containermoveresize(struct Container *c, int checkstack);
void containerdecorate(struct Container *c, struct Column *cdiv, struct Row *rdiv, int recursive, enum Octant o);
void containerredecorate(struct Container *c, struct Column *cdiv, struct Row *rdiv, enum Octant o);
-void containercalccols(struct Container *c, int recalcfact);
+void containercalccols(struct Container *c);
void containersetstate(struct Tab *, Atom *, unsigned long);
void containerincrmove(struct Container *c, int x, int y);
void containerraise(struct Container *c, int isfullscreen, int layer);
diff --git a/xcontainer.c b/xcontainer.c
@@ -436,7 +436,7 @@ coldetach(struct Column *col)
}
c->ncols--;
TAILQ_REMOVE(&c->colq, col, entry);
- containercalccols(col->c, 1);
+ containercalccols(col->c);
}
/* delete column */
@@ -630,7 +630,7 @@ containeraddcol(struct Container *c, struct Column *col, struct Column *prev)
else
TAILQ_INSERT_AFTER(&c->colq, prev, col, entry);
XReparentWindow(dpy, col->div, c->frame, 0, 0);
- containercalccols(c, 1);
+ containercalccols(c);
if (oldc != NULL && oldc->ncols == 0) {
containerdel(oldc);
}
@@ -675,7 +675,7 @@ containerfullscreen(struct Container *c, int fullscreen)
containerraise(c, 0, c->abovebelow);
else
return;
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 1);
containerredecorate(c, NULL, NULL, 0);
ewmhsetstate(c);
@@ -691,7 +691,7 @@ containermaximize(struct Container *c, int maximize)
c->ismaximized = 0;
else
return;
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 1);
containerredecorate(c, NULL, NULL, 0);
}
@@ -742,7 +742,7 @@ containershade(struct Container *c, int shade)
} else {
return;
}
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 1);
containerredecorate(c, NULL, NULL, 0);
if (c == wm.focused) {
@@ -1058,7 +1058,7 @@ containerredecorate(struct Container *c, struct Column *cdiv, struct Row *rdiv,
/* calculate position and width of columns of a container */
void
-containercalccols(struct Container *c, int recalcfact)
+containercalccols(struct Container *c)
{
struct Column *col;
int i, x, w;
@@ -1075,7 +1075,7 @@ containercalccols(struct Container *c, int recalcfact)
TAILQ_FOREACH(col, &c->colq, entry) {
col->x = 0;
col->w = c->w;
- colcalcrows(col, recalcfact);
+ colcalcrows(col, 0);
}
return;
} else if (c->ismaximized) {
@@ -1100,15 +1100,13 @@ containercalccols(struct Container *c, int recalcfact)
sumw = 0;
recalc = 0;
TAILQ_FOREACH(col, &c->colq, entry) {
- if (!recalcfact) {
- if (TAILQ_NEXT(col, entry) == NULL) {
- col->w = content - sumw;
- } else {
- col->w = col->fact * content;
- }
- if (col->w == 0) {
- recalc = 1;
- }
+ if (TAILQ_NEXT(col, entry) == NULL) {
+ col->w = content - sumw;
+ } else {
+ col->w = col->fact * content;
+ }
+ if (col->w == 0) {
+ recalc = 1;
}
sumw += col->w;
}
@@ -1123,11 +1121,11 @@ containercalccols(struct Container *c, int recalcfact)
c->h = max(c->h, col->nrows * config.titlewidth);
if (recalc)
col->w = max(1, ((i + 1) * w / c->ncols) - (i * w / c->ncols));
- if (recalc || recalcfact)
+ if (recalc)
col->fact = (double)col->w/(double)c->w;
col->x = x;
x += col->w + config.divwidth;
- colcalcrows(col, recalcfact);
+ colcalcrows(col, 0);
i++;
}
if (containerisshaded(c)) {
@@ -1272,7 +1270,7 @@ containerconfigure(struct Container *c, unsigned int valuemask, XWindowChanges *
c->nw = wc->width;
if ((valuemask & CWHeight) && wc->height >= wm.minsize)
c->nh = wc->height;
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 1);
containerredecorate(c, NULL, NULL, 0);
}
@@ -1432,7 +1430,7 @@ containerplace(struct Container *c, struct Monitor *mon, int desk, int userplace
subh = subh * mon->wh / DIV;
c->nx = min(mon->wx + mon->ww - c->nw, max(mon->wx, mon->wx + subx + subw / 2 - c->nw / 2));
c->ny = min(mon->wy + mon->wh - c->nh, max(mon->wy, mon->wy + suby + subh / 2 - c->nh / 2));
- containercalccols(c, 0);
+ containercalccols(c);
}
/* check whether container is sticky or is on given desktop */
@@ -1525,7 +1523,7 @@ found:
}
rowaddtab(row, det, tab);
if (ncol != NULL)
- containercalccols(c, 1);
+ containercalccols(c);
else if (nrow != NULL)
colcalcrows(col, 1);
else
@@ -1564,7 +1562,7 @@ containerdelrow(struct Row *row)
recalc = 0;
}
if (recalc) {
- containercalccols(c, 1);
+ containercalccols(c);
containermoveresize(c, 0);
shodgrouptab(c);
shodgroupcontainer(c);
@@ -1967,7 +1965,7 @@ unmanagecontainer(struct Object *obj, int ignoreunmap)
}
}
if (moveresize) {
- containercalccols(c, 1);
+ containercalccols(c);
containermoveresize(c, 0);
containerredecorate(c, NULL, NULL, 0);
shodgrouptab(c);
diff --git a/xevents.c b/xevents.c
@@ -1011,7 +1011,7 @@ mouseresize(int type, void *obj, int xroot, int yroot, enum Octant o)
menumoveresize(menu);
menudecorate(menu, 0);
} else {
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 0);
containerredecorate(c, NULL, NULL, o);
}
@@ -1027,7 +1027,7 @@ done:
menumoveresize(menu);
menudecorate(menu, 0);
} else {
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 1);
containerdecorate(c, NULL, NULL, 0, 0);
}
@@ -1102,13 +1102,14 @@ done:
/* resize tiles by dragging division with mouse */
static void
-mouseretile(struct Container *c, struct Column *cdiv, struct Row *rdiv, int xroot, int yroot)
+mouseretile(struct Container *c, struct Column *cdiv, struct Row *rdiv, int xprev, int yprev)
{
struct Row *row;
XEvent ev;
Cursor curs;
Time lasttime;
- int x, y;
+ double fact;
+ int ignore, len, x, y;
if (cdiv != NULL && TAILQ_NEXT(cdiv, entry) != NULL)
curs = wm.cursors[CURSOR_H];
@@ -1127,51 +1128,70 @@ mouseretile(struct Container *c, struct Column *cdiv, struct Row *rdiv, int xroo
goto done;
break;
case MotionNotify:
- x = ev.xmotion.x_root - xroot;
- y = ev.xmotion.y_root - yroot;
- if (cdiv != NULL) {
- if (x < 0 && cdiv->w + x >= wm.minsize) {
- cdiv->w += x;
- TAILQ_NEXT(cdiv, entry)->w -= x;
- } else if (x > 0 && TAILQ_NEXT(cdiv, entry)->w - x >= wm.minsize) {
- TAILQ_NEXT(cdiv, entry)->w -= x;
- cdiv->w += x;
+ x = ev.xmotion.x - xprev;
+ y = ev.xmotion.y - yprev;
+ ignore = 0;
+ len = 0;
+ 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;
+ fact = (double)x / (double)len;
+ if ((cdiv->fact + fact) * len >= wm.minsize &&
+ (TAILQ_NEXT(cdiv, entry)->fact - fact) *
+ len >= wm.minsize) {
+ cdiv->fact += fact;
+ TAILQ_NEXT(cdiv, entry)->fact -= fact;
}
}
- for (row = rdiv; row != NULL && TAILQ_NEXT(row, entry) != NULL; ) {
- if (y < 0) {
- if (row->h + y < config.titlewidth) {
- row = TAILQ_PREV(row, RowQueue, entry);
- ev.xmotion.y_root -= y;
- continue;
- }
- row->h += y;
- TAILQ_NEXT(row, entry)->h -= y;
+ if (rdiv != NULL) {
+ len = rdiv->col->c->h;
+ len -= 2 * rdiv->col->c->b;
+ len -= (rdiv->col->nrows - 1) * config.divwidth;
+ }
+ for (row = rdiv; row != NULL && y < 0 &&
+ ev.xmotion.y < TAILQ_NEXT(row, entry)->y;
+ row = TAILQ_PREV(row, RowQueue, entry)) {
+ fact = (double)y / (double)len;
+ if (row->fact + fact < 0.0) {
+ ignore = 1;
+ continue;
}
- if (y > 0) {
- if (TAILQ_NEXT(row, entry)->h - y < config.titlewidth) {
- row = TAILQ_NEXT(row, entry);
- ev.xmotion.y_root -= y;
- continue;
- }
- TAILQ_NEXT(row, entry)->h -= y;
- row->h += y;
+ row->fact += fact;
+ TAILQ_NEXT(rdiv, entry)->fact -= fact;
+ if (ignore) {
+ break;
+ }
+ }
+ for (row = rdiv; row != NULL && y > 0 &&
+ ev.xmotion.y > TAILQ_NEXT(rdiv, entry)->y;
+ row = TAILQ_NEXT(row, entry)) {
+ fact = (double)y / (double)len;
+ if (rdiv == row || row->fact - fact < 0.0) {
+ ignore = 1;
+ continue;
+ }
+ rdiv->fact += fact;
+ row->fact -= fact;
+ if (ignore) {
+ break;
}
- break;
}
if (ev.xmotion.time - lasttime > RESIZETIME) {
- containercalccols(c, 1);
+ containercalccols(c);
containermoveresize(c, 0);
containerdecorate(c, cdiv, rdiv, 0, 0);
lasttime = ev.xmotion.time;
}
- xroot = ev.xmotion.x_root;
- yroot = ev.xmotion.y_root;
+ xprev = ev.xmotion.x;
+ yprev = ev.xmotion.y;
break;
}
}
done:
- containercalccols(c, 1);
+ containercalccols(c);
containermoveresize(c, 0);
tabfocus(c->selcol->selrow->seltab, 0);
XUngrabPointer(dpy, CurrentTime);
@@ -1301,7 +1321,7 @@ xeventbuttonpress(XEvent *e)
} else if (ev->window == c->frame && ev->button == Button1 && o == C) {
getdivisions(c, &cdiv, &rdiv, x, y);
if (cdiv != NULL || rdiv != NULL) {
- mouseretile(c, cdiv, rdiv, ev->x_root, ev->y_root);
+ mouseretile(c, cdiv, rdiv, ev->x, ev->y);
}
} else if (!c->isfullscreen && !c->isminimized && !c->ismaximized) {
if (isvalidstate(ev->state) && ev->button == Button1) {
diff --git a/xmon.c b/xmon.c
@@ -221,7 +221,7 @@ monupdatearea(void)
}
TAILQ_FOREACH(c, &wm.focusq, entry) {
if (c->ismaximized) {
- containercalccols(c, 0);
+ containercalccols(c);
containermoveresize(c, 0);
containerredecorate(c, NULL, NULL, 0);
}