Updating xresources patch as per 2020-03-02: [dmenu][patch] xresources: fixed patch, updated description

This commit is contained in:
bakkeby 2020-03-29 12:45:39 +02:00
parent 7f571bd751
commit 0f6d298600
3 changed files with 46 additions and 13 deletions

View File

@ -16,11 +16,21 @@ static int center = 1; /* -c option; if 0, dmenu won't be
static int min_width = 500; /* minimum width when centered */
#endif // CENTER_PATCH
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
#if XRESOURCES_PATCH
static char *fonts[] =
#else
static const char *fonts[] =
#endif // XRESOURCES_PATCH
{
"monospace:size=10"
};
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static const char *colors[][2] = {
#if XRESOURCES_PATCH
static char *colors[][2] =
#else
static const char *colors[][2] =
#endif // XRESOURCES_PATCH
{
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },

17
dmenu.c
View File

@ -862,8 +862,16 @@ setup(void)
int a, di, n, area = 0;
#endif
/* init appearance */
#if XRESOURCES_PATCH
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]);
#else
for (j = 0; j < SchemeLast; j++)
scheme[j] = drw_scm_create(drw, colors[j], 2);
#endif // XRESOURCES_PATCH
clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@ -1195,10 +1203,15 @@ main(int argc, char *argv[])
drw = drw_create(dpy, screen, root, wa.width, wa.height);
#if XRESOURCES_PATCH
read_Xresources();
#endif // XRESOURCES_PATCH
readxresources();
if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
free(fonts[0]);
#else
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
#endif // XRESOURCES_PATCH
lrpad = drw->fonts->h;
#ifdef __OpenBSD__

View File

@ -1,26 +1,36 @@
#include <X11/Xresource.h>
void
read_Xresources(void)
readxresources(void)
{
XrmInitialize();
char* xrm = XResourceManagerString(drw->dpy);
if (xrm) {
char* xrm;
if ((xrm = XResourceManagerString(drw->dpy))) {
char *type;
XrmDatabase xdb = XrmGetStringDatabase(xrm);
XrmValue xval;
if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval) == True) /* font or font set */
if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval))
fonts[0] = strdup(xval.addr);
if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval) == True) /* normal background color */
colors[SchemeSel][ColBg] = strdup(xval.addr);
if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval) == True) /* normal foreground color */
else
fonts[0] = strdup(fonts[0]);
if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval))
colors[SchemeNorm][ColBg] = strdup(xval.addr);
else
colors[SchemeNorm][ColBg] = strdup(colors[SchemeNorm][ColBg]);
if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval))
colors[SchemeNorm][ColFg] = strdup(xval.addr);
if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval) == True) /* selected background color */
else
colors[SchemeNorm][ColFg] = strdup(colors[SchemeNorm][ColFg]);
if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval))
colors[SchemeSel][ColBg] = strdup(xval.addr);
if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval) == True) /* selected foreground color */
else
colors[SchemeSel][ColBg] = strdup(colors[SchemeSel][ColBg]);
if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval))
colors[SchemeSel][ColFg] = strdup(xval.addr);
else
colors[SchemeSel][ColFg] = strdup(colors[SchemeSel][ColFg]);
XrmDestroyDatabase(xdb);
}