dmenu

Mahdi's build of dmenu
git clone git://mahdi.pw/dmenu.git
Log | Files | Refs | README | LICENSE

dmenu-xresources-alt-5.0.diff (5277B)


      1 diff -rupN orig/config.def.h patched/config.def.h
      2 --- orig/config.def.h	2021-04-16 06:30:47.713924755 +0300
      3 +++ patched/config.def.h	2021-04-16 06:34:14.956933252 +0300
      4 @@ -2,16 +2,25 @@
      5  /* Default settings; can be overriden by command line. */
      6  
      7  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
      8 +
      9  /* -fn option overrides fonts[0]; default X11 font or font set */
     10 +static char font[] = "monospace:size=10";
     11  static const char *fonts[] = {
     12 -	"monospace:size=10"
     13 +	font,
     14 +	"monospace:size=10",
     15  };
     16 -static const char *prompt      = NULL;      /* -p  option; prompt to the left of input field */
     17 -static const char *colors[SchemeLast][2] = {
     18 +
     19 +static char *prompt      = NULL;      /* -p  option; prompt to the left of input field */
     20 +
     21 +static char normfgcolor[] = "#bbbbbb";
     22 +static char normbgcolor[] = "#222222";
     23 +static char selfgcolor[]  = "#eeeeee";
     24 +static char selbgcolor[]  = "#005577";
     25 +static char *colors[SchemeLast][2] = {
     26  	/*     fg         bg       */
     27 -	[SchemeNorm] = { "#bbbbbb", "#222222" },
     28 -	[SchemeSel] = { "#eeeeee", "#005577" },
     29 -	[SchemeOut] = { "#000000", "#00ffff" },
     30 +	[SchemeNorm] = { normfgcolor, normbgcolor },
     31 +	[SchemeSel]  = { selfgcolor,  selbgcolor  },
     32 +	[SchemeOut]  = { "#000000",   "#00ffff" },
     33  };
     34  /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
     35  static unsigned int lines      = 0;
     36 @@ -21,3 +30,15 @@ static unsigned int lines      = 0;
     37   * for example: " /?\"&[]"
     38   */
     39  static const char worddelimiters[] = " ";
     40 +
     41 +/*
     42 + * Xresources preferences to load at startup
     43 + */
     44 +ResourcePref resources[] = {
     45 +	{ "font",        STRING, &font },
     46 +	{ "normfgcolor", STRING, &normfgcolor },
     47 +	{ "normbgcolor", STRING, &normbgcolor },
     48 +	{ "selfgcolor",  STRING, &selfgcolor },
     49 +	{ "selbgcolor",  STRING, &selbgcolor },
     50 +	{ "prompt",      STRING, &prompt },
     51 +};
     52 diff -rupN orig/dmenu.c patched/dmenu.c
     53 --- orig/dmenu.c	2021-04-16 06:30:47.715924755 +0300
     54 +++ patched/dmenu.c	2021-04-16 06:30:59.668925245 +0300
     55 @@ -11,6 +11,7 @@
     56  #include <X11/Xlib.h>
     57  #include <X11/Xatom.h>
     58  #include <X11/Xutil.h>
     59 +#include <X11/Xresource.h>
     60  #ifdef XINERAMA
     61  #include <X11/extensions/Xinerama.h>
     62  #endif
     63 @@ -53,6 +54,21 @@ static XIC xic;
     64  static Drw *drw;
     65  static Clr *scheme[SchemeLast];
     66  
     67 +/* Xresources preferences */
     68 +enum resource_type {
     69 +	STRING = 0,
     70 +	INTEGER = 1,
     71 +	FLOAT = 2
     72 +};
     73 +typedef struct {
     74 +	char *name;
     75 +	enum resource_type type;
     76 +	void *dst;
     77 +} ResourcePref;
     78 +
     79 +static void load_xresources(void);
     80 +static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
     81 +
     82  #include "config.h"
     83  
     84  static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
     85 @@ -395,7 +411,7 @@ keypress(XKeyEvent *ev)
     86  
     87  	switch(ksym) {
     88  	default:
     89 -insert:
     90 +	insert:
     91  		if (!iscntrl(*buf))
     92  			insert(buf, len);
     93  		break;
     94 @@ -547,6 +563,54 @@ readstdin(void)
     95  	lines = MIN(lines, i);
     96  }
     97  
     98 +void
     99 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
    100 +{
    101 +	char *sdst = NULL;
    102 +	int *idst = NULL;
    103 +	float *fdst = NULL;
    104 +	sdst = dst;
    105 +	idst = dst;
    106 +	fdst = dst;
    107 +	char fullname[256];
    108 +	char *type;
    109 +	XrmValue ret;
    110 +	snprintf(fullname, sizeof(fullname), "%s.%s", "dmenu", name);
    111 +	fullname[sizeof(fullname) - 1] = '\0';
    112 +	XrmGetResource(db, fullname, "*", &type, &ret);
    113 +	if (!(ret.addr == NULL || strncmp("String", type, 64)))
    114 +	{
    115 +		switch (rtype) {
    116 +		case STRING:
    117 +			strcpy(sdst, ret.addr);
    118 +			break;
    119 +		case INTEGER:
    120 +			*idst = strtoul(ret.addr, NULL, 10);
    121 +			break;
    122 +		case FLOAT:
    123 +			*fdst = strtof(ret.addr, NULL);
    124 +			break;
    125 +		}
    126 +	}
    127 +}
    128 +
    129 +void
    130 +load_xresources(void)
    131 +{
    132 +	Display *display;
    133 +	char *resm;
    134 +	XrmDatabase db;
    135 +	ResourcePref *p;
    136 +	display = XOpenDisplay(NULL);
    137 +	resm = XResourceManagerString(display);
    138 +	if (!resm)
    139 +		return;
    140 +	db = XrmGetStringDatabase(resm);
    141 +	for (p = resources; p < resources + LENGTH(resources); p++)
    142 +		resource_load(db, p->name, p->type, p->dst);
    143 +	XCloseDisplay(display);
    144 +}
    145 +
    146  static void
    147  run(void)
    148  {
    149 @@ -700,6 +764,9 @@ main(int argc, char *argv[])
    150  	XWindowAttributes wa;
    151  	int i, fast = 0;
    152  
    153 +	XrmInitialize();
    154 +	load_xresources();
    155 +	
    156  	for (i = 1; i < argc; i++)
    157  		/* these options take no arguments */
    158  		if (!strcmp(argv[i], "-v")) {      /* prints version information */
    159 diff -rupN orig/drw.c patched/drw.c
    160 --- orig/drw.c	2021-04-16 06:30:47.718924755 +0300
    161 +++ patched/drw.c	2021-04-16 06:30:59.670925245 +0300
    162 @@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, cons
    163  /* Wrapper to create color schemes. The caller has to call free(3) on the
    164   * returned color scheme when done using it. */
    165  Clr *
    166 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    167 +drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
    168  {
    169  	size_t i;
    170  	Clr *ret;
    171 diff -rupN orig/drw.h patched/drw.h
    172 --- orig/drw.h	2021-04-16 06:30:47.718924755 +0300
    173 +++ patched/drw.h	2021-04-16 06:30:59.671925245 +0300
    174 @@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const c
    175  
    176  /* Colorscheme abstraction */
    177  void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
    178 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
    179 +Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
    180  
    181  /* Cursor abstraction */
    182  Cur *drw_cur_create(Drw *drw, int shape);