[hackers] [wmii] add wimenu prompt support || Bart Trojanowski

From: <hg_AT_suckless.org>
Date: Mon, 30 Mar 2009 03:11:35 +0000 (UTC)

changeset: 2440:1b1343972f22
user: Bart Trojanowski <bart_AT_jukie.net>
date: Sun Mar 29 23:01:07 2009 -0400
files: cmd/menu/dat.h cmd/menu/main.c cmd/menu/menu.c cmd/wmiir.c
description:
add wimenu prompt support

diff -r e93d2245fe20 -r 1b1343972f22 cmd/menu/dat.h
--- a/cmd/menu/dat.h Wed Mar 18 18:16:13 2009 -0400
+++ b/cmd/menu/dat.h Sun Mar 29 23:01:07 2009 -0400
@@ -72,6 +72,9 @@
 EXTERN char* (*find)(const char*, const char*);
 EXTERN int (*compare)(const char*, const char*, size_t);
 
+EXTERN char* prompt;
+EXTERN int promptw;
+
 EXTERN char buffer[8092];
 EXTERN char* _buffer;
 
diff -r e93d2245fe20 -r 1b1343972f22 cmd/menu/main.c
--- a/cmd/menu/main.c Wed Mar 18 18:16:13 2009 -0400
+++ b/cmd/menu/main.c Sun Mar 29 23:01:07 2009 -0400
@@ -21,7 +21,7 @@
 
 static void
 usage(void) {
- fatal("usage: wimenu -i [-h <history>] [-a <address>]\n");
+ fatal("usage: wimenu -i [-h <history>] [-a <address>] [-p <prompt>]\n");
 }
 
 static int
@@ -214,6 +214,8 @@
         fmtinstall('r', errfmt);
         address = getenv("WMII_ADDRESS");
         histfile = nil;
+ prompt = nil;
+ promptw = 0;
 
         find = strstr;
         compare = strncmp;
@@ -229,6 +231,9 @@
                 break;
         case 'n':
                 ndump = strtol(EARGF(usage()), nil, 10);
+ break;
+ case 'p':
+ prompt = EARGF(usage());
                 break;
         case 'i':
                 find = strcasestr;
diff -r e93d2245fe20 -r 1b1343972f22 cmd/menu/menu.c
--- a/cmd/menu/menu.c Wed Mar 18 18:16:13 2009 -0400
+++ b/cmd/menu/menu.c Sun Mar 29 23:01:07 2009 -0400
@@ -117,20 +117,30 @@
 
 static void
 menu_draw(void) {
- Rectangle r, r2;
+ Rectangle r, rd, rp, r2;
         CTuple *c;
         Item *i;
         int inputw, itemoff, end, pad, n;
 
         r = barwin->r;
         r = rectsetorigin(r, ZP);
- r2 = r;
 
         pad = (font->height & ~1);
- inputw = min(Dx(r) / 3, maxwidth);
+
+ rd = r;
+ if (prompt) {
+ if (!promptw)
+ promptw = textwidth(font, prompt) + 2 * ltwidth;
+ rd.min.x += promptw;
+
+ rp = r;
+ rp.max.x = promptw;
+ }
+
+ inputw = min(Dx(rd) / 3, maxwidth);
         inputw = max(inputw, textwidth(font, input.string)) + pad;
         itemoff = inputw + 2 * ltwidth;
- end = Dx(r) - ltwidth;
+ end = Dx(rd) - ltwidth;
 
         fill(ibuf, r, cnorm.bg);
 
@@ -155,10 +165,11 @@
         if(matchidx == nil)
                 matchidx = matchstart;
 
+ r2 = rd;
         for(i=matchstart; i->string; i=i->next) {
- r2.min.x = itemoff;
+ r2.min.x = promptw + itemoff;
                 itemoff = itemoff + i->width + pad;
- r2.max.x = min(itemoff, end);
+ r2.max.x = promptw + min(itemoff, end);
                 if(i != matchstart && itemoff > end)
                         break;
 
@@ -170,23 +181,26 @@
                         break;
         }
 
- r2 = r;
- r2.min.x = inputw;
+ r2 = rd;
+ r2.min.x = promptw + inputw;
         if(matchstart != matchfirst)
                 drawstring(ibuf, font, r2, West, "<", cnorm.fg);
         if(matchend->next != matchfirst)
                 drawstring(ibuf, font, r2, East, ">", cnorm.fg);
- r2 = r;
- r2.max.x = inputw;
+ r2 = rd;
+ r2.max.x = promptw + inputw;
         drawstring(ibuf, font, r2, West, input.string, cnorm.fg);
 
- r2.min.x = textwidth_l(font, input.string, input.pos - input.string) + pad/2 - 1;
+ r2.min.x = promptw + textwidth_l(font, input.string, input.pos - input.string) + pad/2 - 1;
         r2.max.x = r2.min.x + 2;
         r2.min.y++;
         r2.max.y--;
         border(ibuf, r2, 1, cnorm.border);
 
- border(ibuf, r, 1, cnorm.border);
+ if (prompt)
+ drawstring(ibuf, font, rp, West, prompt, cnorm.fg);
+
+ border(ibuf, rd, 1, cnorm.border);
         copyimage(barwin, r, ibuf, ZP);
 }
 
diff -r e93d2245fe20 -r 1b1343972f22 cmd/wmiir.c
--- a/cmd/wmiir.c Wed Mar 18 18:16:13 2009 -0400
+++ b/cmd/wmiir.c Sun Mar 29 23:01:07 2009 -0400
@@ -229,7 +229,7 @@
 
                 if(count == -1)
                         fprint(2, "%s: cannot read file '%s': %r\n", argv0, file);
- }while((file = ARGF()));
+ } while((file = ARGF()));
 
         return 0;
 }
Received on Mon Mar 30 2009 - 03:11:35 UTC

This archive was generated by hypermail 2.2.0 : Mon Mar 30 2009 - 03:12:05 UTC