update dmenu
This commit is contained in:
Regular → Executable
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "$(printf "Shutdown\nRestart\nLogout\nSuspend\nLock" | dmenu \
|
||||
-i -p \
|
||||
-i -z 200 -p \
|
||||
"Power:" -l 5)" in
|
||||
Shutdown) exec systemctl poweroff;;
|
||||
Restart) exec systemctl reboot;;
|
||||
|
||||
@@ -8,6 +8,12 @@ dmenu \- dynamic menu
|
||||
.IR lines ]
|
||||
.RB [ \-m
|
||||
.IR monitor ]
|
||||
.RB [ \-x
|
||||
.IR xoffset ]
|
||||
.RB [ \-y
|
||||
.IR yoffset ]
|
||||
.RB [ \-z
|
||||
.IR width ]
|
||||
.RB [ \-p
|
||||
.IR prompt ]
|
||||
.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
|
||||
from 0.
|
||||
.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"
|
||||
defines the prompt to be displayed to the left of the input field.
|
||||
.TP
|
||||
|
||||
+16
-6
@@ -37,6 +37,9 @@ struct item {
|
||||
static char text[BUFSIZ] = "";
|
||||
static char *embed;
|
||||
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 lrpad; /* sum of left and right padding */
|
||||
static size_t cursor;
|
||||
@@ -672,9 +675,9 @@ setup(void)
|
||||
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 + dmx;
|
||||
y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
|
||||
mw = (dmw>0 ? dmw : info[i].width);;
|
||||
XFree(info);
|
||||
} else
|
||||
#endif
|
||||
@@ -682,9 +685,9 @@ 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;
|
||||
x = dmx;
|
||||
y = topbar ? dmy : wa.height - mh - dmy;
|
||||
mw = (dmw>0 ? dmw : wa.width);
|
||||
}
|
||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
inputw = mw / 3; /* input width: ~33% of monitor width */
|
||||
@@ -725,6 +728,7 @@ static void
|
||||
usage(void)
|
||||
{
|
||||
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]");
|
||||
}
|
||||
|
||||
@@ -786,6 +790,12 @@ main(int argc, char *argv[])
|
||||
/* these options take one argument */
|
||||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||
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"))
|
||||
mon = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
||||
|
||||
+68
-8
@@ -15,6 +15,7 @@
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#endif
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
@@ -52,6 +53,10 @@ static XIC xic;
|
||||
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;
|
||||
@@ -626,8 +631,13 @@ setup(void)
|
||||
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);
|
||||
@@ -718,6 +728,41 @@ usage(void)
|
||||
" [-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[])
|
||||
{
|
||||
@@ -746,15 +791,15 @@ main(int argc, char *argv[])
|
||||
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 +817,23 @@ main(int argc, char *argv[])
|
||||
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__
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ static const Layout layouts[] = {
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
#define MODKEY Mod1Mask
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
|
||||
Reference in New Issue
Block a user