aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-31 08:41:59 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-31 08:41:59 -0500
commit7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93 (patch)
treef4e4a6154c32e644b62d8379f69086b5927a8a19
parent593e3c3847a721afd3c7d88767037a7b13132a11 (diff)
downloaddwm-7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93.tar.gz
dwm-7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93.tar.xz
Scaled center layout
-rw-r--r--config.def.h5
-rw-r--r--dwm.c70
2 files changed, 74 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h
index aed3eb3..fa16868 100644
--- a/config.def.h
+++ b/config.def.h
@@ -33,6 +33,7 @@ static const Rule rules[] = {
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static const float cfact = 0.5; /* factor of center area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
@@ -42,6 +43,7 @@ static const Layout layouts[] = {
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "[C]", layoutCenter },
};
/* key definitions */
@@ -77,6 +79,9 @@ static const Key keys[] = {
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_c, setlayout, {.v = &layouts[3]} },
+ { MODKEY, XK_equal, setcfact, {.f = +0.05} },
+ { MODKEY, XK_minus, setcfact, {.f = -0.05} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
diff --git a/dwm.c b/dwm.c
index 8bcf0da..f9719ac 100644
--- a/dwm.c
+++ b/dwm.c
@@ -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)
{