From 39c95f5b03725edecf057e4c5061c8adcee9c6ac Mon Sep 17 00:00:00 2001 From: Philip Wittamore Date: Wed, 28 May 2025 14:27:47 +0200 Subject: update --- patch-dmenu-280525 | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 patch-dmenu-280525 diff --git a/patch-dmenu-280525 b/patch-dmenu-280525 new file mode 100644 index 0000000..14be704 --- /dev/null +++ b/patch-dmenu-280525 @@ -0,0 +1,235 @@ +diff -u /src/MASTER/dmenu/config.def.h /src/WORKING/dmenu/config.def.h +--- /src/MASTER/dmenu/config.def.h 2025-05-19 16:08:44.076125997 +0200 ++++ /src/WORKING/dmenu/config.def.h 2025-05-26 21:19:40.313675171 +0200 +@@ -2,9 +2,11 @@ + /* Default settings; can be overriden by command line. */ + + static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ ++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[] = { +- "monospace:size=10" ++ "JetBrainsMono Nerd Font Mono:size=11" + }; + static const char *prompt = NULL; /* -p option; prompt to the left of input field */ + static const char *colors[SchemeLast][2] = { +Only in /src/WORKING/dmenu: config.h +diff -u /src/MASTER/dmenu/dmenu.1 /src/WORKING/dmenu/dmenu.1 +--- /src/MASTER/dmenu/dmenu.1 2025-05-19 16:08:44.076125997 +0200 ++++ /src/WORKING/dmenu/dmenu.1 2025-05-26 21:19:40.313675171 +0200 +@@ -40,6 +40,9 @@ + .B \-b + dmenu appears at the bottom of the screen. + .TP ++.B \-c ++dmenu appears centered on the screen. ++.TP + .B \-f + dmenu grabs the keyboard before reading stdin if not reading from a tty. This + is faster, but will lock up X until stdin reaches end\-of\-file. +diff -u /src/MASTER/dmenu/dmenu.c /src/WORKING/dmenu/dmenu.c +--- /src/MASTER/dmenu/dmenu.c 2025-05-19 16:08:44.076125997 +0200 ++++ /src/WORKING/dmenu/dmenu.c 2025-05-26 21:19:40.313675171 +0200 +@@ -15,6 +15,7 @@ + #include + #endif + #include ++#include + + #include "drw.h" + #include "util.h" +@@ -52,6 +53,10 @@ + static Drw *drw; + static Clr *scheme[SchemeLast]; + ++/* Temporary arrays to allow overriding xresources values */ ++static char *colortemp[4]; ++static char *tempfonts; ++ + #include "config.h" + + static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; +@@ -95,6 +100,15 @@ + break; + } + ++static int ++max_textw(void) ++{ ++ int len = 0; ++ for (struct item *item = items; item && item->text; item++) ++ len = MAX(TEXTW(item->text), len); ++ return len; ++} ++ + static void + cleanup(void) + { +@@ -626,8 +640,13 @@ + int a, di, n, area = 0; + #endif + /* init appearance */ +- for (j = 0; j < SchemeLast; j++) +- scheme[j] = drw_scm_create(drw, colors[j], 2); ++ 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]); ++ } + + clip = XInternAtom(dpy, "CLIPBOARD", False); + utf8 = XInternAtom(dpy, "UTF8_STRING", False); +@@ -636,6 +655,7 @@ + bh = drw->fonts->h + 2; + lines = MAX(lines, 0); + mh = (lines + 1) * bh; ++ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; + #ifdef XINERAMA + i = 0; + if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { +@@ -662,9 +682,16 @@ + if (INTERSECT(x, y, 1, 1, info[i]) != 0) + break; + +- x = info[i].x_org; +- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); +- mw = info[i].width; ++ if (centered) { ++ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); ++ x = info[i].x_org + ((info[i].width - mw) / 2); ++ y = info[i].y_org + ((info[i].height - mh) / 2); ++ } else { ++ x = info[i].x_org; ++ y = info[i].y_org + (topbar ? 0 : info[i].height - mh); ++ mw = info[i].width; ++ } ++ + XFree(info); + } else + #endif +@@ -672,11 +699,18 @@ + if (!XGetWindowAttributes(dpy, parentwin, &wa)) + die("could not get embedding window attributes: 0x%lx", + parentwin); +- x = 0; +- y = topbar ? 0 : wa.height - mh; +- mw = wa.width; ++ ++ if (centered) { ++ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width); ++ x = (wa.width - mw) / 2; ++ y = (wa.height - mh) / 2; ++ } else { ++ x = 0; ++ y = topbar ? 0 : wa.height - mh; ++ mw = wa.width; ++ } + } +- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; ++ + inputw = mw / 3; /* input width: ~33% of monitor width */ + match(); + +@@ -718,6 +752,41 @@ + " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); + } + ++void ++readxresources(void) { ++ XrmInitialize(); ++ ++ char* xrm; ++ if ((xrm = XResourceManagerString(drw->dpy))) { ++ char *type; ++ XrmDatabase xdb = XrmGetStringDatabase(xrm); ++ XrmValue xval; ++ ++ if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval)) ++ fonts[0] = strdup(xval.addr); ++ 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); ++ else ++ colors[SchemeNorm][ColFg] = strdup(colors[SchemeNorm][ColFg]); ++ if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval)) ++ colors[SchemeSel][ColBg] = strdup(xval.addr); ++ 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); ++ } ++} ++ + int + main(int argc, char *argv[]) + { +@@ -733,6 +802,8 @@ + topbar = 0; + else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ + fast = 1; ++ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ ++ centered = 1; + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +@@ -746,15 +817,15 @@ + 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 */ +- fonts[0] = argv[++i]; ++ tempfonts = argv[++i]; + else if (!strcmp(argv[i], "-nb")) /* normal background color */ +- colors[SchemeNorm][ColBg] = argv[++i]; ++ colortemp[0] = argv[++i]; + else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ +- colors[SchemeNorm][ColFg] = argv[++i]; ++ colortemp[1] = argv[++i]; + else if (!strcmp(argv[i], "-sb")) /* selected background color */ +- colors[SchemeSel][ColBg] = argv[++i]; ++ colortemp[2] = argv[++i]; + else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ +- colors[SchemeSel][ColFg] = argv[++i]; ++ colortemp[3] = argv[++i]; + else if (!strcmp(argv[i], "-w")) /* embedding window id */ + embed = argv[++i]; + else +@@ -772,8 +843,23 @@ + die("could not get embedding window attributes: 0x%lx", + parentwin); + drw = drw_create(dpy, screen, root, wa.width, wa.height); +- if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) ++ 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]); ++ ++ if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts))) + die("no fonts could be loaded."); ++ ++ free(fonts[0]); + lrpad = drw->fonts->h; + + #ifdef __OpenBSD__ +Only in /src/WORKING/dmenu: dwm +Only in /src/MASTER/dmenu/: .git +Only in /src/WORKING/dmenu: README.md -- cgit v1.2.3