commit adc3649bf17590397b5c1030a9d01ef9d4cab487
parent f09418bbb6651ab4c299cfefbe1d18de401f630e
Author: mpizzzle <michael.770211@gmail.com>
Date: Tue, 12 May 2020 18:50:54 +0100
Patched in gaps, fibonacci layout, Makefile change + a few minor config changes
Diffstat:
| M | Makefile | | | 5 | +---- |
| M | config.def.h | | | 57 | +++++++++++++++++++++++++++++++++++++++++++-------------- |
| M | dwm.c | | | 154 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
| A | fibonacci.c | | | 79 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 264 insertions(+), 31 deletions(-)
diff --git a/Makefile b/Makefile
@@ -17,10 +17,7 @@ options:
.c.o:
${CC} -c ${CFLAGS} $<
-${OBJ}: config.h config.mk
-
-config.h:
- cp config.def.h $@
+${OBJ}: config.def.h config.mk
dwm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
diff --git a/config.def.h b/config.def.h
@@ -1,12 +1,17 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
-static const unsigned int borderpx = 1; /* border pixel of windows */
+static const unsigned int borderpx = 0; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
+static const unsigned int gappih = 15; /* horiz inner gap between windows */
+static const unsigned int gappiv = 15; /* vert inner gap between windows */
+static const unsigned int gappoh = 15; /* horiz outer gap between windows and screen edge */
+static const unsigned int gappov = 15; /* vert outer gap between windows and screen edge */
+static const int smartgaps = 1; /* 1 means no outer gap when there is only one window */
static const int showbar = 1; /* 0 means no bar */
-static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "monospace:size=10" };
-static const char dmenufont[] = "monospace:size=10";
+static const int topbar = 0; /* 0 means bottom bar */
+static const char *fonts[] = { "monospace:size=11" };
+static const char dmenufont[] = "monospace:size=11";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
@@ -19,7 +24,7 @@ static const char *colors[][3] = {
};
/* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+static const char *tags[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九" };
static const Rule rules[] = {
/* xprop(1):
@@ -32,19 +37,22 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static const float mfact = 0.50; /* factor of master 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 resizehints = 0; /* 1 means respect size hints in tiled resizals */
+#include "fibonacci.c"
static const Layout layouts[] = {
/* symbol arrange function */
- { "[]=", tile }, /* first entry is default */
+ { "[=]", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "[@]", spiral },
+ { "[\\]", dwindle },
};
/* key definitions */
-#define MODKEY Mod1Mask
+#define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
@@ -57,12 +65,12 @@ static const Layout layouts[] = {
/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
-static const char *termcmd[] = { "st", NULL };
+static const char *termcmd[] = { "urxvt", NULL };
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
+ { MODKEY, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
@@ -70,12 +78,31 @@ static Key keys[] = {
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
- { MODKEY, XK_Return, zoom, {0} },
+/* { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, */
+/* { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, */
+/* { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, */
+/* { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, */
+/* { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, */
+/* { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, */
+/* { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, */
+/* { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, */
+/* { MODKEY, XK_y, incrihgaps, {.i = +1 } }, */
+/* { MODKEY, XK_o, incrihgaps, {.i = -1 } }, */
+/* { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, */
+/* { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, */
+/* { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, */
+/* { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, */
+/* { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, */
+/* { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, */
+ { MODKEY|ShiftMask, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
- { MODKEY|ShiftMask, XK_c, killclient, {0} },
+ { MODKEY|ShiftMask, XK_q, killclient, {0} },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_r, setlayout, {.v = &layouts[3]} },
+ { MODKEY|ShiftMask, XK_r, setlayout, {.v = &layouts[4]} },
+ { MODKEY, XK_y, spawn, SHCMD(". ~/.scripts/wallpapers.sh ~/wallpapers &") },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
@@ -84,6 +111,8 @@ static Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_l, spawn, SHCMD(". ~/.scripts/lock.sh &") },
+ { MODKEY, XK_Print, spawn, SHCMD("scrot") },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
@@ -93,7 +122,7 @@ static Key keys[] = {
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
- { MODKEY|ShiftMask, XK_q, quit, {0} },
+ { MODKEY|ShiftMask, XK_e, quit, {0} },
};
/* button definitions */
diff --git a/dwm.c b/dwm.c
@@ -119,6 +119,10 @@ struct Monitor {
int by; /* bar geometry */
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
+ int gappih; /* horizontal gap between windows */
+ int gappiv; /* vertical gap between windows */
+ int gappoh; /* horizontal outer gaps */
+ int gappov; /* vertical outer gaps */
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
@@ -200,6 +204,16 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
+/* static void setgaps(int oh, int ov, int ih, int iv); */
+/* static void incrgaps(const Arg *arg); */
+/* static void incrigaps(const Arg *arg); */
+/* static void incrogaps(const Arg *arg); */
+/* static void incrohgaps(const Arg *arg); */
+/* static void incrovgaps(const Arg *arg); */
+/* static void incrihgaps(const Arg *arg); */
+/* static void incrivgaps(const Arg *arg); */
+/* static void togglegaps(const Arg *arg); */
+/* static void defaultgaps(const Arg *arg); */
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -241,6 +255,7 @@ static char stext[256];
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh, blw = 0; /* bar geometry */
+static int enablegaps = 1; /* enables gaps, used by togglegaps */
static int lrpad; /* sum of left and right padding for text */
static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
@@ -270,7 +285,7 @@ static Monitor *mons, *selmon;
static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */
-#include "config.h"
+#include "config.def.h"
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -639,6 +654,10 @@ createmon(void)
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
+ m->gappih = gappih;
+ m->gappiv = gappiv;
+ m->gappoh = gappoh;
+ m->gappov = gappov;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
@@ -1498,6 +1517,111 @@ setfullscreen(Client *c, int fullscreen)
}
}
+/* void
+setgaps(int oh, int ov, int ih, int iv)
+{
+ if (oh < 0) oh = 0;
+ if (ov < 0) ov = 0;
+ if (ih < 0) ih = 0;
+ if (iv < 0) iv = 0;
+
+ selmon->gappoh = oh;
+ selmon->gappov = ov;
+ selmon->gappih = ih;
+ selmon->gappiv = iv;
+ arrange(selmon);
+}
+
+void
+togglegaps(const Arg *arg)
+{
+ enablegaps = !enablegaps;
+ arrange(selmon);
+}
+
+void
+defaultgaps(const Arg *arg)
+{
+ setgaps(gappoh, gappov, gappih, gappiv);
+}
+
+void
+incrgaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh + arg->i,
+ selmon->gappov + arg->i,
+ selmon->gappih + arg->i,
+ selmon->gappiv + arg->i
+ );
+}
+
+void
+incrigaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh,
+ selmon->gappov,
+ selmon->gappih + arg->i,
+ selmon->gappiv + arg->i
+ );
+}
+
+void
+incrogaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh + arg->i,
+ selmon->gappov + arg->i,
+ selmon->gappih,
+ selmon->gappiv
+ );
+}
+
+void
+incrohgaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh + arg->i,
+ selmon->gappov,
+ selmon->gappih,
+ selmon->gappiv
+ );
+}
+
+void
+incrovgaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh,
+ selmon->gappov + arg->i,
+ selmon->gappih,
+ selmon->gappiv
+ );
+}
+
+void
+incrihgaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh,
+ selmon->gappov,
+ selmon->gappih + arg->i,
+ selmon->gappiv
+ );
+}
+
+void
+incrivgaps(const Arg *arg)
+{
+ setgaps(
+ selmon->gappoh,
+ selmon->gappov,
+ selmon->gappih,
+ selmon->gappiv + arg->i
+ );
+} */
+
void
setlayout(const Arg *arg)
{
@@ -1674,28 +1798,32 @@ tagmon(const Arg *arg)
void
tile(Monitor *m)
{
- unsigned int i, n, h, mw, my, ty;
+ unsigned int i, n, h, r, oe = enablegaps, ie = enablegaps, mw, my, ty;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
+ if (smartgaps == n) {
+ oe = 0; // outer gaps disabled
+ }
+
if (n > m->nmaster)
- mw = m->nmaster ? m->ww * m->mfact : 0;
+ mw = m->nmaster ? (m->ww + m->gappiv*ie) * m->mfact : 0;
else
- mw = m->ww;
- for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ mw = m->ww - 2*m->gappov*oe + m->gappiv*ie;
+ for (i = 0, my = ty = m->gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
- h = (m->wh - my) / (MIN(n, m->nmaster) - i);
- resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
- if (my + HEIGHT(c) < m->wh)
- my += HEIGHT(c);
+ r = MIN(n, m->nmaster) - i;
+ h = (m->wh - my - m->gappoh*oe - m->gappih*ie * (r - 1)) / r;
+ resize(c, m->wx + m->gappov*oe, m->wy + my, mw - (2*c->bw) - m->gappiv*ie, h - (2*c->bw), 0);
+ my += HEIGHT(c) + m->gappih*ie;
} else {
- h = (m->wh - ty) / (n - i);
- resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
- if (ty + HEIGHT(c) < m->wh)
- ty += HEIGHT(c);
+ r = n - i;
+ h = (m->wh - ty - m->gappoh*oe - m->gappih*ie * (r - 1)) / r;
+ resize(c, m->wx + mw + m->gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappov*oe, h - (2*c->bw), 0);
+ ty += HEIGHT(c) + m->gappih*ie;
}
}
diff --git a/fibonacci.c b/fibonacci.c
@@ -0,0 +1,79 @@
+void
+fibonacci(Monitor *mon, int s) {
+ unsigned int i, n, nx, ny, nw, nh, oe, ie;
+ int oh, ov, ih, iv;
+ Client *c;
+
+ oe = ie = enablegaps;
+
+ for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
+ if(n == 0) {
+ return;
+ }
+ if (smartgaps && n == 1) {
+ oe = 0;
+ }
+
+ oh = mon->gappoh*oe;
+ ov = mon->gappov*oe;
+ ih = mon->gappih*ie;
+ iv = mon->gappiv*ie;
+
+ nx = mon->wx + ov;
+ ny = oh;
+ nw = mon->ww - 2*ov;
+ nh = mon->wh - 2*oh;
+
+ for (i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
+ if ((i % 2 && nh / 2 > 2*c->bw)
+ || (!(i % 2) && nw / 2 > 2*c->bw)) {
+ if (i < n - 1) {
+ if (i % 2)
+ nh = (nh - ih) / 2;
+ else
+ nw = (nw - iv) / 2;
+
+ if ((i % 4) == 2 && !s)
+ nx += nw + iv;
+ else if ((i % 4) == 3 && !s)
+ ny += nh + ih;
+ }
+ if ((i % 4) == 0) {
+ if (s)
+ ny += nh + ih;
+ else
+ ny -= nh + ih;
+ }
+ else if ((i % 4) == 1)
+ nx += nw + iv;
+ else if ((i % 4) == 2)
+ ny += nh + ih;
+ else if ((i % 4) == 3) {
+ if (s)
+ nx += nw + iv;
+ else
+ nx -= nw + iv;
+ }
+ if (i == 0) {
+ if (n != 1)
+ nw = (mon->ww - 2*ov - iv) * mon->mfact;
+ ny = mon->wy + oh;
+ }
+ else if (i == 1)
+ nw = mon->ww - nw - iv - 2*ov;
+ i++;
+ }
+
+ resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
+ }
+}
+
+void
+dwindle(Monitor *mon) {
+ fibonacci(mon, 1);
+}
+
+void
+spiral(Monitor *mon) {
+ fibonacci(mon, 0);
+}