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.
This commit is contained in:
N-R-K 2022-01-03 15:24:26 +06:00 committed by GitHub
parent f7145db7f8
commit 1a18523772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

16
main.c
View file

@ -507,7 +507,7 @@ void handle_key_handler(bool init)
win_draw(&win); 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; pid_t pid;
FILE *pfs; 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); error(0, keyhandler.f.err, "%s", keyhandler.f.cmd);
keyhandler.warned = true; keyhandler.warned = true;
} }
return; return false;
} }
if (key == NULL) if (key == NULL)
return; return false;
if (pipe(pfd) < 0) { if (pipe(pfd) < 0) {
error(0, errno, "pipe"); error(0, errno, "pipe");
return; return false;
} }
if ((pfs = fdopen(pfd[1], "w")) == NULL) { if ((pfs = fdopen(pfd[1], "w")) == NULL) {
error(0, errno, "open pipe"); error(0, errno, "open pipe");
close(pfd[0]), close(pfd[1]); close(pfd[0]), close(pfd[1]);
return; return false;
} }
oldst = emalloc(fcnt * sizeof(*oldst)); oldst = emalloc(fcnt * sizeof(*oldst));
@ -602,7 +602,7 @@ end:
} }
free(oldst); free(oldst);
reset_cursor(); reset_cursor();
redraw(); return true;
} }
static bool process_bindings(const keymap_t *keys, unsigned int len, KeySym ksym_or_button, 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) { if (extprefix && ksym == KEYHANDLER_ABORT && MODMASK(kev->state) == 0) {
handle_key_handler(false); handle_key_handler(false);
} else if (extprefix) { } else if (extprefix) {
run_key_handler(XKeysymToString(ksym), kev->state & ~sh); if ((dirty = run_key_handler(XKeysymToString(ksym), kev->state & ~sh)))
extprefix = false; extprefix = false;
else
handle_key_handler(false);
} else if (key >= '0' && key <= '9') { } else if (key >= '0' && key <= '9') {
/* number prefix for commands */ /* number prefix for commands */
prefix = prefix * 10 + (int) (key - '0'); prefix = prefix * 10 + (int) (key - '0');