forked from RepoMirrors/bemenu
61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
#include "internal.h"
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
/**
|
|
* Filter that mimics the vanilla dmenu filtering.
|
|
*
|
|
* @param menu bmMenu instance to filter.
|
|
* @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, unsigned int *outNmemb, unsigned int *outHighlighted)
|
|
{
|
|
assert(menu);
|
|
assert(outNmemb);
|
|
assert(outHighlighted);
|
|
*outNmemb = *outHighlighted = 0;
|
|
|
|
/* FIXME: not real dmenu like filtering at all */
|
|
|
|
bmItem **filtered = calloc(menu->items.count, sizeof(bmItem*));
|
|
if (!filtered)
|
|
return NULL;
|
|
|
|
unsigned int i, f;
|
|
for (f = i = 0; i < menu->items.count; ++i) {
|
|
bmItem *item = menu->items.list[i];
|
|
if (item->text && strstr(item->text, menu->filter)) {
|
|
if (f == 0 || item == bmMenuGetHighlightedItem(menu))
|
|
*outHighlighted = f;
|
|
filtered[f++] = item;
|
|
}
|
|
}
|
|
|
|
return _bmShrinkItemList(&filtered, menu->items.count, (*outNmemb = f));
|
|
}
|
|
|
|
/**
|
|
* Filter that mimics the vanilla case-insensitive dmenu filtering.
|
|
*
|
|
* @param menu bmMenu instance to filter.
|
|
* @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, unsigned int *outNmemb, unsigned int *outHighlighted)
|
|
{
|
|
assert(menu);
|
|
assert(outNmemb);
|
|
assert(outHighlighted);
|
|
*outNmemb = *outHighlighted = 0;
|
|
|
|
/* FIXME: stub */
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/* vim: set ts=8 sw=4 tw=0 :*/
|