diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2023-01-31 08:41:59 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2023-01-31 08:41:59 -0500 |
| commit | 7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93 (patch) | |
| tree | f4e4a6154c32e644b62d8379f69086b5927a8a19 /dwm.c | |
| parent | 593e3c3847a721afd3c7d88767037a7b13132a11 (diff) | |
| download | dwm-7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93.tar.gz dwm-7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93.tar.xz | |
Scaled center layout
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 70 |
1 files changed, 69 insertions, 1 deletions
@@ -130,6 +130,7 @@ struct Monitor { Monitor *next; Window barwin; const Layout *lt[2]; + float cFact; }; typedef struct { @@ -142,7 +143,7 @@ typedef struct { } Rule; /* function declarations */ -static void restart(Arg *arg); +static void restart(const Arg *arg); static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); static void arrange(Monitor *m); @@ -203,6 +204,7 @@ static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); +static void setcfact(const Arg *arg); static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); @@ -210,6 +212,8 @@ static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); +static void layoutCenterFact(Monitor *m, double fact); +static void layoutCenter(Monitor *m); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); @@ -652,6 +656,7 @@ createmon(void) m->topbar = topbar; m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; + m->cFact = cfact; strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); return m; } @@ -1545,6 +1550,21 @@ setmfact(const Arg *arg) arrange(selmon); } +/* arg > 1.0 will set cfact absolutely */ +void +setcfact(const Arg *arg) +{ + float f; + + if (!arg || !selmon->lt[selmon->sellt]->arrange) + return; + f = arg->f < 1.0 ? arg->f + selmon->cFact : arg->f - 1.0; + if (f < 0.05 || f > 0.95) + return; + selmon->cFact = f; + arrange(selmon); +} + void setup(void) { @@ -1713,6 +1733,54 @@ tile(Monitor *m) } } +/* Like "tile", but only take up a factor of the screen */ +void +layoutCenterFact(Monitor *m, double fact) +{ + unsigned int i, n, h, mw, my, ty; + Client *c; + + + // double fact = 0.9; + unsigned int lx, ly, lw, lh; + + lx = (m->ww - (m->ww * fact))/2; + ly = (m->wh - (m->wh * fact))/2; + lw = m->ww * fact; + lh = m->wh * fact; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + + printf("Number of clients: %d\n", n); + + if (n > m->nmaster) + mw = m->nmaster ? lw * m->mfact : 0; + else + mw = lw; + for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + h = (lh - my) / (MIN(n, m->nmaster) - i); + resize(c, lx, ly + my, mw - (2*c->bw), h - (2*c->bw), 0); + if (my + HEIGHT(c) < lh) + my += HEIGHT(c); + } else { + h = (lh - ty) / (n - i); + resize(c, lx + mw, ly + ty, lw - mw - (2*c->bw), h - (2*c->bw), 0); + if (ty + HEIGHT(c) < lh) + ty += HEIGHT(c); + } +} + +/* Simply utilize the factor attached to the monitor */ +void +layoutCenter(Monitor *m) +{ + layoutCenterFact(m, m->cFact); +} + + void togglebar(const Arg *arg) { |
