Sort items in bemenu-run.

This commit is contained in:
Jari Vetoniemi 2014-10-25 20:57:30 +03:00
parent 9f13ca2e6d
commit 9ad69fb4b4

View File

@ -84,6 +84,13 @@ get_paths(const char *env, const char *default_paths, struct paths *state)
return strip_slash(path); return strip_slash(path);
} }
static int
compare(const void *a, const void *b)
{
const struct bm_item *ia = *(struct bm_item**)a, *ib = *(struct bm_item**)b;
return strcmp(bm_item_get_text(ia), bm_item_get_text(ib));
}
static void static void
read_items_to_menu_from_dir(struct bm_menu *menu, const char *path) read_items_to_menu_from_dir(struct bm_menu *menu, const char *path)
{ {
@ -98,7 +105,7 @@ read_items_to_menu_from_dir(struct bm_menu *menu, const char *path)
memset(&file, 0, sizeof(file)); memset(&file, 0, sizeof(file));
tinydir_readfile(&dir, &file); tinydir_readfile(&dir, &file);
if (!file.is_dir) { if (!file.is_dir && file.name) {
struct bm_item *item; struct bm_item *item;
if (!(item = bm_item_new(file.name))) if (!(item = bm_item_new(file.name)))
break; break;
@ -110,6 +117,10 @@ read_items_to_menu_from_dir(struct bm_menu *menu, const char *path)
} }
tinydir_close(&dir); tinydir_close(&dir);
uint32_t count;
struct bm_item **items = bm_menu_get_items(menu, &count);
qsort(items, count, sizeof(struct bm_item*), compare);
} }
static void static void