wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 9e4195e708b4da450ced9ed4c9b11d270d5a79fe
parent cd233229cfa183c1da4ecd37eeefb9f73bc8bb12
Author: Kris Maglione <jg@suckless.org>
Date:   Tue, 14 Oct 2008 00:02:30 -0400

[menu] General improvements

Diffstat:
cmd/menu/main.c | 2+-
cmd/menu/menu.c | 61+++++++++++++++++++++++++++++++++++++++++++++----------------
config.mk | 2+-
3 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/cmd/menu/main.c b/cmd/menu/main.c @@ -67,7 +67,7 @@ readctl(char *key) { 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 --git a/cmd/menu/menu.c b/cmd/menu/menu.c @@ -69,17 +69,6 @@ menu_cmd(int op) { 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 @@ menu_cmd(int op) { /* 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 @@ menu_cmd(int op) { 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,19 +146,40 @@ menu_draw(void) { 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; itemoff = itemoff + i->width + pad; diff --git a/config.mk b/config.mk @@ -14,7 +14,7 @@ LIBS = -L/usr/lib -L$(ROOT)/lib # Flags include $(ROOT)/mk/gcc.mk -CFLAGS += $(DEBUGCFLAGS) -O0 +CFLAGS += $(DEBUGCFLAGS) -O1 LDFLAGS += -g $(LIBS) SOLDFLAGS += $(LDFLAGS) SHARED = -shared -Wl,-soname=$(SONAME)