From fed90646d3b8fdd99d2811ecc1c9745b86fa051a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 8 Feb 2022 19:43:00 +0100 Subject: [PATCH] input/search/url: pass pointer-to key-binding struct to execute() --- input.c | 34 +++++++++++++++++----------------- search.c | 9 +++++---- url-mode.c | 10 ++++++---- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/input.c b/input.c index 25778683..5a2489de 100644 --- a/input.c +++ b/input.c @@ -81,9 +81,10 @@ pipe_closed: static bool execute_binding(struct seat *seat, struct terminal *term, - enum bind_action_normal action, char *const *pipe_argv, - uint32_t serial) + const struct key_binding *binding, uint32_t serial) { + const enum bind_action_normal action = binding->action; + switch (action) { case BIND_ACTION_NONE: return true; @@ -193,7 +194,7 @@ execute_binding(struct seat *seat, struct terminal *term, /* FALLTHROUGH */ case BIND_ACTION_PIPE_VIEW: case BIND_ACTION_PIPE_SELECTED: { - if (pipe_argv == NULL) + if (binding->aux->type != BINDING_AUX_PIPE) return true; struct pipe_context *ctx = NULL; @@ -266,7 +267,7 @@ execute_binding(struct seat *seat, struct terminal *term, } } - if (!spawn(term->reaper, NULL, pipe_argv, pipe_fd[0], stdout_fd, stderr_fd)) + if (!spawn(term->reaper, NULL, binding->aux->pipe.args, pipe_fd[0], stdout_fd, stderr_fd)) goto pipe_err; /* Close read end */ @@ -1525,8 +1526,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, /* Match translated symbol */ if (bind->k.sym == sym && bind->mods == (bind_mods & ~bind_consumed) && - execute_binding( - seat, term, bind->action, bind->aux->pipe.args, serial)) + execute_binding(seat, term, bind, serial)) { goto maybe_repeat; } @@ -1536,8 +1536,8 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, /* Match untranslated symbols */ for (size_t i = 0; i < raw_count; i++) { - if (bind->k.sym == raw_syms[i] && execute_binding( - seat, term, bind->action, bind->aux->pipe.args, serial)) + if (bind->k.sym == raw_syms[i] && + execute_binding(seat, term, bind, serial)) { goto maybe_repeat; } @@ -1545,8 +1545,8 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, /* Match raw key code */ tll_foreach(bind->k.key_codes, code) { - if (code->item == key && execute_binding( - seat, term, bind->action, bind->aux->pipe.args, serial)) + if (code->item == key && + execute_binding(seat, term, bind, serial)) { goto maybe_repeat; } @@ -2433,10 +2433,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, match = binding; } - if (match != NULL) { - consumed = execute_binding( - seat, term, match->action, match->aux->pipe.args, serial); - } + if (match != NULL) + consumed = execute_binding(seat, term, match, serial); } else { @@ -2469,9 +2467,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } if (match != NULL) { - consumed = execute_binding( - seat, term, match->action, match->aux.pipe.args, - serial); + struct key_binding bind = { + .action = match->action, + .aux = &match->aux, + }; + consumed = execute_binding(seat, term, &bind, serial); } } } diff --git a/search.c b/search.c index 3d3d6265..6251c697 100644 --- a/search.c +++ b/search.c @@ -604,10 +604,11 @@ from_clipboard_done(void *user) static bool execute_binding(struct seat *seat, struct terminal *term, - enum bind_action_search action, uint32_t serial, + const struct key_binding *binding, uint32_t serial, bool *update_search_result, bool *redraw) { *update_search_result = *redraw = false; + const enum bind_action_search action = binding->action; switch (action) { case BIND_ACTION_SEARCH_NONE: @@ -841,7 +842,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key, if (bind->k.sym == sym && bind->mods == (mods & ~consumed)) { - if (execute_binding(seat, term, bind->action, serial, + if (execute_binding(seat, term, bind, serial, &update_search_result, &redraw)) { goto update_search; @@ -855,7 +856,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key, /* Match untranslated symbols */ for (size_t i = 0; i < raw_count; i++) { if (bind->k.sym == raw_syms[i]) { - if (execute_binding(seat, term, bind->action, serial, + if (execute_binding(seat, term, bind, serial, &update_search_result, &redraw)) { goto update_search; @@ -867,7 +868,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key, /* Match raw key code */ tll_foreach(bind->k.key_codes, code) { if (code->item == key) { - if (execute_binding(seat, term, bind->action, serial, + if (execute_binding(seat, term, bind, serial, &update_search_result, &redraw)) { goto update_search; diff --git a/url-mode.c b/url-mode.c index 22cb3359..350bdf25 100644 --- a/url-mode.c +++ b/url-mode.c @@ -25,8 +25,10 @@ static void url_destroy(struct url *url); static bool execute_binding(struct seat *seat, struct terminal *term, - enum bind_action_url action, uint32_t serial) + const struct key_binding *binding, uint32_t serial) { + const enum bind_action_url action = binding->action; + switch (action) { case BIND_ACTION_URL_NONE: return false; @@ -128,7 +130,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, if (bind->k.sym == sym && bind->mods == (mods & ~consumed)) { - execute_binding(seat, term, bind->action, serial); + execute_binding(seat, term, bind, serial); return; } @@ -137,7 +139,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, for (size_t i = 0; i < raw_count; i++) { if (bind->k.sym == raw_syms[i]) { - execute_binding(seat, term, bind->action, serial); + execute_binding(seat, term, bind, serial); return; } } @@ -145,7 +147,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, /* Match raw key code */ tll_foreach(bind->k.key_codes, code) { if (code->item == key) { - execute_binding(seat, term, bind->action, serial); + execute_binding(seat, term, bind, serial); return; } }