Compare commits
1 Commits
mydmenu
...
xresources
| Author | SHA1 | Date | |
|---|---|---|---|
| 64246c0e6d |
@ -2,8 +2,6 @@
|
|||||||
/* Default settings; can be overriden by command line. */
|
/* Default settings; can be overriden by command line. */
|
||||||
|
|
||||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
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 */
|
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||||
static const char *fonts[] = {
|
static const char *fonts[] = {
|
||||||
"monospace:size=10"
|
"monospace:size=10"
|
||||||
@ -17,7 +15,6 @@ static const char *colors[SchemeLast][2] = {
|
|||||||
};
|
};
|
||||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
static unsigned int lines = 0;
|
static unsigned int lines = 0;
|
||||||
static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Characters not considered part of a word while deleting words
|
* Characters not considered part of a word while deleting words
|
||||||
|
|||||||
29
config.h
29
config.h
@ -1,29 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
/* 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"
|
|
||||||
};
|
|
||||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
|
||||||
static const char *colors[SchemeLast][2] = {
|
|
||||||
/* fg bg */
|
|
||||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
|
||||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
|
||||||
[SchemeOut] = { "#000000", "#00ffff" },
|
|
||||||
};
|
|
||||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
|
||||||
static unsigned int lines = 0;
|
|
||||||
static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters not considered part of a word while deleting words
|
|
||||||
* for example: " /?\"&[]"
|
|
||||||
*/
|
|
||||||
static const char worddelimiters[] = " ";
|
|
||||||
|
|
||||||
/* Size of the window border */
|
|
||||||
static const unsigned int border_width = 5;
|
|
||||||
6
dmenu.1
6
dmenu.1
@ -40,9 +40,6 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
|
|||||||
.B \-b
|
.B \-b
|
||||||
dmenu appears at the bottom of the screen.
|
dmenu appears at the bottom of the screen.
|
||||||
.TP
|
.TP
|
||||||
.B \-c
|
|
||||||
dmenu appears centered on the screen.
|
|
||||||
.TP
|
|
||||||
.B \-f
|
.B \-f
|
||||||
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
|
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.
|
is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||||
@ -53,9 +50,6 @@ dmenu matches menu items case insensitively.
|
|||||||
.BI \-l " lines"
|
.BI \-l " lines"
|
||||||
dmenu lists items vertically, with the given number of lines.
|
dmenu lists items vertically, with the given number of lines.
|
||||||
.TP
|
.TP
|
||||||
.BI \-h " height"
|
|
||||||
dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
|
|
||||||
.TP
|
|
||||||
.BI \-m " monitor"
|
.BI \-m " monitor"
|
||||||
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.
|
||||||
|
|||||||
74
dmenu.c
74
dmenu.c
@ -25,8 +25,6 @@
|
|||||||
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
|
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
|
||||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
#define NUMBERSMAXDIGITS 100
|
|
||||||
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
|
|
||||||
|
|
||||||
/* enums */
|
/* enums */
|
||||||
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||||
@ -37,7 +35,6 @@ struct item {
|
|||||||
int out;
|
int out;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char numbers[NUMBERSBUFSIZE] = "";
|
|
||||||
static char text[BUFSIZ] = "";
|
static char text[BUFSIZ] = "";
|
||||||
static char *embed;
|
static char *embed;
|
||||||
static int bh, mw, mh;
|
static int bh, mw, mh;
|
||||||
@ -93,15 +90,6 @@ calcoffsets(void)
|
|||||||
break;
|
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
|
static void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
@ -139,27 +127,12 @@ drawitem(struct item *item, int x, int y, int w)
|
|||||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
recalculatenumbers()
|
|
||||||
{
|
|
||||||
unsigned int numer = 0, denom = 0;
|
|
||||||
struct item *item;
|
|
||||||
if (matchend) {
|
|
||||||
numer++;
|
|
||||||
for (item = matchend; item && item->left; item = item->left)
|
|
||||||
numer++;
|
|
||||||
}
|
|
||||||
for (item = items; item && item->text; item++)
|
|
||||||
denom++;
|
|
||||||
snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawmenu(void)
|
drawmenu(void)
|
||||||
{
|
{
|
||||||
unsigned int curpos;
|
unsigned int curpos;
|
||||||
struct item *item;
|
struct item *item;
|
||||||
int x = 0, y = 0, fh = drw->fonts->h, w;
|
int x = 0, y = 0, w;
|
||||||
|
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||||
@ -176,10 +149,9 @@ drawmenu(void)
|
|||||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||||
if ((curpos += lrpad / 2 - 1) < w) {
|
if ((curpos += lrpad / 2 - 1) < w) {
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
drw_rect(drw, x + curpos, 2 + (bh-fh)/2, 2, fh - 4, 1, 0);
|
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
recalculatenumbers();
|
|
||||||
if (lines > 0) {
|
if (lines > 0) {
|
||||||
/* draw vertical list */
|
/* draw vertical list */
|
||||||
for (item = curr; item != next; item = item->right)
|
for (item = curr; item != next; item = item->right)
|
||||||
@ -194,15 +166,13 @@ drawmenu(void)
|
|||||||
}
|
}
|
||||||
x += w;
|
x += w;
|
||||||
for (item = curr; item != next; item = item->right)
|
for (item = curr; item != next; item = item->right)
|
||||||
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
|
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
|
||||||
if (next) {
|
if (next) {
|
||||||
w = TEXTW(">");
|
w = TEXTW(">");
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
|
drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
|
||||||
drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
|
|
||||||
drw_map(drw, win, 0, 0, mw, mh);
|
drw_map(drw, win, 0, 0, mw, mh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,10 +615,8 @@ setup(void)
|
|||||||
|
|
||||||
/* calculate menu geometry */
|
/* calculate menu geometry */
|
||||||
bh = drw->fonts->h + 2;
|
bh = drw->fonts->h + 2;
|
||||||
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
|
|
||||||
lines = MAX(lines, 0);
|
lines = MAX(lines, 0);
|
||||||
mh = (lines + 1) * bh;
|
mh = (lines + 1) * bh;
|
||||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
i = 0;
|
i = 0;
|
||||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||||
@ -675,16 +643,9 @@ setup(void)
|
|||||||
if (INTERSECT(x, y, 1, 1, info[i]))
|
if (INTERSECT(x, y, 1, 1, info[i]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (centered) {
|
x = info[i].x_org;
|
||||||
mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
|
y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
||||||
x = info[i].x_org + ((info[i].width - mw) / 2);
|
mw = info[i].width;
|
||||||
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);
|
XFree(info);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@ -692,17 +653,11 @@ 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;
|
||||||
if (centered) {
|
y = topbar ? 0 : wa.height - mh;
|
||||||
mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
|
mw = 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 = MIN(inputw, mw/3);
|
inputw = MIN(inputw, mw/3);
|
||||||
match();
|
match();
|
||||||
|
|
||||||
@ -741,7 +696,6 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||||
" [-h height]\n"
|
|
||||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
|
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -796,8 +750,6 @@ main(int argc, char *argv[])
|
|||||||
topbar = 0;
|
topbar = 0;
|
||||||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
|
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
|
||||||
fast = 1;
|
fast = 1;
|
||||||
else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
|
|
||||||
centered = 1;
|
|
||||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||||
fstrncmp = strncasecmp;
|
fstrncmp = strncasecmp;
|
||||||
fstrstr = cistrstr;
|
fstrstr = cistrstr;
|
||||||
@ -812,10 +764,6 @@ main(int argc, char *argv[])
|
|||||||
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];
|
fonts[0] = argv[++i];
|
||||||
else if(!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
|
|
||||||
lineheight = atoi(argv[++i]);
|
|
||||||
lineheight = MAX(lineheight,8); /* reasonable default in case of value too small/negative */
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i], "-nb")) /* normal background color */
|
else if (!strcmp(argv[i], "-nb")) /* normal background color */
|
||||||
colors[SchemeNorm][ColBg] = argv[++i];
|
colors[SchemeNorm][ColBg] = argv[++i];
|
||||||
else if (!strcmp(argv[i], "-nf")) /* normal foreground color */
|
else if (!strcmp(argv[i], "-nf")) /* normal foreground color */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user