FUNCTIONAL
This commit is contained in:
parent
577c419c2a
commit
dd9ec127dc
@ -26,22 +26,12 @@
|
|||||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
|
||||||
/* enums */
|
/* 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 char *embed;
|
||||||
static int bh, mw, mh;
|
static int bh, mw, mh;
|
||||||
static int inputw = 0, promptw;
|
static int inputw = 0;
|
||||||
static int lrpad; /* sum of left and right padding */
|
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 int mon = -1, screen;
|
||||||
|
|
||||||
static Atom clip, utf8;
|
static Atom clip, utf8;
|
||||||
@ -57,21 +47,6 @@ static Clr *scheme[SchemeLast];
|
|||||||
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
|
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
|
||||||
static char *(*fstrstr)(const char *, const char *) = strstr;
|
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
|
static void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
@ -86,19 +61,25 @@ cleanup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawmenu(void)
|
drawmenu(char *text)
|
||||||
{
|
{
|
||||||
int x = 0, y = 0, w;
|
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);
|
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||||
|
|
||||||
if (prompt && *prompt)
|
if (text && *text)
|
||||||
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
|
x = drw_text(drw, x, 0, textw(text), bh, lrpad / 2, text, 0);
|
||||||
|
|
||||||
drw_map(drw, win, 0, 0, mw, mh);
|
drw_map(drw, win, 0, 0, mw, mh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
textw(char *text)
|
||||||
|
{
|
||||||
|
return (text && *text) ? TEXTW(text) - lrpad / 4 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup(void)
|
setup(void)
|
||||||
{
|
{
|
||||||
@ -164,12 +145,11 @@ setup(void)
|
|||||||
y = topbar ? 0 : wa.height - mh;
|
y = topbar ? 0 : wa.height - mh;
|
||||||
mw = wa.width;
|
mw = wa.width;
|
||||||
}
|
}
|
||||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
|
||||||
inputw = MIN(inputw, mw/3);
|
inputw = MIN(inputw, mw/3);
|
||||||
|
|
||||||
/* create menu window */
|
/* create menu window */
|
||||||
swa.override_redirect = True;
|
swa.override_redirect = True;
|
||||||
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
swa.background_pixel = scheme[Scheme][ColBg].pixel;
|
||||||
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
||||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||||
@ -194,13 +174,13 @@ setup(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
drw_resize(drw, mw, mh);
|
drw_resize(drw, mw, mh);
|
||||||
drawmenu();
|
//drawmenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(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);
|
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -210,6 +190,9 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
XWindowAttributes wa;
|
XWindowAttributes wa;
|
||||||
int i;
|
int i;
|
||||||
|
char text[text_s];
|
||||||
|
for(i = 0; i < text_s; ++i)
|
||||||
|
text[i] = '\0';
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
/* these options take no arguments */
|
/* these options take no arguments */
|
||||||
@ -223,14 +206,12 @@ main(int argc, char *argv[])
|
|||||||
/* these options take one argument */
|
/* these options take one argument */
|
||||||
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 */
|
|
||||||
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], "-b")) /* selected background color */
|
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 */
|
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 */
|
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||||
embed = argv[++i];
|
embed = argv[++i];
|
||||||
else
|
else
|
||||||
@ -258,7 +239,12 @@ main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
setup();
|
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 */
|
return 1; /* unreachable */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user