forked from RepoMirrors/bemenu
menu: make SHIFT_RETURN handling more elegant
Don't handle this on client side. Instead have a filter item and return it if filter text is requested.
This commit is contained in:
parent
4534cc8c73
commit
bc584cc5f0
@ -315,9 +315,6 @@ run_menu(const struct client *client, struct bm_menu *menu, void (*item_cb)(stru
|
||||
const char *text = bm_item_get_text(items[i]);
|
||||
item_cb(items[i], text);
|
||||
}
|
||||
|
||||
if (!count && bm_menu_get_filter(menu))
|
||||
item_cb(NULL, bm_menu_get_filter(menu));
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -249,6 +249,11 @@ struct bm_menu {
|
||||
*/
|
||||
char *old_filter;
|
||||
|
||||
/**
|
||||
* Used when selecting the filter text (ex. SHIFT_RETURN)
|
||||
*/
|
||||
struct bm_item *filter_item;
|
||||
|
||||
/**
|
||||
* Size of filter buffer
|
||||
*/
|
||||
|
11
lib/menu.c
11
lib/menu.c
@ -97,6 +97,9 @@ bm_menu_new(const char *renderer)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(menu->filter_item = bm_item_new(NULL)))
|
||||
goto fail;
|
||||
|
||||
return menu;
|
||||
|
||||
fail:
|
||||
@ -131,6 +134,9 @@ bm_menu_free_items(struct bm_menu *menu)
|
||||
list_free_list(&menu->selection);
|
||||
list_free_list(&menu->filtered);
|
||||
list_free_items(&menu->items, (list_free_fun)bm_item_free);
|
||||
|
||||
if (menu->filter_item)
|
||||
free(menu->filter_item);
|
||||
}
|
||||
|
||||
void
|
||||
@ -767,6 +773,11 @@ bm_menu_run_with_key(struct bm_menu *menu, enum bm_key key, uint32_t unicode)
|
||||
break;
|
||||
|
||||
case BM_KEY_SHIFT_RETURN:
|
||||
list_free_list(&menu->selection);
|
||||
bm_item_set_text(menu->filter_item, menu->filter);
|
||||
list_add_item(&menu->selection, menu->filter_item);
|
||||
break;
|
||||
|
||||
case BM_KEY_ESCAPE:
|
||||
list_free_list(&menu->selection);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user