From: Daniel Guihot Subject: [dmenu][patch] floatingmenu v1.0 - floating dmenu bar with padding/height/border (extension of floatingstatus for dwm) NOTE: Added extra flag, '-bo', which allows you to specify the colour of the border explicitly. By default, the background just inherits the '-sb' flag, to cooperate with default dwm behaviour. This is my first time patching suckless software. Please feel free to email me if you encounter any issues. See also: https://dwm.suckless.org/patches/floatingstatus/ diff --git a/config.def.h b/config.def.h --- a/config.def.h +++ b/config.def.h @@ -2,6 +2,12 @@ /* Default settings; can be overriden by command line. */ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ + +static unsigned int barpadh = 200; +static unsigned int barpadv = 10; +static unsigned int barheight = 2; +static unsigned int barborder = 2; + /* -fn option overrides fonts[0]; default X11 font or font set */ static const char *fonts[] = { "monospace:size=10" @@ -12,6 +18,7 @@ [SchemeNorm] = { "#bbbbbb", "#222222" }, [SchemeSel] = { "#eeeeee", "#005577" }, [SchemeOut] = { "#000000", "#00ffff" }, + [SchemeBorder] = { "#005577", "#005577" }, }; /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ static unsigned int lines = 0; diff --git a/dmenu.c b/dmenu.c --- a/dmenu.c +++ b/dmenu.c @@ -25,7 +25,7 @@ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) /* enums */ -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ +enum { SchemeNorm, SchemeSel, SchemeOut, SchemeBorder, SchemeLast }; /* color schemes */ struct item { char *text; @@ -633,7 +633,7 @@ utf8 = XInternAtom(dpy, "UTF8_STRING", False); /* calculate menu geometry */ - bh = drw->fonts->h + 2; + bh = drw->fonts->h + 2 + 2 * barheight; lines = MAX(lines, 0); mh = (lines + 1) * bh; #ifdef XINERAMA @@ -662,9 +662,9 @@ 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; + x = info[i].x_org + barpadh; + y = info[i].y_org + (topbar ? barpadv : info[i].height - mh - barpadv); + mw = info[i].width - 2 * barpadh; XFree(info); } else #endif @@ -672,9 +672,9 @@ 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; + x = barpadh; + y = topbar ? barpadv : wa.height - mh - barpadv; + mw = wa.width - 2 * barpadh; } promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; inputw = mw / 3; /* input width: ~33% of monitor width */ @@ -684,9 +684,11 @@ 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, mw, mh, barborder, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); + if (barborder) + XSetWindowBorder(dpy, win, scheme[SchemeBorder][ColFg].pixel); XSetClassHint(dpy, win, &ch); /* input methods */ @@ -751,10 +753,14 @@ colors[SchemeNorm][ColBg] = argv[++i]; else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ colors[SchemeNorm][ColFg] = argv[++i]; - else if (!strcmp(argv[i], "-sb")) /* selected background color */ + else if (!strcmp(argv[i], "-sb")) { /* selected background color */ colors[SchemeSel][ColBg] = argv[++i]; + colors[SchemeSel][ColFg] = colors[SchemeSel][ColBg]; + } else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ colors[SchemeSel][ColFg] = argv[++i]; + else if (!strcmp(argv[i], "-bo")) /* border colour */ + colors[SchemeBorder][ColFg] = argv[++i]; else if (!strcmp(argv[i], "-ob")) /* outline background color */ colors[SchemeOut][ColBg] = argv[++i]; else if (!strcmp(argv[i], "-of")) /* outline foreground color */