1
0

dinput with dmenu flags, fixed usage & -v, cosmetics

This commit is contained in:
Connor Lane Smith 2010-06-29 16:07:31 +01:00
parent 18dcf73896
commit 340b176de6
2 changed files with 32 additions and 14 deletions

View File

@ -76,11 +76,11 @@ drawinput(void)
/* print prompt? */ /* print prompt? */
if(prompt) { if(prompt) {
dc.w = promptw; dc.w = promptw;
drawtext(&dc, prompt, selcol, False); drawtext(&dc, prompt, normcol, False);
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = mw - dc.x; dc.w = mw - dc.x;
drawtext(&dc, *text ? text : NULL, normcol, False); drawtext(&dc, *text ? text : NULL, selcol, False);
drawcursor(); drawcursor();
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy); XFlush(dpy);
@ -329,11 +329,15 @@ main(int argc, char *argv[]) {
/* command line args */ /* command line args */
progname = argv[0]; progname = argv[0];
for(i = 1; i < argc; i++) for(i = 1; i < argc; i++)
if(!strcmp(argv[i], "-b")) if(!strcmp(argv[i], "-i"))
; /* ignore flag */
else if(!strcmp(argv[i], "-b"))
topbar = False; topbar = False;
else if(!strcmp(argv[i], "-e")) { else if(!strcmp(argv[i], "-e")) {
if(++i < argc) parent = atoi(argv[i]); if(++i < argc) parent = atoi(argv[i]);
} }
else if(!strcmp(argv[i], "-l"))
i++; /* ignore flag */
else if(!strcmp(argv[i], "-fn")) { else if(!strcmp(argv[i], "-fn")) {
if(++i < argc) font = argv[i]; if(++i < argc) font = argv[i];
} }
@ -352,13 +356,17 @@ main(int argc, char *argv[]) {
else if(!strcmp(argv[i], "-sf")) { else if(!strcmp(argv[i], "-sf")) {
if(++i < argc) selfgcolor = argv[i]; if(++i < argc) selfgcolor = argv[i];
} }
else if(!strcmp(argv[i], "-v")) else if(!strcmp(argv[i], "-v")) {
eprint("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n"); printf("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n");
exit(EXIT_SUCCESS);
}
else if(!*text) else if(!*text)
strncpy(text, argv[i], sizeof text); strncpy(text, argv[i], sizeof text);
else else {
eprint("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n" fputs("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n"); " [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n", stderr);
exit(EXIT_FAILURE);
}
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fprintf(stderr, "dinput: warning: no locale support\n"); fprintf(stderr, "dinput: warning: no locale support\n");
if(!(dpy = XOpenDisplay(NULL))) if(!(dpy = XOpenDisplay(NULL)))

22
dmenu.c
View File

@ -49,6 +49,7 @@ static void setup(Bool topbar);
#include "draw.h" #include "draw.h"
/* variables */ /* variables */
static char **argp = NULL;
static char *maxname = NULL; static char *maxname = NULL;
static char *prompt = NULL; static char *prompt = NULL;
static char text[4096]; static char text[4096];
@ -151,7 +152,9 @@ cleanup(void) {
void void
dinput(void) { dinput(void) {
cleanup(); cleanup();
execlp("dinput", "dinput", text, NULL); /* todo: argv */ argp[0] = "dinput";
argp[1] = text;
execvp("dinput", argp);
eprint("cannot exec dinput\n"); eprint("cannot exec dinput\n");
} }
@ -587,11 +590,15 @@ main(int argc, char *argv[]) {
else if(!strcmp(argv[i], "-sf")) { else if(!strcmp(argv[i], "-sf")) {
if(++i < argc) selfgcolor = argv[i]; if(++i < argc) selfgcolor = argv[i];
} }
else if(!strcmp(argv[i], "-v")) else if(!strcmp(argv[i], "-v")) {
eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n"); printf("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
else exit(EXIT_SUCCESS);
eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n" }
" [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); else {
fputs("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
" [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr);
exit(EXIT_FAILURE);
}
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fprintf(stderr, "dmenu: warning: no locale support\n"); fprintf(stderr, "dmenu: warning: no locale support\n");
if(!(dpy = XOpenDisplay(NULL))) if(!(dpy = XOpenDisplay(NULL)))
@ -599,6 +606,9 @@ main(int argc, char *argv[]) {
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
if(!parent) if(!parent)
parent = RootWindow(dpy, screen); parent = RootWindow(dpy, screen);
if(!(argp = malloc(sizeof *argp * (argc+2))))
eprint("cannot malloc %u bytes\n", sizeof *argp * (argc+2));
memcpy(argp + 2, argv + 1, sizeof *argp * argc);
readstdin(); readstdin();
running = grabkeyboard(); running = grabkeyboard();