~mil/sxmo-dmenu

cd84c75f66c3096a9a74e48fb71ca0f194e67b13 — tetrakist 6 months ago ff243da
Fix segfault on missing Xresources. Add and document more color settings.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
3 files changed, 63 insertions(+), 39 deletions(-)

M config.def.h
M dmenu.1
M dmenu.c
M config.def.h => config.def.h +2 -2
@@ 6,11 6,11 @@ static int colorprompt = 1;                 /* -p  option; if 1, prompt uses Sch
static int centered = 0;                    /* -c option; centers dmenu on screen */
static int min_width = 500;                    /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
static const char *defaultfonts[] = {
	"monospace:size=10"
};
static const char *prompt      = NULL;      /* -p  option; prompt to the left of input field */
static const char *colors[SchemeLast][2] = {
static const char *defaultcolors[SchemeLast][2] = {
	/*     fg         bg       */
	[SchemeNorm] = { "#bbbbbb", "#222222" },
	[SchemeSel] = { "#eeeeee", "#005577" },

M dmenu.1 => dmenu.1 +18 -0
@@ 224,6 224,24 @@ defines the selected background color.
.TP
.BI dmenu.selforeground
defines the selected foreground color.
.TP
.BI dmenu.selhighlightbackground
defines the highlighted selected background color.
.TP
.BI dmenu.selhighlightforeground
defines the highlighted selected foreground color.
.TP
.BI dmenu.highlightbackground
defines the highlighted background color.
.TP
.BI dmenu.highlightforeground
defines the highlighted foreground color.
.TP
.BI dmenu.outbackground
defines the out background color.
.TP
.BI dmenu.outforeground
defines the out foreground color.
.SH SEE ALSO
.IR dwm (1),
.IR stest (1)

M dmenu.c => dmenu.c +43 -37
@@ 61,9 61,9 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];

/* Temporary arrays to allow overriding xresources values */
static char *colortemp[4];
static char *tempfonts;
/* Empty arrays to be filled from command line, Xresources, and defaults, in decreasing order of precedence */
static char *colors[SchemeLast][2];
static char *fonts[] = {0};

#include "config.h"



@@ 869,9 869,9 @@ setup(void)
	for (j = 0; j < SchemeLast; j++) {
		scheme[j] = drw_scm_create(drw, (const char**)colors[j], 2);
	}
	for (j = 0; j < SchemeOut; ++j) {
		for (i = 0; i < 2; ++i)
			free(colors[j][i]);
	for (j = 0; j < SchemeLast; ++j) {
		free(colors[j][ColFg]);
		free(colors[j][ColBg]);
	}

	clip = XInternAtom(dpy, "CLIPBOARD",   False);


@@ 1010,26 1010,33 @@ readxresources(void) {
		XrmDatabase xdb = XrmGetStringDatabase(xrm);
		XrmValue xval;

		if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval))
		if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval) && !fonts[0])
			fonts[0] = strdup(xval.addr);
		else
			fonts[0] = strdup(fonts[0]);
		if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval))

		if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval) && !colors[SchemeNorm][ColBg] )
			colors[SchemeNorm][ColBg] = strdup(xval.addr);
		else
			colors[SchemeNorm][ColBg] = strdup(colors[SchemeNorm][ColBg]);
		if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval))
		if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval) && !colors[SchemeNorm][ColFg] )
			colors[SchemeNorm][ColFg] = strdup(xval.addr);
		else
			colors[SchemeNorm][ColFg] = strdup(colors[SchemeNorm][ColFg]);
		if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval))

		if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval) && !colors[SchemeSel][ColBg] )
			colors[SchemeSel][ColBg] = strdup(xval.addr);
		else
			colors[SchemeSel][ColBg] = strdup(colors[SchemeSel][ColBg]);
		if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval))
		if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval) && !colors[SchemeSel][ColFg] )
			colors[SchemeSel][ColFg] = strdup(xval.addr);
		else
			colors[SchemeSel][ColFg] = strdup(colors[SchemeSel][ColFg]);

		if (XrmGetResource(xdb, "dmenu.selhighlightbackground", "*", &type, &xval) && !colors[SchemeSelHighlight][ColBg] )
			colors[SchemeSelHighlight][ColBg] = strdup(xval.addr);
		if (XrmGetResource(xdb, "dmenu.selhighlightforeground", "*", &type, &xval) && !colors[SchemeSelHighlight][ColFg] )
			colors[SchemeSelHighlight][ColFg] = strdup(xval.addr);

		if (XrmGetResource(xdb, "dmenu.highlightbackground", "*", &type, &xval) && !colors[SchemeNormHighlight][ColBg] )
			colors[SchemeNormHighlight][ColBg] = strdup(xval.addr);
		if (XrmGetResource(xdb, "dmenu.highlightforeground", "*", &type, &xval) && !colors[SchemeNormHighlight][ColFg] )
			colors[SchemeNormHighlight][ColFg] = strdup(xval.addr);

		if (XrmGetResource(xdb, "dmenu.outbackground", "*", &type, &xval) && !colors[SchemeOut][ColBg] )
			colors[SchemeOut][ColBg] = strdup(xval.addr);
		if (XrmGetResource(xdb, "dmenu.outforeground", "*", &type, &xval) && !colors[SchemeOut][ColFg] )
			colors[SchemeOut][ColFg] = strdup(xval.addr);

		XrmDestroyDatabase(xdb);
	}


@@ 1069,15 1076,15 @@ main(int argc, char *argv[])
		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
			prompt = argv[++i];
		else if (!strcmp(argv[i], "-fn"))  /* font or font set */
			tempfonts = argv[++i];
			fonts[0] = strdup(argv[++i]);
		else if (!strcmp(argv[i], "-nb"))  /* normal background color */
			colortemp[0] = argv[++i];
			colors[SchemeNorm][ColBg] = strdup(argv[++i]);
		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */
			colortemp[1] = argv[++i];
			colors[SchemeNorm][ColFg] = strdup(argv[++i]);
		else if (!strcmp(argv[i], "-sb"))  /* selected background color */
			colortemp[2] = argv[++i];
			colors[SchemeSel][ColBg]  = strdup(argv[++i]);
		else if (!strcmp(argv[i], "-sf"))  /* selected foreground color */
			colortemp[3] = argv[++i];
			colors[SchemeSel][ColFg]  = strdup(argv[++i]);
		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
			embed = argv[++i];
		else if (!strcmp(argv[i], "-idx")) /* initial index selection */


@@ 1101,17 1108,16 @@ main(int argc, char *argv[])
		    parentwin);
	drw = drw_create(dpy, screen, root, wa.width, wa.height);
	readxresources();
	/* Now we check whether to override xresources with commandline parameters */
	if ( tempfonts )
	   fonts[0] = strdup(tempfonts);
	if ( colortemp[0])
	   colors[SchemeNorm][ColBg] = strdup(colortemp[0]);
	if ( colortemp[1])
	   colors[SchemeNorm][ColFg] = strdup(colortemp[1]);
	if ( colortemp[2])
	   colors[SchemeSel][ColBg]  = strdup(colortemp[2]);
	if ( colortemp[3])
	   colors[SchemeSel][ColFg]  = strdup(colortemp[3]);

	/* Apply defaults to font and colors*/
	if ( !fonts[0] )
	   fonts[0] = strdup(defaultfonts[0]);
	for (i = 0; i < SchemeLast; ++i){
		if ( !colors[i][ColBg] )
		   colors[i][ColBg] = strdup(defaultcolors[i][ColBg]);
		if ( !colors[i][ColFg] )
		   colors[i][ColFg] = strdup(defaultcolors[i][ColFg]);
	}

	if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts)))
		die("no fonts could be loaded.");