commit f728ac3d2484290682e07e341329034970406ff8
parent 6a0b36d21263ae43433f96d53faed3f15c3e7056
Author: miksa234 <milutin@popovic.xyz>
Date: Sun, 14 Mar 2021 20:08:36 +0100
added xresources patch
Diffstat:
| M | config.def.h | | | 64 | ++++++++++++++++++++++++++++++++++++++++++---------------------- |
| M | config.h | | | 64 | ++++++++++++++++++++++++++++++++++++++++++---------------------- |
| M | drw.c | | | 2 | +- |
| M | drw.h | | | 2 | +- |
| M | dwm | | | 0 | |
| M | dwm.c | | | 74 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
| M | dwm.o | | | 0 | |
7 files changed, 159 insertions(+), 47 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -4,25 +4,25 @@
#define TERMCLASS "St"
/* appearance */
-static const unsigned int borderpx = 2; /* border pixel of windows */
-static const unsigned int snap = 32; /* snap pixel */
+static unsigned int borderpx = 2; /* border pixel of windows */
+static unsigned int snap = 32; /* snap pixel */
static const unsigned int gappih = 10; /* horiz inner gap between windows */
static const unsigned int gappiv = 5; /* vert inner gap between windows */
static const unsigned int gappoh = 5; /* horiz outer gap between windows and screen edge */
static const unsigned int gappov = 5; /* vert outer gap between windows and screen edge */
static int smartgaps = 0; /* 1 means no outer gap when there is only one window */
static const int swallowfloating = 0; /* 1 means swallow floating windows by default */
-static const int showbar = 1; /* 0 means no bar */
-static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "Hack:pixelsize=17:antialias=true:autohint=true:spacing=false",
- "Symbola:pixelsize=17" };
-static const char normfgcolor[] = "#6c6c93";
-static const char normbgcolor[] = "#263238";
-static const char normbordercolor[] = "#263238";
-static const char selfgcolor[] = "#000000";
-static const char selbgcolor[] = "#606F88";
-static const char selbordercolor[] = "#6c6c93";
-static const char *colors[][3] = {
+static int showbar = 1; /* 0 means no bar */
+static int topbar = 1; /* 0 means bottom bar */
+static const char *fonts[] = { "Hack:pixelsize=15:antialias=true:autohint=true:spacing=false",
+ "Symbola:pixelsize=15" };
+static char normfgcolor[] = "#6c6c93";
+static char normbgcolor[] = "#263238";
+static char normbordercolor[] = "#263238";
+static char selfgcolor[] = "#000000";
+static char selbgcolor[] = "#606F88";
+static char selbordercolor[] = "#6c6c93";
+static char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor},
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor},
@@ -44,13 +44,33 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.55; /* 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 float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static int nmaster = 1; /* number of clients in master area */
+static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
#include "vanitygaps.c"
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "normbgcolor", STRING, &normbgcolor },
+ { "normbordercolor", STRING, &normbordercolor },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "selbordercolor", STRING, &selbordercolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "borderpx", INTEGER, &borderpx },
+ { "snap", INTEGER, &snap },
+ { "showbar", INTEGER, &showbar },
+ { "topbar", INTEGER, &topbar },
+ { "nmaster", INTEGER, &nmaster },
+ { "resizehints", INTEGER, &resizehints },
+ { "mfact", FLOAT, &mfact },
+};
+
+
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
@@ -105,10 +125,10 @@ static Key keys[] = {
{ MODKEY, XK_m, spawn, SHCMD(TERMINAL " -e neomutt") },
{ MODKEY|ShiftMask, XK_w, spawn, SHCMD(TERMINAL " -e sudo nmtui") },
{ MODKEY, XK_w, spawn, SHCMD("xdotool key Super_L+9 && spotify") },
- { MODKEY, XK_F1, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; toggle volume") },
- { MODKEY, XK_F2, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ -5%") },
- { MODKEY, XK_F3, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ +5%") },
- { MODKEY, XK_F4, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; toggle sink") },
+ { MODKEY, XK_F1, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; toggle volume") },
+ { MODKEY, XK_F2, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ -5%") },
+ { MODKEY, XK_F3, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ +5%") },
+ { MODKEY, XK_F4, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; toggle sink") },
{ MODKEY, XK_F5, spawn, SHCMD("sudo xbacklight -dec 10") },
{ MODKEY, XK_F6, spawn, SHCMD("sudo xbacklight -inc 10") },
{ MODKEY, XK_Return, spawn, {.v = termcmd } },
@@ -119,7 +139,7 @@ static Key keys[] = {
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_o, incnmaster, {.i = -1 } },
{ MODKEY, XK_comma, setmfact, {.f = -0.05} },
- { MODKEY, XK_period, setmfact, {.f = +0.05} },
+{ MODKEY, XK_period, setmfact, {.f = +0.05} },
{ MODKEY|Mod1Mask, XK_k, incrgaps, {.i = +5 } },
{ MODKEY|Mod1Mask, XK_j, incrgaps, {.i = -5 } },
{ MODKEY|Mod1Mask, XK_0, togglegaps, {0} },
@@ -178,7 +198,7 @@ static Button buttons[] = {
{ ClkStatusText, ShiftMask, Button1, sigdwmblocks, {.i = 6} },
{ ClkStatusText, ShiftMask, Button3, spawn, SHCMD(TERMINAL " -e nvim ~/.local/src/dwmblocks/config.h") },
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
+ { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[13]} },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
diff --git a/config.h b/config.h
@@ -4,25 +4,25 @@
#define TERMCLASS "St"
/* appearance */
-static const unsigned int borderpx = 2; /* border pixel of windows */
-static const unsigned int snap = 32; /* snap pixel */
+static unsigned int borderpx = 2; /* border pixel of windows */
+static unsigned int snap = 32; /* snap pixel */
static const unsigned int gappih = 10; /* horiz inner gap between windows */
static const unsigned int gappiv = 5; /* vert inner gap between windows */
static const unsigned int gappoh = 5; /* horiz outer gap between windows and screen edge */
static const unsigned int gappov = 5; /* vert outer gap between windows and screen edge */
static int smartgaps = 0; /* 1 means no outer gap when there is only one window */
static const int swallowfloating = 0; /* 1 means swallow floating windows by default */
-static const int showbar = 1; /* 0 means no bar */
-static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "Hack:pixelsize=17:antialias=true:autohint=true:spacing=false",
- "Symbola:pixelsize=17" };
-static const char normfgcolor[] = "#6c6c93";
-static const char normbgcolor[] = "#263238";
-static const char normbordercolor[] = "#263238";
-static const char selfgcolor[] = "#000000";
-static const char selbgcolor[] = "#606F88";
-static const char selbordercolor[] = "#6c6c93";
-static const char *colors[][3] = {
+static int showbar = 1; /* 0 means no bar */
+static int topbar = 1; /* 0 means bottom bar */
+static const char *fonts[] = { "Hack:pixelsize=15:antialias=true:autohint=true:spacing=false",
+ "Symbola:pixelsize=15" };
+static char normfgcolor[] = "#6c6c93";
+static char normbgcolor[] = "#263238";
+static char normbordercolor[] = "#263238";
+static char selfgcolor[] = "#000000";
+static char selbgcolor[] = "#606F88";
+static char selbordercolor[] = "#6c6c93";
+static char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor},
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor},
@@ -44,13 +44,33 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.55; /* 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 float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static int nmaster = 1; /* number of clients in master area */
+static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
#include "vanitygaps.c"
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "normbgcolor", STRING, &normbgcolor },
+ { "normbordercolor", STRING, &normbordercolor },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "selbordercolor", STRING, &selbordercolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "borderpx", INTEGER, &borderpx },
+ { "snap", INTEGER, &snap },
+ { "showbar", INTEGER, &showbar },
+ { "topbar", INTEGER, &topbar },
+ { "nmaster", INTEGER, &nmaster },
+ { "resizehints", INTEGER, &resizehints },
+ { "mfact", FLOAT, &mfact },
+};
+
+
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
@@ -105,10 +125,10 @@ static Key keys[] = {
{ MODKEY, XK_m, spawn, SHCMD(TERMINAL " -e neomutt") },
{ MODKEY|ShiftMask, XK_w, spawn, SHCMD(TERMINAL " -e sudo nmtui") },
{ MODKEY, XK_w, spawn, SHCMD("xdotool key Super_L+9 && spotify") },
- { MODKEY, XK_F1, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; toggle volume") },
- { MODKEY, XK_F2, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ -5%") },
- { MODKEY, XK_F3, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ +5%") },
- { MODKEY, XK_F4, spawn, SHCMD("pkill -RTMIN+5 dwmblocks ; toggle sink") },
+ { MODKEY, XK_F1, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; toggle volume") },
+ { MODKEY, XK_F2, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ -5%") },
+ { MODKEY, XK_F3, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; pactl set-sink-volume @DEFAULT_SINK@ +5%") },
+ { MODKEY, XK_F4, spawn, SHCMD("pkill -RTMIN+8 dwmblocks ; toggle sink") },
{ MODKEY, XK_F5, spawn, SHCMD("sudo xbacklight -dec 10") },
{ MODKEY, XK_F6, spawn, SHCMD("sudo xbacklight -inc 10") },
{ MODKEY, XK_Return, spawn, {.v = termcmd } },
@@ -119,7 +139,7 @@ static Key keys[] = {
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_o, incnmaster, {.i = -1 } },
{ MODKEY, XK_comma, setmfact, {.f = -0.05} },
- { MODKEY, XK_period, setmfact, {.f = +0.05} },
+{ MODKEY, XK_period, setmfact, {.f = +0.05} },
{ MODKEY|Mod1Mask, XK_k, incrgaps, {.i = +5 } },
{ MODKEY|Mod1Mask, XK_j, incrgaps, {.i = -5 } },
{ MODKEY|Mod1Mask, XK_0, togglegaps, {0} },
@@ -178,7 +198,7 @@ static Button buttons[] = {
{ ClkStatusText, ShiftMask, Button1, sigdwmblocks, {.i = 6} },
{ ClkStatusText, ShiftMask, Button3, spawn, SHCMD(TERMINAL " -e nvim ~/.local/src/dwmblocks/config.h") },
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
+ { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[13]} },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
diff --git a/drw.c b/drw.c
@@ -207,7 +207,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
Clr *
-drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
+drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
{
size_t i;
Clr *ret;
diff --git a/drw.h b/drw.h
@@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
-Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
+Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);
diff --git a/dwm b/dwm
Binary files differ.
diff --git a/dwm.c b/dwm.c
@@ -36,6 +36,7 @@
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -162,6 +163,19 @@ typedef struct {
int monitor;
} Rule;
+/* Xresources preferences */
+enum resource_type {
+ STRING = 0,
+ INTEGER = 1,
+ FLOAT = 2
+};
+
+typedef struct {
+ char *name;
+ enum resource_type type;
+ void *dst;
+} ResourcePref;
+
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -263,6 +277,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void load_xresources(void);
+static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
@@ -1712,7 +1728,7 @@ setmfact(const Arg *arg)
if (!arg || !selmon->lt[selmon->sellt]->arrange)
return;
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
- if (f < 0.1 || f > 0.9)
+ if (f < 0.05 || f > 0.95)
return;
selmon->mfact = f;
arrange(selmon);
@@ -2515,6 +2531,60 @@ zoom(const Arg *arg)
pop(c);
}
+void
+resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
+{
+ char *sdst = NULL;
+ int *idst = NULL;
+ float *fdst = NULL;
+
+ sdst = dst;
+ idst = dst;
+ fdst = dst;
+
+ char fullname[256];
+ char *type;
+ XrmValue ret;
+
+ snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
+ fullname[sizeof(fullname) - 1] = '\0';
+
+ XrmGetResource(db, fullname, "*", &type, &ret);
+ if (!(ret.addr == NULL || strncmp("String", type, 64)))
+ {
+ switch (rtype) {
+ case STRING:
+ strcpy(sdst, ret.addr);
+ break;
+ case INTEGER:
+ *idst = strtoul(ret.addr, NULL, 10);
+ break;
+ case FLOAT:
+ *fdst = strtof(ret.addr, NULL);
+ break;
+ }
+ }
+}
+
+void
+load_xresources(void)
+{
+ Display *display;
+ char *resm;
+ XrmDatabase db;
+ ResourcePref *p;
+
+ display = XOpenDisplay(NULL);
+ resm = XResourceManagerString(display);
+ if (!resm)
+ return;
+
+ db = XrmGetStringDatabase(resm);
+ for (p = resources; p < resources + LENGTH(resources); p++)
+ resource_load(db, p->name, p->type, p->dst);
+ XCloseDisplay(display);
+}
+
int
main(int argc, char *argv[])
{
@@ -2529,6 +2599,8 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
+ XrmInitialize();
+ load_xresources();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec ps", NULL) == -1)
diff --git a/dwm.o b/dwm.o
Binary files differ.