forked from RepoMirrors/bemenu
Replace --vim option with a generic --binding [name] option
This commit is contained in:
parent
dc24d795bb
commit
17481427a0
@ -181,7 +181,7 @@ usage(FILE *out, const char *name)
|
||||
" -C, --no-cursor ignore cursor events.\n"
|
||||
" -T, --no-touch ignore touch events.\n"
|
||||
" -K, --no-keyboard ignore keyboard events.\n"
|
||||
" --vim use vim bindings.\n"
|
||||
" --binding use alternative key bindings. Available options: vim\n"
|
||||
" --scrollbar display scrollbar. (none (default), always, autohide)\n"
|
||||
" --accept-single immediately return if there is only one item.\n"
|
||||
" --ifne only display menu if there are items.\n"
|
||||
@ -309,7 +309,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
||||
{ "scb", required_argument, 0, 0x114 },
|
||||
{ "scf", required_argument, 0, 0x115 },
|
||||
{ "bdr", required_argument, 0, 0x121 },
|
||||
{ "vim", no_argument, 0, 0x128 },
|
||||
{ "binding", required_argument, 0, 0x128 },
|
||||
|
||||
{ "disco", no_argument, 0, 0x116 },
|
||||
{ 0, 0, 0, 0 }
|
||||
@ -482,7 +482,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
||||
client->colors[BM_COLOR_BORDER] = optarg;
|
||||
break;
|
||||
case 0x128:
|
||||
client->use_vim_bindings = true;
|
||||
client->key_binding = optarg;
|
||||
break;
|
||||
|
||||
case 0x116:
|
||||
@ -539,7 +539,7 @@ menu_with_options(struct client *client)
|
||||
bm_menu_set_password(menu, client->password);
|
||||
bm_menu_set_width(menu, client->hmargin_size, client->width_factor);
|
||||
bm_menu_set_border_size(menu, client->border_size);
|
||||
bm_menu_set_use_vim_bindings(menu, client->use_vim_bindings);
|
||||
bm_menu_set_key_binding(menu, client->key_binding);
|
||||
|
||||
if (client->center) {
|
||||
bm_menu_set_align(menu, BM_ALIGN_CENTER);
|
||||
|
@ -36,7 +36,7 @@ struct client {
|
||||
bool force_fork, fork;
|
||||
bool no_exec;
|
||||
bool password;
|
||||
bool use_vim_bindings;
|
||||
char *key_binding;
|
||||
char *monitor_name;
|
||||
};
|
||||
|
||||
|
@ -789,10 +789,13 @@ BM_PUBLIC bool bm_menu_get_password(struct bm_menu *menu);
|
||||
|
||||
|
||||
/**
|
||||
* Should the menu use vim bindings?
|
||||
* @param menu bm_menu instance to enable/disable vim bindings
|
||||
* Specify the key bindings that should be used.
|
||||
* If an invalid key_binding is provided it will fall back to the default one.
|
||||
*
|
||||
* @param menu bm_menu instance to set the key binding on.
|
||||
* @param key_binding binding name that should be used. (available: vim)
|
||||
*/
|
||||
BM_PUBLIC void bm_menu_set_use_vim_bindings(struct bm_menu *menu, bool use_vim_bindings);
|
||||
BM_PUBLIC void bm_menu_set_key_binding(struct bm_menu *menu, char *key_binding);
|
||||
|
||||
|
||||
/** @} Properties */
|
||||
|
@ -412,7 +412,15 @@ struct bm_menu {
|
||||
*/
|
||||
bool dirty;
|
||||
|
||||
bool use_vim_bindings;
|
||||
/**
|
||||
* Key binding that should be used.
|
||||
* If empty or invalid the default bindings will be used. (available: vim)
|
||||
*/
|
||||
char *key_binding;
|
||||
|
||||
/**
|
||||
* Vim binding specific variables.
|
||||
*/
|
||||
char vim_mode;
|
||||
uint32_t vim_last_key;
|
||||
};
|
||||
|
28
lib/menu.c
28
lib/menu.c
@ -55,7 +55,7 @@ bm_menu_new(const char *renderer)
|
||||
|
||||
menu->dirty = true;
|
||||
|
||||
menu->use_vim_bindings = false;
|
||||
menu->key_binding = NULL;
|
||||
menu->vim_mode = 'i';
|
||||
menu->vim_last_key = 0;
|
||||
|
||||
@ -690,8 +690,8 @@ bm_menu_set_selected_items(struct bm_menu *menu, struct bm_item **items, uint32_
|
||||
}
|
||||
|
||||
void
|
||||
bm_menu_set_use_vim_bindings(struct bm_menu *menu, bool use_vim_bindings){
|
||||
menu->use_vim_bindings = use_vim_bindings;
|
||||
bm_menu_set_key_binding(struct bm_menu *menu, char *key_binding){
|
||||
menu->key_binding = key_binding;
|
||||
}
|
||||
|
||||
struct bm_item**
|
||||
@ -950,17 +950,19 @@ bm_menu_run_with_key(struct bm_menu *menu, enum bm_key key, uint32_t unicode)
|
||||
if (key != BM_KEY_NONE)
|
||||
menu->dirty = true;
|
||||
|
||||
if(menu->use_vim_bindings){
|
||||
enum bm_vim_code code = bm_vim_key_press(menu, key, unicode, count, displayed);
|
||||
if(menu->key_binding != NULL){
|
||||
if(strcmp(menu->key_binding, "vim") == 0){
|
||||
enum bm_vim_code code = bm_vim_key_press(menu, key, unicode, count, displayed);
|
||||
|
||||
switch(code){
|
||||
case BM_VIM_CONSUME:
|
||||
return BM_RUN_RESULT_RUNNING;
|
||||
case BM_VIM_EXIT:
|
||||
list_free_list(&menu->selection);
|
||||
return BM_RUN_RESULT_CANCEL;
|
||||
case BM_VIM_IGNORE:
|
||||
break;
|
||||
switch(code){
|
||||
case BM_VIM_CONSUME:
|
||||
return BM_RUN_RESULT_RUNNING;
|
||||
case BM_VIM_EXIT:
|
||||
list_free_list(&menu->selection);
|
||||
return BM_RUN_RESULT_CANCEL;
|
||||
case BM_VIM_IGNORE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user