sites

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

dwm-xresources-20210827-138b405.diff (8163B)


      1 From f30583c6e2ab5e7de6ef4ebf156076ac0f6e69fc Mon Sep 17 00:00:00 2001
      2 From: Jack Bird <jack.bird@durham.ac.uk>
      3 Date: Fri, 27 Aug 2021 00:53:14 +0100
      4 Subject: [PATCH] xresources updated for 138b405
      5 
      6 ---
      7  config.def.h | 61 ++++++++++++++++++++++++++++++--------------
      8  drw.c        |  2 +-
      9  drw.h        |  2 +-
     10  dwm.c        | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
     11  4 files changed, 116 insertions(+), 21 deletions(-)
     12 
     13 diff --git a/config.def.h b/config.def.h
     14 index a2ac963..87ac198 100644
     15 --- a/config.def.h
     16 +++ b/config.def.h
     17 @@ -1,21 +1,23 @@
     18  /* See LICENSE file for copyright and license details. */
     19  
     20  /* appearance */
     21 -static const unsigned int borderpx  = 1;        /* border pixel of windows */
     22 -static const unsigned int snap      = 32;       /* snap pixel */
     23 -static const int showbar            = 1;        /* 0 means no bar */
     24 -static const int topbar             = 1;        /* 0 means bottom bar */
     25 -static const char *fonts[]          = { "monospace:size=10" };
     26 -static const char dmenufont[]       = "monospace:size=10";
     27 -static const char col_gray1[]       = "#222222";
     28 -static const char col_gray2[]       = "#444444";
     29 -static const char col_gray3[]       = "#bbbbbb";
     30 -static const char col_gray4[]       = "#eeeeee";
     31 -static const char col_cyan[]        = "#005577";
     32 -static const char *colors[][3]      = {
     33 -	/*               fg         bg         border   */
     34 -	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
     35 -	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
     36 +static unsigned int borderpx  = 1;        /* border pixel of windows */
     37 +static unsigned int snap      = 32;       /* snap pixel */
     38 +static int showbar            = 1;        /* 0 means no bar */
     39 +static int topbar             = 1;        /* 0 means bottom bar */
     40 +static char font[]            = "monospace:size=10";
     41 +static char dmenufont[]       = "monospace:size=10";
     42 +static const char *fonts[]          = { font };
     43 +static char normbgcolor[]           = "#222222";
     44 +static char normbordercolor[]       = "#444444";
     45 +static char normfgcolor[]           = "#bbbbbb";
     46 +static char selfgcolor[]            = "#eeeeee";
     47 +static char selbordercolor[]        = "#005577";
     48 +static char selbgcolor[]            = "#005577";
     49 +static char *colors[][3] = {
     50 +       /*               fg           bg           border   */
     51 +       [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
     52 +       [SchemeSel]  = { selfgcolor,  selbgcolor,  selbordercolor  },
     53  };
     54  
     55  /* tagging */
     56 @@ -32,9 +34,9 @@ static const Rule rules[] = {
     57  };
     58  
     59  /* layout(s) */
     60 -static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
     61 -static const int nmaster     = 1;    /* number of clients in master area */
     62 -static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
     63 +static float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
     64 +static int nmaster     = 1;    /* number of clients in master area */
     65 +static int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
     66  static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
     67  
     68  static const Layout layouts[] = {
     69 @@ -57,9 +59,30 @@ static const Layout layouts[] = {
     70  
     71  /* commands */
     72  static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
     73 -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
     74 +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
     75  static const char *termcmd[]  = { "st", NULL };
     76  
     77 +/*
     78 + * Xresources preferences to load at startup
     79 + */
     80 +ResourcePref resources[] = {
     81 +		{ "font",               STRING,  &font },
     82 +		{ "dmenufont",          STRING,  &dmenufont },
     83 +		{ "normbgcolor",        STRING,  &normbgcolor },
     84 +		{ "normbordercolor",    STRING,  &normbordercolor },
     85 +		{ "normfgcolor",        STRING,  &normfgcolor },
     86 +		{ "selbgcolor",         STRING,  &selbgcolor },
     87 +		{ "selbordercolor",     STRING,  &selbordercolor },
     88 +		{ "selfgcolor",         STRING,  &selfgcolor },
     89 +		{ "borderpx",          	INTEGER, &borderpx },
     90 +		{ "snap",          		INTEGER, &snap },
     91 +		{ "showbar",          	INTEGER, &showbar },
     92 +		{ "topbar",          	INTEGER, &topbar },
     93 +		{ "nmaster",          	INTEGER, &nmaster },
     94 +		{ "resizehints",       	INTEGER, &resizehints },
     95 +		{ "mfact",      	 	FLOAT,   &mfact },
     96 +};
     97 +
     98  static Key keys[] = {
     99  	/* modifier                     key        function        argument */
    100  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
    101 diff --git a/drw.c b/drw.c
    102 index 4cdbcbe..8f1059e 100644
    103 --- a/drw.c
    104 +++ b/drw.c
    105 @@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
    106  /* Wrapper to create color schemes. The caller has to call free(3) on the
    107   * returned color scheme when done using it. */
    108  Clr *
    109 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    110 +drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
    111  {
    112  	size_t i;
    113  	Clr *ret;
    114 diff --git a/drw.h b/drw.h
    115 index 4bcd5ad..42b04ce 100644
    116 --- a/drw.h
    117 +++ b/drw.h
    118 @@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
    119  
    120  /* Colorscheme abstraction */
    121  void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
    122 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
    123 +Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
    124  
    125  /* Cursor abstraction */
    126  Cur *drw_cur_create(Drw *drw, int shape);
    127 diff --git a/dwm.c b/dwm.c
    128 index 5e4d494..2214b19 100644
    129 --- a/dwm.c
    130 +++ b/dwm.c
    131 @@ -36,6 +36,7 @@
    132  #include <X11/Xlib.h>
    133  #include <X11/Xproto.h>
    134  #include <X11/Xutil.h>
    135 +#include <X11/Xresource.h>
    136  #ifdef XINERAMA
    137  #include <X11/extensions/Xinerama.h>
    138  #endif /* XINERAMA */
    139 @@ -141,6 +142,19 @@ typedef struct {
    140  	int monitor;
    141  } Rule;
    142  
    143 +/* Xresources preferences */
    144 +enum resource_type {
    145 +	STRING = 0,
    146 +	INTEGER = 1,
    147 +	FLOAT = 2
    148 +};
    149 +
    150 +typedef struct {
    151 +	char *name;
    152 +	enum resource_type type;
    153 +	void *dst;
    154 +} ResourcePref;
    155 +
    156  /* function declarations */
    157  static void applyrules(Client *c);
    158  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
    159 @@ -234,6 +248,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
    160  static int xerrordummy(Display *dpy, XErrorEvent *ee);
    161  static int xerrorstart(Display *dpy, XErrorEvent *ee);
    162  static void zoom(const Arg *arg);
    163 +static void load_xresources(void);
    164 +static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
    165  
    166  /* variables */
    167  static const char broken[] = "broken";
    168 @@ -2127,6 +2143,60 @@ zoom(const Arg *arg)
    169  	pop(c);
    170  }
    171  
    172 +void
    173 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
    174 +{
    175 +	char *sdst = NULL;
    176 +	int *idst = NULL;
    177 +	float *fdst = NULL;
    178 +
    179 +	sdst = dst;
    180 +	idst = dst;
    181 +	fdst = dst;
    182 +
    183 +	char fullname[256];
    184 +	char *type;
    185 +	XrmValue ret;
    186 +
    187 +	snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
    188 +	fullname[sizeof(fullname) - 1] = '\0';
    189 +
    190 +	XrmGetResource(db, fullname, "*", &type, &ret);
    191 +	if (!(ret.addr == NULL || strncmp("String", type, 64)))
    192 +	{
    193 +		switch (rtype) {
    194 +		case STRING:
    195 +			strcpy(sdst, ret.addr);
    196 +			break;
    197 +		case INTEGER:
    198 +			*idst = strtoul(ret.addr, NULL, 10);
    199 +			break;
    200 +		case FLOAT:
    201 +			*fdst = strtof(ret.addr, NULL);
    202 +			break;
    203 +		}
    204 +	}
    205 +}
    206 +
    207 +void
    208 +load_xresources(void)
    209 +{
    210 +	Display *display;
    211 +	char *resm;
    212 +	XrmDatabase db;
    213 +	ResourcePref *p;
    214 +
    215 +	display = XOpenDisplay(NULL);
    216 +	resm = XResourceManagerString(display);
    217 +	if (!resm)
    218 +		return;
    219 +
    220 +	db = XrmGetStringDatabase(resm);
    221 +	for (p = resources; p < resources + LENGTH(resources); p++)
    222 +		resource_load(db, p->name, p->type, p->dst);
    223 +	XCloseDisplay(display);
    224 +}
    225 +
    226  int
    227  main(int argc, char *argv[])
    228  {
    229 @@ -2139,6 +2209,8 @@ main(int argc, char *argv[])
    230  	if (!(dpy = XOpenDisplay(NULL)))
    231  		die("dwm: cannot open display");
    232  	checkotherwm();
    233 +	XrmInitialize();
    234 +	load_xresources();
    235  	setup();
    236  #ifdef __OpenBSD__
    237  	if (pledge("stdio rpath proc exec", NULL) == -1)
    238 -- 
    239 2.33.0
    240