[hackers] [wmii] [menu] General improvements || Kris Maglione

From: <hg_AT_suckless.org>
Date: Tue, 14 Oct 2008 04:17:06 +0000 (UTC)

changeset: 2360:fd1f153409b1
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Oct 14 00:02:30 2008 -0400
files: cmd/menu/main.c cmd/menu/menu.c config.mk
description:
[menu] General improvements

diff -r d64b122c5afe -r fd1f153409b1 cmd/menu/main.c
--- a/cmd/menu/main.c Mon Oct 13 23:39:20 2008 -0400
+++ b/cmd/menu/main.c Tue Oct 14 00:02:30 2008 -0400
@@ -67,7 +67,7 @@
                         p += nkey;
                         s = strchr(p, '\n');
                         n = (s ? s : ectl) - p;
- s = emalloc(n + 1);
+ s = freelater(emalloc(n + 1));
                         s[n] = '\0';
                         return strncpy(s, p, n);
                 }
diff -r d64b122c5afe -r fd1f153409b1 cmd/menu/menu.c
--- a/cmd/menu/menu.c Mon Oct 13 23:39:20 2008 -0400
+++ b/cmd/menu/menu.c Tue Oct 14 00:02:30 2008 -0400
@@ -69,17 +69,6 @@
 
         i = strlen(filter);
         switch(op) {
- case ACCEPT:
- srv.running = false;
- if(matchidx)
- print("%s", matchidx->retstring);
- else
- result = 1;
- break;
- case REJECT:
- srv.running = false;
- result = 1;
- break;
         case HIST_NEXT:
                 if(histidx->next) {
                         strncpy(filter, histtext(histidx->next), sizeof filter);
@@ -110,6 +99,23 @@
                 /* TODO: Add a caret. */
                 filter[0] = '\0';
                 break;
+ default:
+ goto next;
+ }
+ update_filter();
+next:
+ switch(op) {
+ case ACCEPT:
+ srv.running = false;
+ if(matchidx)
+ print("%s", matchidx->retstring);
+ else
+ result = 1;
+ break;
+ case REJECT:
+ srv.running = false;
+ result = 1;
+ break;
         case CMPL_NEXT:
                 matchidx = matchidx->next;
                 break;
@@ -117,19 +123,21 @@
                 matchidx = matchidx->prev;
                 break;
         case CMPL_FIRST:
- matchidx = matchfirst;
+ matchstart = matchfirst;
+ matchidx = nil;
+ matchend = nil;
                 break;
         case CMPL_LAST:
                 matchidx = matchfirst->prev;
                 break;
         case CMPL_NEXT_PAGE:
- matchstart = matchend->next;
+ matchidx = matchend->next;
                 break;
         case CMPL_PREV_PAGE:
                 matchend = matchstart->prev;
+ matchidx = nil;
                 break;
         }
- update_filter();
         menu_draw();
 }
 
@@ -138,18 +146,39 @@
         Rectangle r, r2;
         CTuple *c;
         Item *i;
- int inputw, itemoff, end, pad;
+ 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) + pad;
         itemoff = inputw + 2 * ltwidth;
         end = Dx(r) - ltwidth;
- pad = (font->height & ~1);
 
         fill(ibuf, r, cnorm.bg);
+
+ if(matchend && matchidx == matchend->next)
+ matchstart = matchidx;
+ else if(matchidx == matchstart->prev)
+ matchend = matchidx;
+
+ if(matchend == matchstart->prev && matchstart != matchidx) {
+ n = itemoff;
+ matchstart = matchend;
+ for(i=matchend; ; i=i->prev) {
+ n += i->width + pad;
+ if(n > end)
+ break;
+ matchstart = i;
+ if(i == matchfirst)
+ break;
+ }
+ }
+
+ if(matchidx == nil)
+ matchidx = matchstart;
 
         for(i=matchstart; i->string; i=i->next) {
                 r2.min.x = itemoff;
diff -r d64b122c5afe -r fd1f153409b1 config.mk
--- a/config.mk Mon Oct 13 23:39:20 2008 -0400
+++ b/config.mk Tue Oct 14 00:02:30 2008 -0400
@@ -14,7 +14,7 @@
 
 # Flags
 include $(ROOT)/mk/gcc.mk
-CFLAGS += $(DEBUGCFLAGS) -O0
+CFLAGS += $(DEBUGCFLAGS) -O1
 LDFLAGS += -g $(LIBS)
 SOLDFLAGS += $(LDFLAGS)
 SHARED = -shared -Wl,-soname=$(SONAME)
Received on Tue Oct 14 2008 - 04:17:06 UTC

This archive was generated by hypermail 2.2.0 : Tue Oct 14 2008 - 04:24:04 UTC