Modifiers _were_ displayed in status bar before this commit. They just
were discarded since there are no keybindings like <C-a><C-b>. This can
be tested by commenting out line 243 which contains `state->nbuf = 0` in
frontends/visurf/keybindings.c and then pressing Ctrl+a.
This commit displays the partial modifiers. For example, when Ctrl is
pressed, it displays "<C-".
A bug in showing modifiers has also been fixed. Before this commit, when
Ctrl+Alt+a was pressed, <CA-a> would be shown. Now, <C-A-a> is shown.
bufsz has been increased to 10 for this reason.
Fixes: https://todo.sr.ht/~sircmpwn/visurf/56
---
frontends/visurf/window.c | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/frontends/visurf/window.c b/frontends/visurf/window.c
index 3680ed43c..ad2ce03ef 100644
--- a/frontends/visurf/window.c+++ b/frontends/visurf/window.c
@@ -107,24 +107,26 @@ draw_tabs(struct nsvi_window *win, struct pool_buffer *buf)
static char *
keybuf_to_str(struct nsvi_bindings *state)
{
- size_t bufsz = 8, bufidx = 0;+ size_t bufsz = 10, bufidx = 0; char *keys = calloc(sizeof(char), bufsz);
for (size_t i = 0; i < state->nbuf; i++) {
size_t inc = 0;
if (state->buffer[i].mask != 0) {
- char buf[6] = { 0 };+ char buf[8] = { 0 }; size_t idx = 0;
buf[idx++] = '<';
if (state->buffer[i].mask & MOD_CTRL) {
buf[idx++] = 'C';
+ buf[idx++] = '-'; }
if (state->buffer[i].mask & MOD_ALT) {
buf[idx++] = 'A';
+ buf[idx++] = '-'; }
if (state->buffer[i].mask & MOD_LOGO) {
buf[idx++] = 'L';
+ buf[idx++] = '-'; }
- buf[idx++] = '-'; buf[idx++] = '\0';
int ret = snprintf(&keys[bufidx + inc], bufsz - bufidx,
"%s", buf);
@@ -160,6 +162,33 @@ expand:
i--;
keys[bufidx] = '\0';
}
++ /* Add currently pressed modifiers. For example, if Ctrl is pressed,+ * <C- will be added to keys. */+ uint32_t mask = 0;+ /* TODO: Find out why state->xkb_state is NULL, when this function is+ * first called. It is set by wl_keyboard_keymap, so probably related+ * to that. */+ if (state->xkb_state &&+ (mask = xkb_state_mask(state->xkb_state)) != 0) {+ bufsz *= 2;+ keys = realloc(keys, bufsz);+ keys[bufidx++] = '<';+ if (mask & MOD_CTRL) {+ keys[bufidx++] = 'C';+ keys[bufidx++] = '-';+ }+ if (mask & MOD_ALT) {+ keys[bufidx++] = 'A';+ keys[bufidx++] = '-';+ }+ if (mask & MOD_LOGO) {+ keys[bufidx++] = 'L';+ keys[bufidx++] = '-';+ }+ keys[bufidx] = '\0';+ }+ return keys;
}
--
2.34.1