From 1a185237723229720260a04cb61fcffa96dab4d9 Mon Sep 17 00:00:00 2001 From: N-R-K <79544946+N-R-K@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:24:26 +0600 Subject: [PATCH] fix: reset statusbar after failed keyhandler (#191) currently if the keyhandler invocation fails, for example due to it not being present, the statusbar does not reset and stays on "getting keyhandler input" message. now the return value from run_key_handler() is used to determine if the function was successful or not. and if the function failed, we call handle_key_handler() with false which resets the statusbar. we also no longer call redraw() within run_key_handler() and instead assign it's return value to dirty which does a redraw if true. --- main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 0bd923e..34c0254 100644 --- a/main.c +++ b/main.c @@ -507,7 +507,7 @@ void handle_key_handler(bool init) win_draw(&win); } -static void run_key_handler(const char *key, unsigned int mask) +static bool run_key_handler(const char *key, unsigned int mask) { pid_t pid; FILE *pfs; @@ -524,19 +524,19 @@ static void run_key_handler(const char *key, unsigned int mask) error(0, keyhandler.f.err, "%s", keyhandler.f.cmd); keyhandler.warned = true; } - return; + return false; } if (key == NULL) - return; + return false; if (pipe(pfd) < 0) { error(0, errno, "pipe"); - return; + return false; } if ((pfs = fdopen(pfd[1], "w")) == NULL) { error(0, errno, "open pipe"); close(pfd[0]), close(pfd[1]); - return; + return false; } oldst = emalloc(fcnt * sizeof(*oldst)); @@ -602,7 +602,7 @@ end: } free(oldst); reset_cursor(); - redraw(); + return true; } static bool process_bindings(const keymap_t *keys, unsigned int len, KeySym ksym_or_button, @@ -645,8 +645,10 @@ static void on_keypress(XKeyEvent *kev) if (extprefix && ksym == KEYHANDLER_ABORT && MODMASK(kev->state) == 0) { handle_key_handler(false); } else if (extprefix) { - run_key_handler(XKeysymToString(ksym), kev->state & ~sh); - extprefix = false; + if ((dirty = run_key_handler(XKeysymToString(ksym), kev->state & ~sh))) + extprefix = false; + else + handle_key_handler(false); } else if (key >= '0' && key <= '9') { /* number prefix for commands */ prefix = prefix * 10 + (int) (key - '0');