Krolyxon
Commit 1a18523

Branches

Refs →

nsxiv1a18523

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.
Author
N-R-K
Date
2022-01-03 15:24 +0600
Committer
GitHub · 2022-01-03 09:24 +0000
Parent
f7145db
Commit
1a185237723229720260a04cb61fcffa96dab4d9

+10 −8

1 file changed

  1. M main.c +10 −8
M main.c View
@@ -507,7 +507,7 @@ void handle_key_handler(bool init)
507507 win_draw(&win);
508508 }
509509
510−static void run_key_handler(const char *key, unsigned int mask)
510+static bool run_key_handler(const char *key, unsigned int mask)
511511 {
512512 pid_t pid;
513513 FILE *pfs;
@@ -524,19 +524,19 @@ static void run_key_handler(const char *key, unsigned int mask)
524524 error(0, keyhandler.f.err, "%s", keyhandler.f.cmd);
525525 keyhandler.warned = true;
526526 }
527− return;
527+ return false;
528528 }
529529 if (key == NULL)
530− return;
530+ return false;
531531
532532 if (pipe(pfd) < 0) {
533533 error(0, errno, "pipe");
534− return;
534+ return false;
535535 }
536536 if ((pfs = fdopen(pfd[1], "w")) == NULL) {
537537 error(0, errno, "open pipe");
538538 close(pfd[0]), close(pfd[1]);
539− return;
539+ return false;
540540 }
541541 oldst = emalloc(fcnt * sizeof(*oldst));
542542
@@ -602,7 +602,7 @@ end:
602602 }
603603 free(oldst);
604604 reset_cursor();
605− redraw();
605+ return true;
606606 }
607607
608608 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)
645645 if (extprefix && ksym == KEYHANDLER_ABORT && MODMASK(kev->state) == 0) {
646646 handle_key_handler(false);
647647 } else if (extprefix) {
648− run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
649− extprefix = false;
648+ if ((dirty = run_key_handler(XKeysymToString(ksym), kev->state & ~sh)))
649+ extprefix = false;
650+ else
651+ handle_key_handler(false);
650652 } else if (key >= '0' && key <= '9') {
651653 /* number prefix for commands */
652654 prefix = prefix * 10 + (int) (key - '0');