add layouts
This commit is contained in:
parent
c3752a4a96
commit
90cf2c303d
5 changed files with 210 additions and 0 deletions
|
@ -42,6 +42,10 @@ static const Layout layouts[] = {
|
||||||
{ "[]=", tile }, /* first entry is default */
|
{ "[]=", tile }, /* first entry is default */
|
||||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
{ "[M]", monocle },
|
{ "[M]", monocle },
|
||||||
|
{ "TTT", bstack },
|
||||||
|
{ "===", bstackhoriz },
|
||||||
|
{ "|M|", centeredmaster },
|
||||||
|
{ ">M>", centeredfloatingmaster },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* key definitions */
|
/* key definitions */
|
||||||
|
|
206
dwm.c
206
dwm.c
|
@ -148,7 +148,11 @@ static void arrange(Monitor *m);
|
||||||
static void arrangemon(Monitor *m);
|
static void arrangemon(Monitor *m);
|
||||||
static void attach(Client *c);
|
static void attach(Client *c);
|
||||||
static void attachstack(Client *c);
|
static void attachstack(Client *c);
|
||||||
|
static void bstack(Monitor *m);
|
||||||
|
static void bstackhoriz(Monitor *m);
|
||||||
static void buttonpress(XEvent *e);
|
static void buttonpress(XEvent *e);
|
||||||
|
static void centeredmaster(Monitor *m);
|
||||||
|
static void centeredfloatingmaster(Monitor *m);
|
||||||
static void checkotherwm(void);
|
static void checkotherwm(void);
|
||||||
static void cleanup(void);
|
static void cleanup(void);
|
||||||
static void cleanupmon(Monitor *mon);
|
static void cleanupmon(Monitor *mon);
|
||||||
|
@ -169,6 +173,7 @@ static void focus(Client *c);
|
||||||
static void focusin(XEvent *e);
|
static void focusin(XEvent *e);
|
||||||
static void focusmon(const Arg *arg);
|
static void focusmon(const Arg *arg);
|
||||||
static void focusstack(const Arg *arg);
|
static void focusstack(const Arg *arg);
|
||||||
|
static void gaplessgrid(Monitor *m);
|
||||||
static Atom getatomprop(Client *c, Atom prop);
|
static Atom getatomprop(Client *c, Atom prop);
|
||||||
static int getrootptr(int *x, int *y);
|
static int getrootptr(int *x, int *y);
|
||||||
static long getstate(Window w);
|
static long getstate(Window w);
|
||||||
|
@ -415,6 +420,68 @@ attachstack(Client *c)
|
||||||
c->mon->stack = c;
|
c->mon->stack = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bstack(Monitor *m) {
|
||||||
|
int w, h, mh, mx, tx, ty, tw;
|
||||||
|
unsigned int i, n;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||||
|
if (n == 0)
|
||||||
|
return;
|
||||||
|
if (n > m->nmaster) {
|
||||||
|
mh = m->nmaster ? m->mfact * m->wh : 0;
|
||||||
|
tw = m->ww / (n - m->nmaster);
|
||||||
|
ty = m->wy + mh;
|
||||||
|
} else {
|
||||||
|
mh = m->wh;
|
||||||
|
tw = m->ww;
|
||||||
|
ty = m->wy;
|
||||||
|
}
|
||||||
|
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||||
|
if (i < m->nmaster) {
|
||||||
|
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
||||||
|
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
||||||
|
mx += WIDTH(c);
|
||||||
|
} else {
|
||||||
|
h = m->wh - mh;
|
||||||
|
resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0);
|
||||||
|
if (tw != m->ww)
|
||||||
|
tx += WIDTH(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bstackhoriz(Monitor *m) {
|
||||||
|
int w, mh, mx, tx, ty, th;
|
||||||
|
unsigned int i, n;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||||
|
if (n == 0)
|
||||||
|
return;
|
||||||
|
if (n > m->nmaster) {
|
||||||
|
mh = m->nmaster ? m->mfact * m->wh : 0;
|
||||||
|
th = (m->wh - mh) / (n - m->nmaster);
|
||||||
|
ty = m->wy + mh;
|
||||||
|
} else {
|
||||||
|
th = mh = m->wh;
|
||||||
|
ty = m->wy;
|
||||||
|
}
|
||||||
|
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||||
|
if (i < m->nmaster) {
|
||||||
|
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
||||||
|
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
||||||
|
mx += WIDTH(c);
|
||||||
|
} else {
|
||||||
|
resize(c, tx, ty, m->ww - (2 * c->bw), th - (2 * c->bw), 0);
|
||||||
|
if (th != m->wh)
|
||||||
|
ty += HEIGHT(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buttonpress(XEvent *e)
|
buttonpress(XEvent *e)
|
||||||
{
|
{
|
||||||
|
@ -457,6 +524,109 @@ buttonpress(XEvent *e)
|
||||||
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
|
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
centeredmaster(Monitor *m)
|
||||||
|
{
|
||||||
|
unsigned int i, n, h, mw, mx, my, oty, ety, tw;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
/* count number of clients in the selected monitor */
|
||||||
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||||
|
if (n == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* initialize areas */
|
||||||
|
mw = m->ww;
|
||||||
|
mx = 0;
|
||||||
|
my = 0;
|
||||||
|
tw = mw;
|
||||||
|
|
||||||
|
if (n > m->nmaster) {
|
||||||
|
/* go mfact box in the center if more than nmaster clients */
|
||||||
|
mw = m->nmaster ? m->ww * m->mfact : 0;
|
||||||
|
tw = m->ww - mw;
|
||||||
|
|
||||||
|
if (n - m->nmaster > 1) {
|
||||||
|
/* only one client */
|
||||||
|
mx = (m->ww - mw) / 2;
|
||||||
|
tw = (m->ww - mw) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oty = 0;
|
||||||
|
ety = 0;
|
||||||
|
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||||
|
if (i < m->nmaster) {
|
||||||
|
/* nmaster clients are stacked vertically, in the center
|
||||||
|
* of the screen */
|
||||||
|
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
|
||||||
|
resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw),
|
||||||
|
h - (2*c->bw), 0);
|
||||||
|
my += HEIGHT(c);
|
||||||
|
} else {
|
||||||
|
/* stack clients are stacked vertically */
|
||||||
|
if ((i - m->nmaster) % 2 ) {
|
||||||
|
h = (m->wh - ety) / ( (1 + n - i) / 2);
|
||||||
|
resize(c, m->wx, m->wy + ety, tw - (2*c->bw),
|
||||||
|
h - (2*c->bw), 0);
|
||||||
|
ety += HEIGHT(c);
|
||||||
|
} else {
|
||||||
|
h = (m->wh - oty) / ((1 + n - i) / 2);
|
||||||
|
resize(c, m->wx + mx + mw, m->wy + oty,
|
||||||
|
tw - (2*c->bw), h - (2*c->bw), 0);
|
||||||
|
oty += HEIGHT(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
centeredfloatingmaster(Monitor *m)
|
||||||
|
{
|
||||||
|
unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
/* count number of clients in the selected monitor */
|
||||||
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||||
|
if (n == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* initialize nmaster area */
|
||||||
|
if (n > m->nmaster) {
|
||||||
|
/* go mfact box in the center if more than nmaster clients */
|
||||||
|
if (m->ww > m->wh) {
|
||||||
|
mw = m->nmaster ? m->ww * m->mfact : 0;
|
||||||
|
mh = m->nmaster ? m->wh * 0.9 : 0;
|
||||||
|
} else {
|
||||||
|
mh = m->nmaster ? m->wh * m->mfact : 0;
|
||||||
|
mw = m->nmaster ? m->ww * 0.9 : 0;
|
||||||
|
}
|
||||||
|
mx = mxo = (m->ww - mw) / 2;
|
||||||
|
my = myo = (m->wh - mh) / 2;
|
||||||
|
} else {
|
||||||
|
/* go fullscreen if all clients are in the master area */
|
||||||
|
mh = m->wh;
|
||||||
|
mw = m->ww;
|
||||||
|
mx = mxo = 0;
|
||||||
|
my = myo = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||||
|
if (i < m->nmaster) {
|
||||||
|
/* nmaster clients are stacked horizontally, in the center
|
||||||
|
* of the screen */
|
||||||
|
w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i);
|
||||||
|
resize(c, m->wx + mx, m->wy + my, w - (2*c->bw),
|
||||||
|
mh - (2*c->bw), 0);
|
||||||
|
mx += WIDTH(c);
|
||||||
|
} else {
|
||||||
|
/* stack clients are stacked horizontally */
|
||||||
|
w = (m->ww - tx) / (n - i);
|
||||||
|
resize(c, m->wx + tx, m->wy, w - (2*c->bw),
|
||||||
|
m->wh - (2*c->bw), 0);
|
||||||
|
tx += WIDTH(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
checkotherwm(void)
|
checkotherwm(void)
|
||||||
{
|
{
|
||||||
|
@ -861,6 +1031,42 @@ focusstack(const Arg *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gaplessgrid(Monitor *m) {
|
||||||
|
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
|
||||||
|
if(n == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* grid dimensions */
|
||||||
|
for(cols = 0; cols <= n/2; cols++)
|
||||||
|
if(cols*cols >= n)
|
||||||
|
break;
|
||||||
|
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
|
||||||
|
cols = 2;
|
||||||
|
rows = n/cols;
|
||||||
|
|
||||||
|
/* window geometries */
|
||||||
|
cw = cols ? m->ww / cols : m->ww;
|
||||||
|
cn = 0; /* current column number */
|
||||||
|
rn = 0; /* current row number */
|
||||||
|
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
|
||||||
|
if(i/rows + 1 > cols - n%cols)
|
||||||
|
rows = n/cols + 1;
|
||||||
|
ch = rows ? m->wh / rows : m->wh;
|
||||||
|
cx = m->wx + cn*cw;
|
||||||
|
cy = m->wy + rn*ch;
|
||||||
|
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
|
||||||
|
rn++;
|
||||||
|
if(rn >= rows) {
|
||||||
|
rn = 0;
|
||||||
|
cn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Atom
|
Atom
|
||||||
getatomprop(Client *c, Atom prop)
|
getatomprop(Client *c, Atom prop)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue