forked from RepoMirrors/bemenu
Pass bm_menu struct on each render api call.
This commit is contained in:
parent
30269b6385
commit
0abad19b3e
@ -37,12 +37,12 @@ struct render_api {
|
||||
/**
|
||||
* Create underlying renderer.
|
||||
*/
|
||||
bool (*constructor)(void);
|
||||
bool (*constructor)(struct bm_menu *menu);
|
||||
|
||||
/**
|
||||
* Release underlying renderer.
|
||||
*/
|
||||
void (*destructor)(void);
|
||||
void (*destructor)(struct bm_menu *menu);
|
||||
|
||||
/**
|
||||
* Get count of displayed items by the underlying renderer.
|
||||
@ -53,7 +53,7 @@ struct render_api {
|
||||
* If the underlying renderer is a UI toolkit. (curses, etc...)
|
||||
* There might be possibility to get user input, and this should be thus implemented.
|
||||
*/
|
||||
enum bm_key (*poll_key)(uint32_t *unicode);
|
||||
enum bm_key (*poll_key)(const struct bm_menu *menu, uint32_t *unicode);
|
||||
|
||||
/**
|
||||
* Tells underlying renderer to draw the menu.
|
||||
@ -182,7 +182,7 @@ struct bm_menu {
|
||||
};
|
||||
|
||||
/* library.c */
|
||||
bool bm_renderer_activate(struct bm_renderer *renderer);
|
||||
bool bm_renderer_activate(struct bm_renderer *renderer, struct bm_menu *menu);
|
||||
|
||||
/* menu.c */
|
||||
bool bm_menu_item_is_selected(const struct bm_menu *menu, const struct bm_item *item);
|
||||
|
@ -69,14 +69,14 @@ fail:
|
||||
}
|
||||
|
||||
bool
|
||||
bm_renderer_activate(struct bm_renderer *renderer)
|
||||
bm_renderer_activate(struct bm_renderer *renderer, struct bm_menu *menu)
|
||||
{
|
||||
assert(renderer);
|
||||
|
||||
if (!load(renderer->file, renderer))
|
||||
return false;
|
||||
|
||||
if (!renderer->api.constructor())
|
||||
if (!renderer->api.constructor(menu))
|
||||
goto fail;
|
||||
|
||||
return true;
|
||||
|
@ -39,7 +39,7 @@ bm_menu_new(const char *renderer)
|
||||
if (renderer && strcmp(renderer, renderers[i]->name))
|
||||
continue;
|
||||
|
||||
if (bm_renderer_activate((struct bm_renderer*)renderers[i])) {
|
||||
if (bm_renderer_activate((struct bm_renderer*)renderers[i], menu)) {
|
||||
status = true;
|
||||
menu->renderer = renderers[i];
|
||||
break;
|
||||
@ -60,7 +60,7 @@ bm_menu_free(struct bm_menu *menu)
|
||||
assert(menu);
|
||||
|
||||
if (menu->renderer && menu->renderer->api.destructor)
|
||||
menu->renderer->api.destructor();
|
||||
menu->renderer->api.destructor(menu);
|
||||
|
||||
free(menu->title);
|
||||
free(menu->filter);
|
||||
@ -356,7 +356,7 @@ bm_menu_poll_key(struct bm_menu *menu, uint32_t *out_unicode)
|
||||
enum bm_key key = BM_KEY_NONE;
|
||||
|
||||
if (menu->renderer->api.poll_key)
|
||||
key = menu->renderer->api.poll_key(out_unicode);
|
||||
key = menu->renderer->api.poll_key(menu, out_unicode);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -239,8 +239,9 @@ get_displayed_count(const struct bm_menu *menu)
|
||||
}
|
||||
|
||||
static enum bm_key
|
||||
poll_key(uint32_t *unicode)
|
||||
poll_key(const struct bm_menu *menu, uint32_t *unicode)
|
||||
{
|
||||
(void)menu;
|
||||
assert(unicode);
|
||||
*unicode = 0;
|
||||
|
||||
@ -341,8 +342,9 @@ poll_key(uint32_t *unicode)
|
||||
}
|
||||
|
||||
static void
|
||||
destructor(void)
|
||||
destructor(struct bm_menu *menu)
|
||||
{
|
||||
(void)menu;
|
||||
terminate();
|
||||
sigaction(SIGABRT, &curses.abrt_action, NULL);
|
||||
sigaction(SIGSEGV, &curses.segv_action, NULL);
|
||||
@ -351,8 +353,9 @@ destructor(void)
|
||||
}
|
||||
|
||||
static bool
|
||||
constructor(void)
|
||||
constructor(struct bm_menu *menu)
|
||||
{
|
||||
(void)menu;
|
||||
memset(&curses, 0, sizeof(curses));
|
||||
|
||||
struct sigaction action;
|
||||
|
Loading…
Reference in New Issue
Block a user