aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2010-06-29 16:07:31 +0100
committerConnor Lane Smith <cls@lubutu.com>2010-06-29 16:07:31 +0100
commit340b176de6db87471610c0a75450e0de9535b6ae (patch)
treec1ca4c81a196306ed360330da906de15971084e5
parent18dcf738967a45208e880b72ce273afdd93ee6c7 (diff)
dinput with dmenu flags, fixed usage & -v, cosmetics
-rw-r--r--dinput.c24
-rw-r--r--dmenu.c22
2 files changed, 32 insertions, 14 deletions
diff --git a/dinput.c b/dinput.c
index 0bf2679..b69dcb3 100644
--- a/dinput.c
+++ b/dinput.c
@@ -76,11 +76,11 @@ drawinput(void)
76 /* print prompt? */ 76 /* print prompt? */
77 if(prompt) { 77 if(prompt) {
78 dc.w = promptw; 78 dc.w = promptw;
79 drawtext(&dc, prompt, selcol, False); 79 drawtext(&dc, prompt, normcol, False);
80 dc.x += dc.w; 80 dc.x += dc.w;
81 } 81 }
82 dc.w = mw - dc.x; 82 dc.w = mw - dc.x;
83 drawtext(&dc, *text ? text : NULL, normcol, False); 83 drawtext(&dc, *text ? text : NULL, selcol, False);
84 drawcursor(); 84 drawcursor();
85 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 85 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
86 XFlush(dpy); 86 XFlush(dpy);
@@ -329,11 +329,15 @@ main(int argc, char *argv[]) {
329 /* command line args */ 329 /* command line args */
330 progname = argv[0]; 330 progname = argv[0];
331 for(i = 1; i < argc; i++) 331 for(i = 1; i < argc; i++)
332 if(!strcmp(argv[i], "-b")) 332 if(!strcmp(argv[i], "-i"))
333 ; /* ignore flag */
334 else if(!strcmp(argv[i], "-b"))
333 topbar = False; 335 topbar = False;
334 else if(!strcmp(argv[i], "-e")) { 336 else if(!strcmp(argv[i], "-e")) {
335 if(++i < argc) parent = atoi(argv[i]); 337 if(++i < argc) parent = atoi(argv[i]);
336 } 338 }
339 else if(!strcmp(argv[i], "-l"))
340 i++; /* ignore flag */
337 else if(!strcmp(argv[i], "-fn")) { 341 else if(!strcmp(argv[i], "-fn")) {
338 if(++i < argc) font = argv[i]; 342 if(++i < argc) font = argv[i];
339 } 343 }
@@ -352,13 +356,17 @@ main(int argc, char *argv[]) {
352 else if(!strcmp(argv[i], "-sf")) { 356 else if(!strcmp(argv[i], "-sf")) {
353 if(++i < argc) selfgcolor = argv[i]; 357 if(++i < argc) selfgcolor = argv[i];
354 } 358 }
355 else if(!strcmp(argv[i], "-v")) 359 else if(!strcmp(argv[i], "-v")) {
356 eprint("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n"); 360 printf("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n");
361 exit(EXIT_SUCCESS);
362 }
357 else if(!*text) 363 else if(!*text)
358 strncpy(text, argv[i], sizeof text); 364 strncpy(text, argv[i], sizeof text);
359 else 365 else {
360 eprint("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n" 366 fputs("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
361 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n"); 367 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n", stderr);
368 exit(EXIT_FAILURE);
369 }
362 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 370 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
363 fprintf(stderr, "dinput: warning: no locale support\n"); 371 fprintf(stderr, "dinput: warning: no locale support\n");
364 if(!(dpy = XOpenDisplay(NULL))) 372 if(!(dpy = XOpenDisplay(NULL)))
diff --git a/dmenu.c b/dmenu.c
index 8059f29..9e30add 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -49,6 +49,7 @@ static void setup(Bool topbar);
49#include "draw.h" 49#include "draw.h"
50 50
51/* variables */ 51/* variables */
52static char **argp = NULL;
52static char *maxname = NULL; 53static char *maxname = NULL;
53static char *prompt = NULL; 54static char *prompt = NULL;
54static char text[4096]; 55static char text[4096];
@@ -151,7 +152,9 @@ cleanup(void) {
151void 152void
152dinput(void) { 153dinput(void) {
153 cleanup(); 154 cleanup();
154 execlp("dinput", "dinput", text, NULL); /* todo: argv */ 155 argp[0] = "dinput";
156 argp[1] = text;
157 execvp("dinput", argp);
155 eprint("cannot exec dinput\n"); 158 eprint("cannot exec dinput\n");
156} 159}
157 160
@@ -587,11 +590,15 @@ main(int argc, char *argv[]) {
587 else if(!strcmp(argv[i], "-sf")) { 590 else if(!strcmp(argv[i], "-sf")) {
588 if(++i < argc) selfgcolor = argv[i]; 591 if(++i < argc) selfgcolor = argv[i];
589 } 592 }
590 else if(!strcmp(argv[i], "-v")) 593 else if(!strcmp(argv[i], "-v")) {
591 eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n"); 594 printf("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
592 else 595 exit(EXIT_SUCCESS);
593 eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n" 596 }
594 " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); 597 else {
598 fputs("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
599 " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr);
600 exit(EXIT_FAILURE);
601 }
595 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 602 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
596 fprintf(stderr, "dmenu: warning: no locale support\n"); 603 fprintf(stderr, "dmenu: warning: no locale support\n");
597 if(!(dpy = XOpenDisplay(NULL))) 604 if(!(dpy = XOpenDisplay(NULL)))
@@ -599,6 +606,9 @@ main(int argc, char *argv[]) {
599 screen = DefaultScreen(dpy); 606 screen = DefaultScreen(dpy);
600 if(!parent) 607 if(!parent)
601 parent = RootWindow(dpy, screen); 608 parent = RootWindow(dpy, screen);
609 if(!(argp = malloc(sizeof *argp * (argc+2))))
610 eprint("cannot malloc %u bytes\n", sizeof *argp * (argc+2));
611 memcpy(argp + 2, argv + 1, sizeof *argp * argc);
602 612
603 readstdin(); 613 readstdin();
604 running = grabkeyboard(); 614 running = grabkeyboard();