sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit af463df202bf60b580c62c3dd047a85b573c5b4e
parent 2ab65c262dc73c64dd23280d353e436af04165c7
Author: Petr Schmied <7877707+JBlackN@users.noreply.github.com>
Date:   Tue,  4 Sep 2018 13:55:25 +0200

[dwm] xrdb patch (load colors from .Xresources)

Diffstat:
dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
dwm.suckless.org/patches/xrdb/index.md | 30++++++++++++++++++++++++++++++
2 files changed, 184 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff b/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff @@ -0,0 +1,154 @@ +From 920617a80d3009fe01843f1f7d36d3a92d19c2fa Mon Sep 17 00:00:00 2001 +From: Petr Schmied +Date: Tue, 28 Aug 2018 21:08:53 +0200 +Subject: [PATCH] XRDB + +--- + config.def.h | 14 ++++++++------ + dwm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 60 insertions(+), 6 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 7054c06..e2f2634 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -5,12 +5,12 @@ static const char *fonts[] = { + "monospace:size=10" + }; + static const char dmenufont[] = "monospace:size=10"; +-static const char normbordercolor[] = "#444444"; +-static const char normbgcolor[] = "#222222"; +-static const char normfgcolor[] = "#bbbbbb"; +-static const char selbordercolor[] = "#005577"; +-static const char selbgcolor[] = "#005577"; +-static const char selfgcolor[] = "#eeeeee"; ++static char normbordercolor[] = "#444444"; ++static char normbgcolor[] = "#222222"; ++static char normfgcolor[] = "#bbbbbb"; ++static char selbordercolor[] = "#005577"; ++static char selbgcolor[] = "#005577"; ++static char selfgcolor[] = "#eeeeee"; + static const unsigned int borderpx = 1; /* border pixel of windows */ + static const unsigned int snap = 32; /* snap pixel */ + static const int showbar = 1; /* 0 means no bar */ +@@ -82,6 +82,7 @@ static Key keys[] = { + { MODKEY, XK_period, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, + { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, ++ { MODKEY, XK_F5, xrdb, {.v = NULL } }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) +@@ -111,3 +112,4 @@ static Button buttons[] = { + { ClkTagBar, MODKEY, Button3, toggletag, {0} }, + }; + ++static const char *xres = "/home/USERNAME/.Xresources"; +diff --git a/dwm.c b/dwm.c +index 0362114..0f257ec 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -35,6 +35,7 @@ + #include <X11/Xatom.h> + #include <X11/Xlib.h> + #include <X11/Xproto.h> ++#include <X11/Xresource.h> + #include <X11/Xutil.h> + #ifdef XINERAMA + #include <X11/extensions/Xinerama.h> +@@ -56,6 +57,21 @@ + #define HEIGHT(X) ((X)->h + 2 * (X)->bw) + #define TAGMASK ((1 << LENGTH(tags)) - 1) + #define TEXTW(X) (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h) ++#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \ ++ if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \ ++ int i = 1; \ ++ for (; i <= 6; i++) { \ ++ if (value.addr[i] < 48) break; \ ++ if (value.addr[i] > 57 && value.addr[i] < 65) break; \ ++ if (value.addr[i] > 70 && value.addr[i] < 97) break; \ ++ if (value.addr[i] > 102) break; \ ++ } \ ++ if (i == 7) { \ ++ strncpy(V, value.addr, 7); \ ++ V[7] = '\0'; \ ++ } \ ++ } \ ++ } + + /* enums */ + enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ +@@ -178,6 +194,7 @@ static void grabkeys(void); + static void incnmaster(const Arg *arg); + static void keypress(XEvent *e); + static void killclient(const Arg *arg); ++static void loadxrdb(void); + static void manage(Window w, XWindowAttributes *wa); + static void mappingnotify(XEvent *e); + static void maprequest(XEvent *e); +@@ -232,6 +249,7 @@ static Monitor *wintomon(Window w); + static int xerror(Display *dpy, XErrorEvent *ee); + static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); ++static void xrdb(const Arg *arg); + static void zoom(const Arg *arg); + + /* variables */ +@@ -1029,6 +1047,23 @@ killclient(const Arg *arg) + } + } + ++void ++loadxrdb() ++{ ++ XrmDatabase xrdb = XrmGetFileDatabase(xres); ++ if (xrdb != NULL) { ++ char *type; ++ XrmValue value; ++ ++ XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor); ++ XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor); ++ XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor); ++ XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor); ++ XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor); ++ XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor); ++ } ++} ++ + void + manage(Window w, XWindowAttributes *wa) + { +@@ -2106,6 +2141,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee) + return -1; + } + ++void ++xrdb(const Arg *arg) ++{ ++ loadxrdb(); ++ ++ scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor); ++ scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor); ++ scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor); ++ scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor); ++ scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor); ++ scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor); ++ ++ focus(NULL); ++ arrange(NULL); ++} ++ + void + zoom(const Arg *arg) + { +@@ -2132,6 +2183,7 @@ main(int argc, char *argv[]) + if (!(dpy = XOpenDisplay(NULL))) + die("dwm: cannot open display\n"); + checkotherwm(); ++ loadxrdb(); + setup(); + scan(); + run(); +-- +2.16.4 + diff --git a/dwm.suckless.org/patches/xrdb/index.md b/dwm.suckless.org/patches/xrdb/index.md @@ -0,0 +1,30 @@ +xrdb +==== + +Description +----------- + +Allows dwm to read colors from `.Xresources` at run time. + +After applying the patch, don't forget to update your `config.h` file and fill in path to your `.Xresources` there (`xres` variable). + +X resources used: + + dwm.normbordercolor + dwm.normbgcolor + dwm.normfgcolor + dwm.selbordercolor + dwm.selbgcolor + dwm.selfgcolor + +Default key to reload is `Mod+F5`. + +Download +-------- + + * [dwm-xrdb-6.1.diff](dwm-xrdb-6.1.diff) + +Authors +------- + + * Petr Schmied - <https://github.com/JBlackN/dwm-xrdb>