update dmenu

This commit is contained in:
wt committed 2024-11-06 16:20:59 +07:00
1 parent 127beafbde
commit f78044fca6
5 files changed
+110 -16

No files matched your search

Regular → Executable
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
case "$(printf "Shutdown\nRestart\nLogout\nSuspend\nLock" | dmenu \ case "$(printf "Shutdown\nRestart\nLogout\nSuspend\nLock" | dmenu \
-i -p \ -i -z 200 -p \
"Power:" -l 5)" in "Power:" -l 5)" in
Shutdown) exec systemctl poweroff;; Shutdown) exec systemctl poweroff;;
Restart) exec systemctl reboot;; Restart) exec systemctl reboot;;
+24
View File
@@ -8,6 +8,12 @@ dmenu \- dynamic menu
.IR lines ] .IR lines ]
.RB [ \-m .RB [ \-m
.IR monitor ] .IR monitor ]
.RB [ \-x
.IR xoffset ]
.RB [ \-y
.IR yoffset ]
.RB [ \-z
.IR width ]
.RB [ \-p .RB [ \-p
.IR prompt ] .IR prompt ]
.RB [ \-fn .RB [ \-fn
@@ -54,6 +60,24 @@ dmenu lists items vertically, with the given number of lines.
dmenu is displayed on the monitor number supplied. Monitor numbers are starting dmenu is displayed on the monitor number supplied. Monitor numbers are starting
from 0. from 0.
.TP .TP
.BI \-x " xoffset"
dmenu is placed at this offset measured from the left side of the monitor.
Can be negative.
If option
.B \-m
is present, the measurement will use the given monitor.
.TP
.BI \-y " yoffset"
dmenu is placed at this offset measured from the top of the monitor. If the
.B \-b
option is used, the offset is measured from the bottom. Can be negative.
If option
.B \-m
is present, the measurement will use the given monitor.
.TP
.BI \-z " width"
sets the width of the dmenu window.
.TP
.BI \-p " prompt" .BI \-p " prompt"
defines the prompt to be displayed to the left of the input field. defines the prompt to be displayed to the left of the input field.
.TP .TP
+16 -6
View File
@@ -37,6 +37,9 @@ struct item {
static char text[BUFSIZ] = ""; static char text[BUFSIZ] = "";
static char *embed; static char *embed;
static int bh, mw, mh; static int bh, mw, mh;
static int dmx = 0; /* put dmenu at this x offset */
static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
static unsigned int dmw = 0; /* make dmenu this wide */
static int inputw = 0, promptw; static int inputw = 0, promptw;
static int lrpad; /* sum of left and right padding */ static int lrpad; /* sum of left and right padding */
static size_t cursor; static size_t cursor;
@@ -672,9 +675,9 @@ setup(void)
if (INTERSECT(x, y, 1, 1, info[i]) != 0) if (INTERSECT(x, y, 1, 1, info[i]) != 0)
break; break;
x = info[i].x_org; x = info[i].x_org + dmx;
y = info[i].y_org + (topbar ? 0 : info[i].height - mh); y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
mw = info[i].width; mw = (dmw>0 ? dmw : info[i].width);;
XFree(info); XFree(info);
} else } else
#endif #endif
@@ -682,9 +685,9 @@ setup(void)
if (!XGetWindowAttributes(dpy, parentwin, &wa)) if (!XGetWindowAttributes(dpy, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx", die("could not get embedding window attributes: 0x%lx",
parentwin); parentwin);
x = 0; x = dmx;
y = topbar ? 0 : wa.height - mh; y = topbar ? dmy : wa.height - mh - dmy;
mw = wa.width; mw = (dmw>0 ? dmw : wa.width);
} }
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
inputw = mw / 3; /* input width: ~33% of monitor width */ inputw = mw / 3; /* input width: ~33% of monitor width */
@@ -725,6 +728,7 @@ static void
usage(void) usage(void)
{ {
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
" [-x xoffset] [-y yoffset] [-z width]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
} }
@@ -786,6 +790,12 @@ main(int argc, char *argv[])
/* these options take one argument */ /* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]); lines = atoi(argv[++i]);
else if (!strcmp(argv[i], "-x")) /* window x offset */
dmx = atoi(argv[++i]);
else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */
dmy = atoi(argv[++i]);
else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */
dmw = atoi(argv[++i]);
else if (!strcmp(argv[i], "-m")) else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]); mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
+68 -8
View File
@@ -15,6 +15,7 @@
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
#endif #endif
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#include <X11/Xresource.h>
#include "drw.h" #include "drw.h"
#include "util.h" #include "util.h"
@@ -52,6 +53,10 @@ static XIC xic;
static Drw *drw; static Drw *drw;
static Clr *scheme[SchemeLast]; static Clr *scheme[SchemeLast];
/* Temporary arrays to allow overriding xresources values */
static char *colortemp[4];
static char *tempfonts;
#include "config.h" #include "config.h"
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
@@ -626,8 +631,13 @@ setup(void)
int a, di, n, area = 0; int a, di, n, area = 0;
#endif #endif
/* init appearance */ /* init appearance */
for (j = 0; j < SchemeLast; j++) for (j = 0; j < SchemeLast; j++) {
scheme[j] = drw_scm_create(drw, colors[j], 2); 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); clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False); utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@@ -718,6 +728,41 @@ usage(void)
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); " [-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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@@ -746,15 +791,15 @@ main(int argc, char *argv[])
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i]; prompt = argv[++i];
else if (!strcmp(argv[i], "-fn")) /* font or font set */ 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 */ 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 */ 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 */ 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 */ 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 */ else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i]; embed = argv[++i];
else else
@@ -772,8 +817,23 @@ main(int argc, char *argv[])
die("could not get embedding window attributes: 0x%lx", die("could not get embedding window attributes: 0x%lx",
parentwin); parentwin);
drw = drw_create(dpy, screen, root, wa.width, wa.height); 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."); die("no fonts could be loaded.");
free(fonts[0]);
lrpad = drw->fonts->h; lrpad = drw->fonts->h;
#ifdef __OpenBSD__ #ifdef __OpenBSD__
+1 -1
View File
@@ -48,7 +48,7 @@ static const Layout layouts[] = {
}; };
/* key definitions */ /* key definitions */
#define MODKEY Mod1Mask #define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \ #define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \