edryd.org

some of my neat stuff
git clone git://edryd.org/edryd.org
Log | Files | Refs | LICENSE

commit b9ccd3e4eedc075d7484421667606a274186a4d7
parent d0b7335e628ea7ec0e0a4320c4f22df5f6931769
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 17 Mar 2018 23:49:10 -0700

Make dmenu-center an external link to suckless

Diffstat:
_data/projects.yml | 1+
projects/dmenu-center-20161108-a9a5c6c.diff | 94-------------------------------------------------------------------------------
projects/dmenu-center-4.6.diff | 91-------------------------------------------------------------------------------
projects/dmenu-center.md | 16----------------
4 files changed, 1 insertion(+), 201 deletions(-)

diff --git a/_data/projects.yml b/_data/projects.yml @@ -16,6 +16,7 @@ main: desc: 'dmenu functions for vim' - name: 'dmenu-center' desc: 'center dmenu in the middle of the screen' + link: 'https://tools.suckless.org/dmenu/patches/center.html' - name: 'catium.vim' desc: 'add an element of nyan cat to vim' - name: 'tim' diff --git a/projects/dmenu-center-20161108-a9a5c6c.diff b/projects/dmenu-center-20161108-a9a5c6c.diff @@ -1,94 +0,0 @@ -diff --git a/dmenu.c b/dmenu.c -index 9278e91..23c7038 100644 ---- a/dmenu.c -+++ b/dmenu.c -@@ -43,6 +43,7 @@ static struct item *items = NULL; - static struct item *matches, *matchend; - static struct item *prev, *curr, *next, *sel; - static int mon = -1, screen; -+static int center = 0; - - static Atom clip, utf8; - static Display *dpy; -@@ -88,6 +89,15 @@ calcoffsets(void) - 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) - { -@@ -562,6 +572,7 @@ setup(void) - bh = drw->fonts->h + 2; - lines = MAX(lines, 0); - mh = (lines + 1) * bh; -+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; - #ifdef XINERAMA - if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { - XGetInputFocus(dpy, &w, &di); -@@ -587,9 +598,15 @@ setup(void) - if (INTERSECT(x, y, 1, 1, info[i])) - break; - -- x = info[i].x_org; -- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); -- mw = info[i].width; -+ if (center) { -+ mw = MAX(max_textw() + promptw, 100); -+ 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 -@@ -597,11 +614,16 @@ setup(void) - 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 (center) { -+ mw = MAX(max_textw() + promptw, 100); -+ 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 = MIN(inputw, mw/3); - match(); - -@@ -635,7 +657,7 @@ setup(void) - static void - usage(void) - { -- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" -+ fputs("usage: dmenu [-bcfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); - exit(1); - } -@@ -653,6 +675,8 @@ main(int argc, char *argv[]) - exit(0); - } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ - topbar = 0; -+ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ -+ center = 1; - else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ - fast = 1; - else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ diff --git a/projects/dmenu-center-4.6.diff b/projects/dmenu-center-4.6.diff @@ -1,91 +0,0 @@ -diff --git a/dmenu.c b/dmenu.c -index a07f8e3..3cc1f00 100644 ---- a/dmenu.c -+++ b/dmenu.c -@@ -43,6 +43,7 @@ static struct item *items = NULL; - static struct item *matches, *matchend; - static struct item *prev, *curr, *next, *sel; - static int mon = -1, screen; -+static int center = 0; - - static Atom clip, utf8; - static Display *dpy; -@@ -88,6 +89,15 @@ calcoffsets(void) - 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) - { -@@ -546,6 +556,7 @@ setup(void) - bh = drw->fonts[0]->h + 2; - lines = MAX(lines, 0); - mh = (lines + 1) * bh; -+ promptw = (prompt && *prompt) ? TEXTW(prompt) : 0; - #ifdef XINERAMA - if ((info = XineramaQueryScreens(dpy, &n))) { - XGetInputFocus(dpy, &w, &di); -@@ -571,18 +582,29 @@ setup(void) - if (INTERSECT(x, y, 1, 1, info[i])) - break; - -- x = info[i].x_org; -- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); -- mw = info[i].width; -+ if (center) { -+ mw = MAX(max_textw() + promptw, 100); -+ 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 - { -- x = 0; -- y = topbar ? 0 : sh - mh; -- mw = sw; -+ if (center) { -+ mw = MAX(max_textw() + promptw, 100); -+ x = (sw - mw) / 2; -+ y = (sh - mh) / 2; -+ } else { -+ x = 0; -+ y = topbar ? 0 : sh - mh; -+ mw = sw; -+ } - } -- promptw = (prompt && *prompt) ? TEXTW(prompt) : 0; - inputw = MIN(inputw, mw/3); - match(); - -@@ -608,7 +630,7 @@ setup(void) - static void - usage(void) - { -- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" -+ fputs("usage: dmenu [-b] [-c] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" - " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); - exit(1); - } -@@ -625,6 +647,8 @@ main(int argc, char *argv[]) - exit(0); - } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ - topbar = 0; -+ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ -+ center = 1; - else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ - fast = 1; - else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ diff --git a/projects/dmenu-center.md b/projects/dmenu-center.md @@ -1,16 +0,0 @@ ---- -title: dmenu-center -description: 'patch to center dmenu in the middle of the screen' -tags: dmenu patch c suckless ---- - -Center dmenu in the middle of the screen with `-c` argument. - -## Download - -* [dmenu-center-20161108-a9a5c6c.diff](dmenu-center-20161108-a9a5c6c.diff) -* [dmenu-center-4.6.diff](dmenu-center-4.6.diff) - -## Authors - -* ed <edvb54@gmail.com>