commit 3717a5547ad8b0b3369c72f77b4713c52c5784e9
parent 728211419f75cb1cb719d684412f8a9b153a480b
Author: miksa234 <milutin@popovic.xyz>
Date: Thu, 19 Dec 2024 09:21:12 +0100
add xresources patch
Diffstat:
14 files changed, 363 insertions(+), 14 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -5,14 +5,19 @@ static int topbar = 1; /* -b option; if 0, dmenu appears a
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 char font[] = "terminus:size=20:style=Bold";
static const char *fonts[] = {
- "terminus:size=20:style=Bold"
+ font
};
-static const char *prompt = NULL; /* -p option; prompt to the left of input field */
-static const char *colors[SchemeLast][2] = {
+static char *prompt = NULL; /* -p option; prompt to the left of input field */
+static char normfgcolor[] = "#bcbcbc";
+static char normbgcolor[] = "#000000";
+static char selfgcolor[] = "#eeeeee";
+static char selbgcolor[] = "#bcbcbc";
+static char *colors[SchemeLast][2] = {
/* fg bg */
- [SchemeNorm] = { "#bcbcbc", "#000000" },
- [SchemeSel] = { "#eeeeee", "#bcbcbc" },
+ [SchemeNorm] = { normfgcolor, normbgcolor },
+ [SchemeSel] = { selfgcolor, selbgcolor },
[SchemeOut] = { "#000000", "#00ffff" },
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
@@ -26,3 +31,15 @@ static const char worddelimiters[] = " ";
/* Size of the window border */
static unsigned int border_width = 0;
+
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "font", STRING, &font },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "normbgcolor", STRING, &normbgcolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "prompt", STRING, &prompt },
+};
diff --git a/config.def.h.orig b/config.def.h.orig
@@ -23,3 +23,6 @@ static unsigned int lines = 0;
* for example: " /?\"&[]"
*/
static const char worddelimiters[] = " ";
+
+/* Size of the window border */
+static unsigned int border_width = 0;
diff --git a/config.def.h.rej b/config.def.h.rej
@@ -0,0 +1,48 @@
+--- config.def.h 2021-04-16 06:30:47.713924755 +0300
++++ config.def.h 2021-04-16 06:34:14.956933252 +0300
+@@ -2,16 +2,25 @@
+ /* Default settings; can be overriden by command line. */
+
+ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
++
+ /* -fn option overrides fonts[0]; default X11 font or font set */
++static char font[] = "monospace:size=10";
+ static const char *fonts[] = {
+- "monospace:size=10"
++ font,
++ "monospace:size=10",
+ };
+-static const char *prompt = NULL; /* -p option; prompt to the left of input field */
+-static const char *colors[SchemeLast][2] = {
++
++static char *prompt = NULL; /* -p option; prompt to the left of input field */
++
++static char normfgcolor[] = "#bbbbbb";
++static char normbgcolor[] = "#222222";
++static char selfgcolor[] = "#eeeeee";
++static char selbgcolor[] = "#005577";
++static char *colors[SchemeLast][2] = {
+ /* fg bg */
+- [SchemeNorm] = { "#bbbbbb", "#222222" },
+- [SchemeSel] = { "#eeeeee", "#005577" },
+- [SchemeOut] = { "#000000", "#00ffff" },
++ [SchemeNorm] = { normfgcolor, normbgcolor },
++ [SchemeSel] = { selfgcolor, selbgcolor },
++ [SchemeOut] = { "#000000", "#00ffff" },
+ };
+ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+ static unsigned int lines = 0;
+@@ -21,3 +30,15 @@ static unsigned int lines = 0;
+ * for example: " /?\"&[]"
++
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "font", STRING, &font },
++ { "normfgcolor", STRING, &normfgcolor },
++ { "normbgcolor", STRING, &normbgcolor },
++ { "selfgcolor", STRING, &selfgcolor },
++ { "selbgcolor", STRING, &selbgcolor },
++ { "prompt", STRING, &prompt },
++};
diff --git a/config.h b/config.h
@@ -5,14 +5,19 @@ static int topbar = 1; /* -b option; if 0, dmenu appears a
static int centered = 1; /* -c option; centers dmenu on screen */
static int min_width = 1200; /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
+static char font[] = "terminus:size=20:style=Bold";
static const char *fonts[] = {
- "terminus:size=20:style=Bold"
+ font
};
-static const char *prompt = NULL; /* -p option; prompt to the left of input field */
-static const char *colors[SchemeLast][2] = {
+static char *prompt = NULL; /* -p option; prompt to the left of input field */
+static char normfgcolor[] = "#bcbcbc";
+static char normbgcolor[] = "#000000";
+static char selfgcolor[] = "#000000";
+static char selbgcolor[] = "#bcbcbc";
+static char *colors[SchemeLast][2] = {
/* fg bg */
- [SchemeNorm] = { "#bcbcbc", "#000000" },
- [SchemeSel] = { "#000000", "#bcbcbc" },
+ [SchemeNorm] = { normfgcolor, normbgcolor },
+ [SchemeSel] = { selfgcolor, selbgcolor },
[SchemeOut] = { "#642b2b", "#00ffff" },
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
@@ -25,4 +30,16 @@ static unsigned int lines = 0;
static const char worddelimiters[] = " ";
/* Size of the window border */
-static unsigned int border_width = 4;
+static unsigned int border_width = 3;
+
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "font", STRING, &font },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "normbgcolor", STRING, &normbgcolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "prompt", STRING, &prompt },
+};
diff --git a/dmenu b/dmenu
Binary files differ.
diff --git a/dmenu.c b/dmenu.c
@@ -11,6 +11,7 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
@@ -52,6 +53,21 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];
+/* Xresources preferences */
+enum resource_type {
+ STRING = 0,
+ INTEGER = 1,
+ FLOAT = 2
+};
+typedef struct {
+ char *name;
+ enum resource_type type;
+ void *dst;
+} ResourcePref;
+
+static void load_xresources(void);
+static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
+
#include "config.h"
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
@@ -581,6 +597,54 @@ readstdin(void)
lines = MIN(lines, i);
}
+void
+resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
+{
+ char *sdst = NULL;
+ int *idst = NULL;
+ float *fdst = NULL;
+ sdst = dst;
+ idst = dst;
+ fdst = dst;
+ char fullname[256];
+ char *type;
+ XrmValue ret;
+ snprintf(fullname, sizeof(fullname), "%s.%s", "dmenu", name);
+ fullname[sizeof(fullname) - 1] = '\0';
+ XrmGetResource(db, fullname, "*", &type, &ret);
+ if (!(ret.addr == NULL || strncmp("String", type, 64)))
+ {
+ switch (rtype) {
+ case STRING:
+ strcpy(sdst, ret.addr);
+ break;
+ case INTEGER:
+ *idst = strtoul(ret.addr, NULL, 10);
+ break;
+ case FLOAT:
+ *fdst = strtof(ret.addr, NULL);
+ break;
+ }
+ }
+}
+
+void
+load_xresources(void)
+{
+ Display *display;
+ char *resm;
+ XrmDatabase db;
+ ResourcePref *p;
+ display = XOpenDisplay(NULL);
+ resm = XResourceManagerString(display);
+ if (!resm)
+ return;
+ db = XrmGetStringDatabase(resm);
+ for (p = resources; p < resources + LENGTH(resources); p++)
+ resource_load(db, p->name, p->type, p->dst);
+ XCloseDisplay(display);
+}
+
static void
run(void)
{
@@ -751,6 +815,9 @@ main(int argc, char *argv[])
XWindowAttributes wa;
int i, fast = 0;
+ XrmInitialize();
+ load_xresources();
+
for (i = 1; i < argc; i++)
/* these options take no arguments */
if (!strcmp(argv[i], "-v")) { /* prints version information */
diff --git a/dmenu.c.orig b/dmenu.c.orig
@@ -708,9 +708,11 @@ setup(void)
swa.override_redirect = True;
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
- win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
+ win = XCreateWindow(dpy, root, x, y/2, mw, mh, border_width,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
+ if (border_width)
+ XSetWindowBorder(dpy, win, scheme[SchemeOut][ColFg].pixel);
XSetClassHint(dpy, win, &ch);
@@ -784,6 +786,8 @@ main(int argc, char *argv[])
colors[SchemeSel][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
+ else if (!strcmp(argv[i], "-bw"))
+ border_width = atoi(argv[++i]); /* border width */
else
usage();
diff --git a/dmenu.c.rej b/dmenu.c.rej
@@ -0,0 +1,11 @@
+--- dmenu.c 2021-04-16 06:30:47.715924755 +0300
++++ dmenu.c 2021-04-16 06:30:59.668925245 +0300
+@@ -411,7 +427,7 @@ keypress(XKeyEvent *ev)
+
+ switch(ksym) {
+ default:
+-insert:
++ insert:
+ if (!iscntrl(*buf))
+ insert(buf, len);
+ break;
diff --git a/dmenu.o b/dmenu.o
Binary files differ.
diff --git a/drw.c b/drw.c
@@ -195,7 +195,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.c b/drw.c.orig
diff --git a/drw.h b/drw.h
@@ -40,7 +40,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/drw.h b/drw.h.orig
diff --git a/patches/dmenu-xresources-alt-5.0.diff b/patches/dmenu-xresources-alt-5.0.diff
@@ -0,0 +1,182 @@
+diff -rupN orig/config.def.h patched/config.def.h
+--- orig/config.def.h 2021-04-16 06:30:47.713924755 +0300
++++ patched/config.def.h 2021-04-16 06:34:14.956933252 +0300
+@@ -2,16 +2,25 @@
+ /* Default settings; can be overriden by command line. */
+
+ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
++
+ /* -fn option overrides fonts[0]; default X11 font or font set */
++static char font[] = "monospace:size=10";
+ static const char *fonts[] = {
+- "monospace:size=10"
++ font,
++ "monospace:size=10",
+ };
+-static const char *prompt = NULL; /* -p option; prompt to the left of input field */
+-static const char *colors[SchemeLast][2] = {
++
++static char *prompt = NULL; /* -p option; prompt to the left of input field */
++
++static char normfgcolor[] = "#bbbbbb";
++static char normbgcolor[] = "#222222";
++static char selfgcolor[] = "#eeeeee";
++static char selbgcolor[] = "#005577";
++static char *colors[SchemeLast][2] = {
+ /* fg bg */
+- [SchemeNorm] = { "#bbbbbb", "#222222" },
+- [SchemeSel] = { "#eeeeee", "#005577" },
+- [SchemeOut] = { "#000000", "#00ffff" },
++ [SchemeNorm] = { normfgcolor, normbgcolor },
++ [SchemeSel] = { selfgcolor, selbgcolor },
++ [SchemeOut] = { "#000000", "#00ffff" },
+ };
+ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+ static unsigned int lines = 0;
+@@ -21,3 +30,15 @@ static unsigned int lines = 0;
+ * for example: " /?\"&[]"
+ */
+ static const char worddelimiters[] = " ";
++
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "font", STRING, &font },
++ { "normfgcolor", STRING, &normfgcolor },
++ { "normbgcolor", STRING, &normbgcolor },
++ { "selfgcolor", STRING, &selfgcolor },
++ { "selbgcolor", STRING, &selbgcolor },
++ { "prompt", STRING, &prompt },
++};
+diff -rupN orig/dmenu.c patched/dmenu.c
+--- orig/dmenu.c 2021-04-16 06:30:47.715924755 +0300
++++ patched/dmenu.c 2021-04-16 06:30:59.668925245 +0300
+@@ -11,6 +11,7 @@
+ #include <X11/Xlib.h>
+ #include <X11/Xatom.h>
+ #include <X11/Xutil.h>
++#include <X11/Xresource.h>
+ #ifdef XINERAMA
+ #include <X11/extensions/Xinerama.h>
+ #endif
+@@ -53,6 +54,21 @@ static XIC xic;
+ static Drw *drw;
+ static Clr *scheme[SchemeLast];
+
++/* Xresources preferences */
++enum resource_type {
++ STRING = 0,
++ INTEGER = 1,
++ FLOAT = 2
++};
++typedef struct {
++ char *name;
++ enum resource_type type;
++ void *dst;
++} ResourcePref;
++
++static void load_xresources(void);
++static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
++
+ #include "config.h"
+
+ static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+@@ -395,7 +411,7 @@ keypress(XKeyEvent *ev)
+
+ switch(ksym) {
+ default:
+-insert:
++ insert:
+ if (!iscntrl(*buf))
+ insert(buf, len);
+ break;
+@@ -547,6 +563,54 @@ readstdin(void)
+ lines = MIN(lines, i);
+ }
+
++void
++resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
++{
++ char *sdst = NULL;
++ int *idst = NULL;
++ float *fdst = NULL;
++ sdst = dst;
++ idst = dst;
++ fdst = dst;
++ char fullname[256];
++ char *type;
++ XrmValue ret;
++ snprintf(fullname, sizeof(fullname), "%s.%s", "dmenu", name);
++ fullname[sizeof(fullname) - 1] = '\0';
++ XrmGetResource(db, fullname, "*", &type, &ret);
++ if (!(ret.addr == NULL || strncmp("String", type, 64)))
++ {
++ switch (rtype) {
++ case STRING:
++ strcpy(sdst, ret.addr);
++ break;
++ case INTEGER:
++ *idst = strtoul(ret.addr, NULL, 10);
++ break;
++ case FLOAT:
++ *fdst = strtof(ret.addr, NULL);
++ break;
++ }
++ }
++}
++
++void
++load_xresources(void)
++{
++ Display *display;
++ char *resm;
++ XrmDatabase db;
++ ResourcePref *p;
++ display = XOpenDisplay(NULL);
++ resm = XResourceManagerString(display);
++ if (!resm)
++ return;
++ db = XrmGetStringDatabase(resm);
++ for (p = resources; p < resources + LENGTH(resources); p++)
++ resource_load(db, p->name, p->type, p->dst);
++ XCloseDisplay(display);
++}
++
+ static void
+ run(void)
+ {
+@@ -700,6 +764,9 @@ main(int argc, char *argv[])
+ XWindowAttributes wa;
+ int i, fast = 0;
+
++ XrmInitialize();
++ load_xresources();
++
+ for (i = 1; i < argc; i++)
+ /* these options take no arguments */
+ if (!strcmp(argv[i], "-v")) { /* prints version information */
+diff -rupN orig/drw.c patched/drw.c
+--- orig/drw.c 2021-04-16 06:30:47.718924755 +0300
++++ patched/drw.c 2021-04-16 06:30:59.670925245 +0300
+@@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, cons
+ /* 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 -rupN orig/drw.h patched/drw.h
+--- orig/drw.h 2021-04-16 06:30:47.718924755 +0300
++++ patched/drw.h 2021-04-16 06:30:59.671925245 +0300
+@@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const c
+
+ /* 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);