1
0

FUNCTIONAL

This commit is contained in:
Deven Blake 2021-05-16 00:24:38 -04:00
parent 577c419c2a
commit dd9ec127dc

View File

@ -26,22 +26,12 @@
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
enum { Scheme, SchemeLast }; /* color schemes */
struct item {
char *text;
struct item *left, *right;
int out;
};
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
static int inputw = 0, promptw;
static int inputw = 0;
static int lrpad; /* sum of left and right padding */
static struct item *items = NULL;
static struct item *matches, *matchend;
static struct item *prev, *curr, *next, *sel;
static int mon = -1, screen;
static Atom clip, utf8;
@ -57,21 +47,6 @@ static Clr *scheme[SchemeLast];
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr;
static void
calcoffsets(void)
{
int i, n;
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right)
if ((i ? bh : MIN(TEXTW(next->text), n)) > n)
break;
for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
if ((i ? bh : MIN(TEXTW(prev->left->text), n)) > n)
break;
}
static void
cleanup(void)
{
@ -86,19 +61,25 @@ cleanup(void)
}
static void
drawmenu(void)
drawmenu(char *text)
{
int x = 0, y = 0, w;
drw_setscheme(drw, scheme[SchemeSel]);
drw_setscheme(drw, scheme[Scheme]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
if (prompt && *prompt)
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
if (text && *text)
x = drw_text(drw, x, 0, textw(text), bh, lrpad / 2, text, 0);
drw_map(drw, win, 0, 0, mw, mh);
}
int
textw(char *text)
{
return (text && *text) ? TEXTW(text) - lrpad / 4 : 0;
}
static void
setup(void)
{
@ -164,12 +145,11 @@ setup(void)
y = topbar ? 0 : wa.height - mh;
mw = wa.width;
}
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
inputw = MIN(inputw, mw/3);
/* create menu window */
swa.override_redirect = True;
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
swa.background_pixel = scheme[Scheme][ColBg].pixel;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
CopyFromParent, CopyFromParent, CopyFromParent,
@ -194,13 +174,13 @@ setup(void)
}
}
drw_resize(drw, mw, mh);
drawmenu();
//drawmenu();
}
static void
usage(void)
{
fputs("usage: dmenu [-bfiv] [-p prompt] [-fn font] [-m monitor]\n"
fputs("usage: dmenu [-bfiv] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
exit(1);
}
@ -210,6 +190,9 @@ main(int argc, char *argv[])
{
XWindowAttributes wa;
int i;
char text[text_s];
for(i = 0; i < text_s; ++i)
text[i] = '\0';
for (i = 1; i < argc; i++)
/* these options take no arguments */
@ -223,14 +206,12 @@ main(int argc, char *argv[])
/* these options take one argument */
else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]);
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];
else if (!strcmp(argv[i], "-b")) /* selected background color */
colors[SchemeSel][ColBg] = argv[++i];
colors[Scheme][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-f")) /* selected foreground color */
colors[SchemeSel][ColFg] = argv[++i];
colors[Scheme][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
else
@ -258,7 +239,12 @@ main(int argc, char *argv[])
#endif
setup();
while(1); // bodge
do{
/* fgets adds a newline which will be printable in some fonts */
if(strlen(text) > 0)
text[strlen(text)-1] = '\0';
drawmenu(text);
}while(fgets(text, text_s, stdin) != NULL);
return 1; /* unreachable */
}