summaryrefslogtreecommitdiff
path: root/lib/filter.c
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2014-04-10 01:09:35 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2014-04-10 01:10:05 +0300
commit67be25fbe43274340de89049fec7098cdf998b47 (patch)
treef8d6be283944fc90e1c224c461f6e92b3ae78d6f /lib/filter.c
parenta3498b25f414a888aa01ffd1cf9b2e44f6c54764 (diff)
downloadbemenu-67be25fbe43274340de89049fec7098cdf998b47.tar.gz
bemenu-67be25fbe43274340de89049fec7098cdf998b47.tar.bz2
bemenu-67be25fbe43274340de89049fec7098cdf998b47.zip
Basic working bemenu with curses backend
Diffstat (limited to 'lib/filter.c')
-rw-r--r--lib/filter.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/filter.c b/lib/filter.c
new file mode 100644
index 0000000..b1cf668
--- /dev/null
+++ b/lib/filter.c
@@ -0,0 +1,64 @@
+/**
+ * @file filter.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 count unsigned int reference to filtered items count.
+ * @param selected unsigned int reference to new selected item index.
+ * @return Pointer to array of bmItem pointers.
+ */
+bmItem** _bmFilterDmenu(bmMenu *menu, unsigned int *count, unsigned int *selected)
+{
+ assert(menu != NULL);
+ assert(count != NULL);
+ assert(selected != NULL);
+ *count = *selected = 0;
+
+ /* FIXME: not real dmenu like filtering at all */
+
+ bmItem **filtered = calloc(menu->itemsCount, sizeof(bmItem*));
+ if (!filtered)
+ return NULL;
+
+ unsigned int i, f;
+ for (f = i = 0; i < menu->itemsCount; ++i) {
+ bmItem *item = menu->items[i];
+ if (item->text && strstr(item->text, menu->filter)) {
+ if (f == 0 || item == bmMenuGetSelectedItem(menu))
+ *selected = f;
+ filtered[f++] = item;
+ }
+ }
+
+ return _bmShrinkItemList(&filtered, menu->itemsCount, (*count = f));
+}
+
+/**
+ * Filter that mimics the vanilla case-insensitive dmenu filtering.
+ *
+ * @param menu bmMenu instance to filter.
+ * @param count unsigned int reference to filtered items count.
+ * @param selected unsigned int reference to new selected item index.
+ * @return Pointer to array of bmItem pointers.
+ */
+bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, unsigned int *count, unsigned int *selected)
+{
+ assert(menu != NULL);
+ assert(count != NULL);
+ assert(selected != NULL);
+ *count = *selected = 0;
+
+ /* FIXME: stub */
+
+ return NULL;
+}
+
+/* vim: set ts=8 sw=4 tw=0 :*/