Cloudef / bemenu

Dynamic menu library and client program inspired by dmenu
GNU General Public License v3.0
1.15k stars 90 forks source link

Nothing happens when pressing 'Return' on an item in vim normal mode, on Wayland backend #409

Open sij1nk opened 1 week ago

sij1nk commented 1 week ago

bemenu version: v0.6.20 (also happens on current master, 5bc8a6c)

On the Wayland backend, when I enter vim normal mode, highlight an item, and press 'Return', nothing happens. The 'Return' key in vim insert mode works as expected.

# all other BEMENU_* environment variables are left blank
export BEMENU_BACKEND wayland
echo -e "1\n2\n3" | bemenu --binding vim

However if I use the x11 backend, the 'Return' key also works in vim normal node - the highlighted item is printed to stdout and bemenu exits. I assume this is the intended behavior.

# all other BEMENU_* environment variables are left blank
export BEMENU_BACKEND x11
echo -e "1\n2\n3" | bemenu --binding vim

Can reproduce on sway version 1.9 (default configs), and on a heavily configured Hyprland 0.38, which I daily drive.

sij1nk commented 1 week ago

I looked into this a bit, and logged the key (bm_key), unicode, and code (bm_vim_code) values directly after the bm_vim_key_press call (https://github.com/Cloudef/bemenu/blob/master/lib/menu.c#L1039) for a 'Return' keytap (vim normal node on a highlighted item):

wayland: (default case -> key is consumed -> nothing happens)

bm_key: BM_KEY_RETURN
unicode: 13 (carriage return)
bm_vim_code: BM_VIM_CONSUME

x11: (unicode 0 is immediately ignored -> default action for 'Return' is used)

bm_key: BM_KEY_RETURN
unicode: 0
vim code: BM_VIM_IGNORE

curses: (default case -> key is consumed -> nothing happens)

bm_key: BM_KEY_RETURN
unicode: 10 (line feed)
vim code: BM_VIM_CONSUME

The x11 keysym to unicode mapping in https://github.com/Cloudef/bemenu/blob/master/lib/renderers/x11/xkb_unicode.c confuses me a bit - not sure why the GLFW folks decided not to map XK_Return to anything

The actual bm_key value is consistent across all 3 platforms, but the unicode isn't, so it'd make sense to me to base such logic on bm_key instead. However the 'Return' key isn't explicitly handled in bm_vim_key_press so I'm not sure what the intended behavior really is

sij1nk commented 1 week ago

I hacked around this by doing https://github.com/sij1nk/bemenu/commit/6dc4af0f8faf5d3c6b76ceb827abbf9c7ea7470e