From 9e9b671fa3863aecabdee4a9befdef91ef29f6f3 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 12 Apr 2014 14:36:12 +0300 Subject: [PATCH] Remove highlight logic from filters, it does not belong there. Plus it seems dmenu always just highlights first item on filter change. --- lib/filter.c | 21 ++++++--------------- lib/internal.h | 4 ++-- lib/menu.c | 8 ++++---- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/filter.c b/lib/filter.c index 4674b5d..836ad83 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -79,17 +79,15 @@ fail: * @param addition This will be 1, if filter is same as previous filter with something appended. * @param fstrstr Substring function used to match items. * @param outNmemb unsigned int reference to filtered items outNmemb. - * @param outHighlighted unsigned int reference to new outHighlighted item index. * @return Pointer to array of bmItem pointers. */ -bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), unsigned int *outNmemb, unsigned int *outHighlighted) +bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), unsigned int *outNmemb) { assert(menu); assert(fstrstr); assert(fstrncmp); assert(outNmemb); - assert(outHighlighted); - *outNmemb = *outHighlighted = 0; + *outNmemb = 0; unsigned int itemsCount; bmItem **items; @@ -110,8 +108,6 @@ bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const c if (!(buffer = _bmFilterTokenize(menu, &tokv, &tokc))) goto fail; - bmItem *highlighted = bmMenuGetHighlightedItem(menu); - size_t len = (tokc ? strlen(tokv[0]) : 0); unsigned int i, f, e; for (e = f = i = 0; i < itemsCount; ++i) { @@ -126,9 +122,6 @@ bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const c continue; } - if (item == highlighted) - *outHighlighted = f; - if (tokc && item->text && !fstrncmp(tokv[0], item->text, len + 1)) { /* exact matches */ memmove(&filtered[1], filtered, f * sizeof(bmItem*)); filtered[0] = item; @@ -164,12 +157,11 @@ fail: * @param menu bmMenu instance to filter. * @param addition This will be 1, if filter is same as previous filter with something appended. * @param outNmemb unsigned int reference to filtered items outNmemb. - * @param outHighlighted unsigned int reference to new outHighlighted item index. * @return Pointer to array of bmItem pointers. */ -bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted) +bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb) { - return _bmFilterDmenuFun(menu, addition, strstr, strncmp, outNmemb, outHighlighted); + return _bmFilterDmenuFun(menu, addition, strstr, strncmp, outNmemb); } /** @@ -178,12 +170,11 @@ bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, uns * @param menu bmMenu instance to filter. * @param addition This will be 1, if filter is same as previous filter with something appended. * @param outNmemb unsigned int reference to filtered items outNmemb. - * @param outHighlighted unsigned int reference to new outHighlighted item index. * @return Pointer to array of bmItem pointers. */ -bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted) +bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb) { - return _bmFilterDmenuFun(menu, addition, _bmStrupstr, _bmStrnupcmp, outNmemb, outHighlighted); + return _bmFilterDmenuFun(menu, addition, _bmStrupstr, _bmStrnupcmp, outNmemb); } /* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/internal.h b/lib/internal.h index c33c441..2acd6f5 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -141,8 +141,8 @@ int _bmDrawCursesInit(struct _bmRenderApi *api); int _bmMenuItemIsSelected(const bmMenu *menu, const bmItem *item); /* filter.c */ -bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted); -bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted); +bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb); +bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb); /* list.c */ void _bmItemListFreeList(struct _bmItemList *list); diff --git a/lib/menu.c b/lib/menu.c index edbcf73..0457da8 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -7,7 +7,7 @@ /** * Filter function map. */ -static bmItem** (*filterFunc[BM_FILTER_MODE_LAST])(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted) = { +static bmItem** (*filterFunc[BM_FILTER_MODE_LAST])(bmMenu *menu, char addition, unsigned int *outNmemb) = { _bmFilterDmenu, /* BM_FILTER_DMENU */ _bmFilterDmenuCaseInsensitive /* BM_FILTER_DMENU_CASE_INSENSITIVE */ }; @@ -482,11 +482,11 @@ void bmMenuFilter(bmMenu *menu) if (menu->oldFilter && !strcmp(menu->filter, menu->oldFilter)) return; - unsigned int count, selected; - bmItem **filtered = filterFunc[menu->filterMode](menu, addition, &count, &selected); + unsigned int count; + bmItem **filtered = filterFunc[menu->filterMode](menu, addition, &count); _bmItemListSetItemsNoCopy(&menu->filtered, filtered, count); - menu->index = selected; + menu->index = 0; if (menu->oldFilter) free(menu->oldFilter);