[wiki] [sites] [dwm] xrdb patch update || Petr Schmied

From: <git_AT_suckless.org>
Date: Tue, 09 Jul 2019 08:55:52 +0200

commit 991f9877bbb4b9412877dbcb145b2d426c6c2614
Author: Petr Schmied <peter9209_AT_gmail.com>
Date: Tue Jul 9 08:55:23 2019 +0200

    [dwm] xrdb patch update

diff --git a/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff b/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff
index 2b49f93a..a33cf880 100644
--- a/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff
+++ b/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.1.diff
_AT_@ -1,15 +1,5 @@
-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
+index 7054c06..436e16f 100644
 --- a/config.def.h
 +++ b/config.def.h
 _AT_@ -5,12 +5,12 @@ static const char *fonts[] = {
_AT_@ -39,13 +29,13 @@ index 7054c06..e2f2634 100644
  	TAGKEYS(                        XK_1,                      0)
  	TAGKEYS(                        XK_2,                      1)
  	TAGKEYS(                        XK_3,                      2)
-_AT_@ -111,3 +112,4 @@ static Button buttons[] = {
+_AT_@ -110,4 +111,3 @@ static Button buttons[] = {
+ 	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
  	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
  };
- 
-+static const char *xres = "/home/USERNAME/.Xresources";
+-
 diff --git a/dwm.c b/dwm.c
-index 0362114..0f257ec 100644
+index 0362114..bb1238c 100644
 --- a/dwm.c
 +++ b/dwm.c
 _AT_@ -35,6 +35,7 @@
_AT_@ -94,31 +84,45 @@ index 0362114..0f257ec 100644
  static void zoom(const Arg *arg);
  
  /* variables */
-_AT_@ -1029,6 +1047,23 @@ killclient(const Arg *arg)
+_AT_@ -1029,6 +1047,37 @@ killclient(const Arg *arg)
  	}
  }
  
 +void
 +loadxrdb()
 +{
-+  XrmDatabase xrdb = XrmGetFileDatabase(xres);
-+  if (xrdb != NULL) {
-+    char *type;
-+    XrmValue value;
++  Display *display;
++  char *resm;
++  XrmDatabase xrdb;
++  char *type;
++  XrmValue value;
++
++  display = XOpenDisplay(NULL);
++
++  if (display != NULL) {
++    resm = XResourceManagerString(display);
 +
-+    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);
++    if (resm != NULL) {
++      xrdb = XrmGetStringDatabase(resm);
++
++      if (xrdb != NULL) {
++        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);
++      }
++    }
 +  }
++
++  XCloseDisplay(display);
 +}
 +
  void
  manage(Window w, XWindowAttributes *wa)
  {
-_AT_@ -2106,6 +2141,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
+_AT_@ -2106,6 +2155,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
  	return -1;
  }
  
_AT_@ -141,14 +145,12 @@ index 0362114..0f257ec 100644
  void
  zoom(const Arg *arg)
  {
-_AT_@ -2132,6 +2183,7 @@ main(int argc, char *argv[])
+_AT_@ -2132,6 +2197,8 @@ main(int argc, char *argv[])
  	if (!(dpy = XOpenDisplay(NULL)))
  		die("dwm: cannot open display
");
  	checkotherwm();
-+  loadxrdb();
++	XrmInitialize();
++	loadxrdb();
  	setup();
  	scan();
  	run();
--- 
-2.16.4
-
diff --git a/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.2.diff b/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.2.diff
new file mode 100644
index 00000000..4c5a53ff
--- /dev/null
+++ b/dwm.suckless.org/patches/xrdb/dwm-xrdb-6.2.diff
_AT_@ -0,0 +1,188 @@
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..5db7d05 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -7,15 +7,16 @@ 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 char col_gray1[]       = "#222222";
+-static const char col_gray2[]       = "#444444";
+-static const char col_gray3[]       = "#bbbbbb";
+-static const char col_gray4[]       = "#eeeeee";
+-static const char col_cyan[]        = "#005577";
+-static const char *colors[][3]      = {
+-	/*               fg         bg         border   */
+-	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+-	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
++static char normbgcolor[]           = "#222222";
++static char normbordercolor[]       = "#444444";
++static char normfgcolor[]           = "#bbbbbb";
++static char selfgcolor[]            = "#eeeeee";
++static char selbordercolor[]        = "#005577";
++static char selbgcolor[]            = "#005577";
++static char *colors[][3] = {
++       /*               fg           bg           border   */
++       [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
++       [SchemeSel]  = { selfgcolor,  selbgcolor,  selbordercolor  },
+ };
+ 
+ /* tagging */
+_AT_@ -56,7 +57,7 @@ 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 *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
+ static const char *termcmd[]  = { "st", NULL };
+ 
+ static Key keys[] = {
+_AT_@ -84,6 +85,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)
+diff --git a/drw.c b/drw.c
+index 8fd1ca4..e4968a0 100644
+--- a/drw.c
++++ b/drw.c
+_AT_@ -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
+index 4bcd5ad..42b04ce 100644
+--- a/drw.h
++++ b/drw.h
+_AT_@ -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.c b/dwm.c
+index 4465af1..7fa45c5 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -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>
+_AT_@ -56,6 +57,21 @@
+ #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
+ #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
+ #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
++#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] = '++                                    } \
++                                  } \
++                                }
+ 
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+_AT_@ -177,6 +193,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);
+_AT_@ -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 */
+_AT_@ -1014,6 +1032,37 @@ killclient(const Arg *arg)
+ 	}
+ }
+ 
++void
++loadxrdb()
++{
++  Display *display;
++  char * resm;
++  XrmDatabase xrdb;
++  char *type;
++  XrmValue value;
++
++  display = XOpenDisplay(NULL);
++
++  if (display != NULL) {
++    resm = XResourceManagerString(display);
++
++    if (resm != NULL) {
++      xrdb = XrmGetStringDatabase(resm);
++
++      if (xrdb != NULL) {
++        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);
++      }
++    }
++  }
++
++  XCloseDisplay(display);
++}
++
+ void
+ manage(Window w, XWindowAttributes *wa)
+ {
+_AT_@ -2110,6 +2159,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
+ 	return -1;
+ }
+ 
++void
++xrdb(const Arg *arg)
++{
++  loadxrdb();
++  int i;
++  for (i = 0; i < LENGTH(colors); i++)
++                scheme[i] = drw_scm_create(drw, colors[i], 3);
++  focus(NULL);
++  arrange(NULL);
++}
++
+ void
+ zoom(const Arg *arg)
+ {
+_AT_@ -2136,6 +2196,8 @@ main(int argc, char *argv[])
+ 	if (!(dpy = XOpenDisplay(NULL)))
+ 		die("dwm: cannot open display");
+ 	checkotherwm();
++        XrmInitialize();
++        loadxrdb();
+ 	setup();
+ #ifdef __OpenBSD__
+ 	if (pledge("stdio rpath proc exec", NULL) == -1)
diff --git a/dwm.suckless.org/patches/xrdb/index.md b/dwm.suckless.org/patches/xrdb/index.md
index c9fef4b6..80d1329f 100644
--- a/dwm.suckless.org/patches/xrdb/index.md
+++ b/dwm.suckless.org/patches/xrdb/index.md
_AT_@ -3,10 +3,7 @@ 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).
+Allows dwm to read colors from `xrdb (.Xresources)` at run time.
 
 X resources used:
 
_AT_@ -17,12 +14,16 @@ X resources used:
 	dwm.selbgcolor
 	dwm.selfgcolor
 
+Example Xresource string: `dwm.normbgcolor: #002b36`.
+
 Default key to reload is `Mod+F5`.
 
 Download
 --------
+* [dwm-xrdb-6.2.diff](dwm-xrdb-6.2.diff)
 * [dwm-xrdb-6.1.diff](dwm-xrdb-6.1.diff)
 
 Authors
 -------
 * Petr Schmied - <https://github.com/JBlackN/dwm-xrdb>
+* Rob Livesey - <rlives6789_AT_gmail.com> (v6.2 port)
Received on Tue Jul 09 2019 - 08:55:52 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 09 2019 - 09:00:32 CEST