aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN-R-K <79544946+N-R-K@users.noreply.github.com>2022-01-03 15:24:26 +0600
committerGitHub <noreply@github.com>2022-01-03 09:24:26 +0000
commit1a185237723229720260a04cb61fcffa96dab4d9 (patch)
treead9372368d36e6adca24c1daf1a3b4cd3cfdeb0d
parentf7145db7f8a5d136a522e0045e5ff39b2279e04c (diff)
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.
-rw-r--r--main.c18
1 files 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');