Remove old layouts, update dragmfact

This commit is contained in:
speedie 2022-11-16 21:52:09 +01:00
parent 3efef27525
commit 154e6d2681
2 changed files with 53 additions and 191 deletions

168
layouts.c
View file

@ -814,89 +814,6 @@ ngrid(Monitor *m)
}
}
static void
bstack(Monitor *m)
{
unsigned int i, n;
int oh, ov, ih, iv;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts, sfacts;
int mrest, srest;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0)
return;
sx = mx = m->wx + ov;
sy = my = m->wy + oh;
sh = mh = m->wh - 2*oh;
mw = m->ww - 2*ov - iv * (MIN(n, m->mastercount) - 1);
sw = m->ww - 2*ov - iv * (n - m->mastercount - 1);
if (m->mastercount && n > m->mastercount) {
sh = (mh - ih) * (1 - m->mfact);
mh = mh - ih - sh;
sx = mx;
sy = my + mh + ih;
}
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if (i < m->mastercount) {
resize(c, mx, my, mw * (c->cfact / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
} else {
resize(c, sx, sy, sw * (c->cfact / sfacts) + ((i - m->mastercount) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
sx += WIDTH(c) + iv;
}
}
}
static void
bstackhoriz(Monitor *m)
{
unsigned int i, n;
int oh, ov, ih, iv;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts, sfacts;
int mrest, srest;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0)
return;
sx = mx = m->wx + ov;
sy = my = m->wy + oh;
mh = m->wh - 2*oh;
sh = m->wh - 2*oh - ih * (n - m->mastercount - 1);
mw = m->ww - 2*ov - iv * (MIN(n, m->mastercount) - 1);
sw = m->ww - 2*ov;
if (m->mastercount && n > m->mastercount) {
sh = (mh - ih) * (1 - m->mfact);
mh = mh - ih - sh;
sy = my + mh + ih;
sh = m->wh - mh - 2*oh - ih * (n - m->mastercount);
}
getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if (i < m->mastercount) {
resize(c, mx, my, mw * (c->cfact / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
} else {
resize(c, sx, sy, sw - (2*c->bw), sh * (c->cfact / sfacts) + ((i - m->mastercount) < srest ? 1 : 0) - (2*c->bw), 0);
sy += HEIGHT(c) + ih;
}
}
}
void
hgrid(Monitor *m) {
Client *c;
@ -958,91 +875,6 @@ hgrid(Monitor *m) {
}
}
void
centeredmaster(Monitor *m)
{
unsigned int i, n;
int oh, ov, ih, iv;
int mx = 0, my = 0, mh = 0, mw = 0;
int lx = 0, ly = 0, lw = 0, lh = 0;
int rx = 0, ry = 0, rw = 0, rh = 0;
float mfacts = 0, lfacts = 0, rfacts = 0;
int mtotal = 0, ltotal = 0, rtotal = 0;
int mrest = 0, lrest = 0, rrest = 0;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0)
return;
/* initialize areas */
mx = m->wx + ov;
my = m->wy + oh;
mh = m->wh - 2*oh - ih * ((!m->mastercount ? n : MIN(n, m->mastercount)) - 1);
mw = m->ww - 2*ov;
lh = m->wh - 2*oh - ih * (((n - m->mastercount) / 2) - 1);
rh = m->wh - 2*oh - ih * (((n - m->mastercount) / 2) - ((n - m->mastercount) % 2 ? 0 : 1));
if (m->mastercount && n > m->mastercount) {
/* go mfact box in the center if more than mastercount clients */
if (n - m->mastercount > 1) {
/* ||<-S->|<---M--->|<-S->|| */
mw = (m->ww - 2*ov - 2*iv) * m->mfact;
lw = (m->ww - mw - 2*ov - 2*iv) / 2;
rw = (m->ww - mw - 2*ov - 2*iv) - lw;
mx += lw + iv;
} else {
/* ||<---M--->|<-S->|| */
mw = (mw - iv) * m->mfact;
lw = 0;
rw = m->ww - mw - iv - 2*ov;
}
lx = m->wx + ov;
ly = m->wy + oh;
rx = mx + mw + iv;
ry = m->wy + oh;
}
/* calculate facts */
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
if (!m->mastercount || n < m->mastercount)
mfacts += c->cfact;
else if ((n - m->mastercount) % 2)
lfacts += c->cfact; // total factor of left hand stack area
else
rfacts += c->cfact; // total factor of right hand stack area
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
if (!m->mastercount || n < m->mastercount)
mtotal += mh * (c->cfact / mfacts);
else if ((n - m->mastercount) % 2)
ltotal += lh * (c->cfact / lfacts);
else
rtotal += rh * (c->cfact / rfacts);
mrest = mh - mtotal;
lrest = lh - ltotal;
rrest = rh - rtotal;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if (!m->mastercount || i < m->mastercount) {
/* mastercount clients are stacked vertically, in the center of the screen */
resize(c, mx, my, mw - (2*c->bw), mh * (c->cfact / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
my += HEIGHT(c) + ih;
} else {
/* stack clients are stacked vertically */
if ((i - m->mastercount) % 2 ) {
resize(c, lx, ly, lw - (2*c->bw), lh * (c->cfact / lfacts) + ((i - 2*m->mastercount) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
ly += HEIGHT(c) + ih;
} else {
resize(c, rx, ry, rw - (2*c->bw), rh * (c->cfact / rfacts) + ((i - 2*m->mastercount) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
ry += HEIGHT(c) + ih;
}
}
}
}
#if LAYOUT_CUSTOM
enum node_type_t
{

View file

@ -638,11 +638,8 @@ static void arrange_spiral(Monitor *m, int ax, int ay, int ah, int aw, int ih, i
static void arrange_tatami(Monitor *m, int ax, int ay, int ah, int aw, int ih, int iv, int n, int an, int ai);
static void tile(Monitor *m);
static void bstack(Monitor *m);
static void bstackhoriz(Monitor *m);
static void hgrid(Monitor *m);
static void ngrid(Monitor *m);
static void centeredmaster(Monitor *m);
#if LAYOUT_CUSTOM
static void custom(Monitor *m);
static void set_s_layout(const Arg *arg);
@ -1001,7 +998,6 @@ struct Pertag {
int ltaxis[LENGTH(tags) + 1][ltaxislast];
const Layout *ltidxs[LENGTH(tags) + 1][3]; /* matrix of tags and layouts indexes */
int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
unsigned int gaps[LENGTH(tags) + 1];
};
/* compile-time check if all tags fit into an unsigned int bit array. */
@ -2325,14 +2321,10 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
void
dragmfact(const Arg *arg)
{
if (!mousemfact)
return;
unsigned int n;
int py, px; /* pointer coordinates */
int ax, ay, aw, ah; /* area position, width and height */
int center = 0, horizontal = 0, mirror = 0, fixed = 0; /* layout configuration */
int py, px;
int ax, ay, aw, ah;
int center = 0, horizontal = 0, mirror = 0, fixed = 0;
double fact;
Monitor *m;
XEvent ev;
@ -2350,18 +2342,40 @@ dragmfact(const Arg *arg)
if (!n)
return;
else if (m->lt[m->sellt]->arrange == &centeredmaster && (fixed || n - m->mastercount > 1))
center = 1;
else if (m->lt[m->sellt]->arrange == &bstack)
horizontal = 1;
else if (m->lt[m->sellt]->arrange == &bstackhoriz)
horizontal = 1;
else if (m->lt[m->sellt]->arrange == &tile) {
int layout = m->ltaxis[layout];
if (layout < 0) {
mirror = 1;
layout *= -1;
}
if (layout > floatingmaster) {
layout -= floatingmaster;
fixed = 1;
}
if (layout == splithorizontal || layout == splithorizontaldualstack)
horizontal = 1;
else if (layout == splitcenteredvertical && (fixed || n - m->mastercount > 1))
center = 1;
else if (layout == floatingmaster) {
center = 1;
if (aw < ah)
horizontal = 1;
}
else if (layout == splitcenteredhorizontal) {
if (fixed || n - m->mastercount > 1)
center = 1;
horizontal = 1;
}
}
/* do not allow mfact to be modified under certain conditions */
if (!m->lt[m->sellt]->arrange /* floating layout */
|| (!fixed && m->mastercount && n <= m->mastercount) /* no master */
if (!m->lt[m->sellt]->arrange
|| (!fixed && m->mastercount && n <= m->mastercount)
|| m->lt[m->sellt]->arrange == &ngrid
|| m->lt[m->sellt]->arrange == &hgrid
|| (m->lt[m->sellt]->arrange == &tile && m->ltaxis[layout] == nosplit)
)
return;
return;
ay += oh;
ax += ov;
@ -2372,7 +2386,7 @@ dragmfact(const Arg *arg)
if (horizontal) {
px = ax + aw / 2;
py = ay + ah / 2 + (ah - 2*ih) * (m->mfact / 2.0) + ih / 2;
} else { /* vertical split */
} else { // vertical split
px = ax + aw / 2 + (aw - 2*iv) * m->mfact / 2.0 + iv / 2;
py = ay + ah / 2;
}
@ -2382,12 +2396,12 @@ dragmfact(const Arg *arg)
py = ay + (ah - ih) * (1.0 - m->mfact) + ih / 2;
else
py = ay + ((ah - ih) * m->mfact) + ih / 2;
} else { /* vertical split */
} else { // vertical split
if (mirror)
px = ax + (aw - iv) * (1.0 - m->mfact) + iv / 2;
else
px = ax + ((aw - iv) * m->mfact) + iv / 2;
py = ay + ah / 2;
py = ay + ah / 2;
}
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
@ -2428,6 +2442,22 @@ dragmfact(const Arg *arg)
fact = (double) (py - ay - ih / 2) / (double) (ah - ih);
else
fact = (double) (px - ax - iv / 2) / (double) (aw - iv);
if (center)
if (horizontal)
if (py - ay > ah / 2)
fact = (double) 1.0 - (ay + ah - py) * 2 / (double) ah;
else
fact = (double) 1.0 - (py - ay) * 2 / (double) ah;
else
if (px - ax > aw / 2)
fact = (double) 1.0 - (ax + aw - px) * 2 / (double) aw;
else
fact = (double) 1.0 - (px - ax) * 2 / (double) aw;
else
if (horizontal)
fact = (double) (py - ay) / (double) ah;
else
fact = (double) (px - ax) / (double) aw;
if (!center && mirror)
fact = 1.0 - fact;