input/search/url: pass pointer-to key-binding struct to execute()

This commit is contained in:
Daniel Eklöf 2022-02-08 19:43:00 +01:00
parent e5c5cd5478
commit fed90646d3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 28 additions and 25 deletions

34
input.c
View file

@ -81,9 +81,10 @@ pipe_closed:
static bool static bool
execute_binding(struct seat *seat, struct terminal *term, execute_binding(struct seat *seat, struct terminal *term,
enum bind_action_normal action, char *const *pipe_argv, const struct key_binding *binding, uint32_t serial)
uint32_t serial)
{ {
const enum bind_action_normal action = binding->action;
switch (action) { switch (action) {
case BIND_ACTION_NONE: case BIND_ACTION_NONE:
return true; return true;
@ -193,7 +194,7 @@ execute_binding(struct seat *seat, struct terminal *term,
/* FALLTHROUGH */ /* FALLTHROUGH */
case BIND_ACTION_PIPE_VIEW: case BIND_ACTION_PIPE_VIEW:
case BIND_ACTION_PIPE_SELECTED: { case BIND_ACTION_PIPE_SELECTED: {
if (pipe_argv == NULL) if (binding->aux->type != BINDING_AUX_PIPE)
return true; return true;
struct pipe_context *ctx = NULL; 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; goto pipe_err;
/* Close read end */ /* Close read end */
@ -1525,8 +1526,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
/* Match translated symbol */ /* Match translated symbol */
if (bind->k.sym == sym && if (bind->k.sym == sym &&
bind->mods == (bind_mods & ~bind_consumed) && bind->mods == (bind_mods & ~bind_consumed) &&
execute_binding( execute_binding(seat, term, bind, serial))
seat, term, bind->action, bind->aux->pipe.args, serial))
{ {
goto maybe_repeat; goto maybe_repeat;
} }
@ -1536,8 +1536,8 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
/* Match untranslated symbols */ /* Match untranslated symbols */
for (size_t i = 0; i < raw_count; i++) { for (size_t i = 0; i < raw_count; i++) {
if (bind->k.sym == raw_syms[i] && execute_binding( if (bind->k.sym == raw_syms[i] &&
seat, term, bind->action, bind->aux->pipe.args, serial)) execute_binding(seat, term, bind, serial))
{ {
goto maybe_repeat; goto maybe_repeat;
} }
@ -1545,8 +1545,8 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
/* Match raw key code */ /* Match raw key code */
tll_foreach(bind->k.key_codes, code) { tll_foreach(bind->k.key_codes, code) {
if (code->item == key && execute_binding( if (code->item == key &&
seat, term, bind->action, bind->aux->pipe.args, serial)) execute_binding(seat, term, bind, serial))
{ {
goto maybe_repeat; goto maybe_repeat;
} }
@ -2433,10 +2433,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
match = binding; match = binding;
} }
if (match != NULL) { if (match != NULL)
consumed = execute_binding( consumed = execute_binding(seat, term, match, serial);
seat, term, match->action, match->aux->pipe.args, serial);
}
} }
else { else {
@ -2469,9 +2467,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
} }
if (match != NULL) { if (match != NULL) {
consumed = execute_binding( struct key_binding bind = {
seat, term, match->action, match->aux.pipe.args, .action = match->action,
serial); .aux = &match->aux,
};
consumed = execute_binding(seat, term, &bind, serial);
} }
} }
} }

View file

@ -604,10 +604,11 @@ from_clipboard_done(void *user)
static bool static bool
execute_binding(struct seat *seat, struct terminal *term, 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) bool *update_search_result, bool *redraw)
{ {
*update_search_result = *redraw = false; *update_search_result = *redraw = false;
const enum bind_action_search action = binding->action;
switch (action) { switch (action) {
case BIND_ACTION_SEARCH_NONE: 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 && if (bind->k.sym == sym &&
bind->mods == (mods & ~consumed)) { bind->mods == (mods & ~consumed)) {
if (execute_binding(seat, term, bind->action, serial, if (execute_binding(seat, term, bind, serial,
&update_search_result, &redraw)) &update_search_result, &redraw))
{ {
goto update_search; goto update_search;
@ -855,7 +856,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
/* Match untranslated symbols */ /* Match untranslated symbols */
for (size_t i = 0; i < raw_count; i++) { for (size_t i = 0; i < raw_count; i++) {
if (bind->k.sym == raw_syms[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)) &update_search_result, &redraw))
{ {
goto update_search; goto update_search;
@ -867,7 +868,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
/* Match raw key code */ /* Match raw key code */
tll_foreach(bind->k.key_codes, code) { tll_foreach(bind->k.key_codes, code) {
if (code->item == key) { if (code->item == key) {
if (execute_binding(seat, term, bind->action, serial, if (execute_binding(seat, term, bind, serial,
&update_search_result, &redraw)) &update_search_result, &redraw))
{ {
goto update_search; goto update_search;

View file

@ -25,8 +25,10 @@ static void url_destroy(struct url *url);
static bool static bool
execute_binding(struct seat *seat, struct terminal *term, 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) { switch (action) {
case BIND_ACTION_URL_NONE: case BIND_ACTION_URL_NONE:
return false; return false;
@ -128,7 +130,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
if (bind->k.sym == sym && if (bind->k.sym == sym &&
bind->mods == (mods & ~consumed)) bind->mods == (mods & ~consumed))
{ {
execute_binding(seat, term, bind->action, serial); execute_binding(seat, term, bind, serial);
return; 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++) { for (size_t i = 0; i < raw_count; i++) {
if (bind->k.sym == raw_syms[i]) { if (bind->k.sym == raw_syms[i]) {
execute_binding(seat, term, bind->action, serial); execute_binding(seat, term, bind, serial);
return; return;
} }
} }
@ -145,7 +147,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
/* Match raw key code */ /* Match raw key code */
tll_foreach(bind->k.key_codes, code) { tll_foreach(bind->k.key_codes, code) {
if (code->item == key) { if (code->item == key) {
execute_binding(seat, term, bind->action, serial); execute_binding(seat, term, bind, serial);
return; return;
} }
} }