From 85c50099afa792a45671664275d3cd33bb8606e6 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 09:46:13 +0200 Subject: conf: add definitions for pipe-{scrollback,view} bindings --- input.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 79491f8f..2df8c73a 100644 --- a/input.c +++ b/input.c @@ -101,6 +101,11 @@ execute_binding(struct seat *seat, struct terminal *term, xdg_toplevel_set_fullscreen(term->window->xdg_toplevel, NULL); break; + case BIND_ACTION_PIPE_SCROLLBACK: + case BIND_ACTION_PIPE_VIEW: + LOG_ERR("unimplemented"); + break; + case BIND_ACTION_COUNT: assert(false); break; -- cgit v1.3 From f21ea97037bd11f2375fff5f82dc2d08d0d552b9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 13:26:13 +0200 Subject: input: parse_key_binding: free key-codes list if 'bindings' is NULL --- input.c | 3 ++- wayland.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 2df8c73a..af0619ac 100644 --- a/input.c +++ b/input.c @@ -197,7 +197,8 @@ input_parse_key_binding(struct xkb_keymap *keymap, const char *combos, }; tll_push_back(*bindings, binding); - } + } else + tll_free(key_codes); } free(copy); diff --git a/wayland.h b/wayland.h index c47d3c29..9da2c856 100644 --- a/wayland.h +++ b/wayland.h @@ -47,6 +47,7 @@ enum bind_action_normal { struct key_binding_normal { struct key_binding bind; enum bind_action_normal action; + const char *spawn; }; struct mouse_binding { -- cgit v1.3 From 062b0eb7ab69e7821ab79763bfdc3648fdbb5f40 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 13:34:32 +0200 Subject: input: wip: initial support for piping scrollback/view to external tools --- input.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- wayland.h | 2 +- 2 files changed, 133 insertions(+), 8 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index af0619ac..00382c4f 100644 --- a/input.c +++ b/input.c @@ -5,10 +5,12 @@ #include #include #include +#include #include #include #include #include +#include #include @@ -28,13 +30,54 @@ #include "render.h" #include "search.h" #include "selection.h" +#include "spawn.h" #include "terminal.h" +#include "tokenize.h" #include "util.h" #include "vt.h" +struct pipe_context { + char *text; + size_t idx; + size_t left; +}; + +static bool +fdm_write_pipe(struct fdm *fdm, int fd, int events, void *data) +{ + struct pipe_context *ctx = data; + + if (events & EPOLLHUP) + goto pipe_closed; + + assert(events & EPOLLOUT); + ssize_t written = write(fd, &ctx->text[ctx->idx], ctx->left); + + if (written < 0) { + LOG_WARN("failed to write to pipe: %s", strerror(errno)); + goto pipe_closed; + } + + assert(written <= ctx->left); + ctx->idx += written; + ctx->left -= written; + + if (ctx->left == 0) + goto pipe_closed; + + return true; + +pipe_closed: + free(ctx->text); + free(ctx); + fdm_del(fdm, fd); + return true; +} + static void execute_binding(struct seat *seat, struct terminal *term, - enum bind_action_normal action, uint32_t serial) + enum bind_action_normal action, const char *pipe_cmd, + uint32_t serial) { switch (action) { case BIND_ACTION_NONE: @@ -102,10 +145,89 @@ execute_binding(struct seat *seat, struct terminal *term, break; case BIND_ACTION_PIPE_SCROLLBACK: - case BIND_ACTION_PIPE_VIEW: - LOG_ERR("unimplemented"); + case BIND_ACTION_PIPE_VIEW: { + if (pipe_cmd == NULL) + break; + + struct pipe_context *ctx = NULL; + + char *cmd = strdup(pipe_cmd); + char **argv = NULL; + + if (!tokenize_cmdline(cmd, &argv)) + goto pipe_err; + + int pipe_fd[2] = {-1, -1}; + if (pipe(pipe_fd) < 0) { + LOG_ERRNO("failed to create pipe"); + goto pipe_err; + } + + char *text; + size_t len; + + bool success = action == BIND_ACTION_PIPE_SCROLLBACK + ? term_scrollback_to_text(term, &text, &len) + : term_view_to_text(term, &text, &len); + + if (!success) + goto pipe_err; + + /* Make write-end non-blocking; required by the FDM */ + { + int flags = fcntl(pipe_fd[1], F_GETFL); + if (flags < 0 || + fcntl(pipe_fd[1], F_SETFL, flags | O_NONBLOCK) < 0) + { + LOG_ERRNO("failed to make write-end of pipe non-blocking"); + goto pipe_err; + } + } + + /* Make sure write-end is closed on exec() */ + { + int flags = fcntl(pipe_fd[1], F_GETFD); + if (flags < 0 || + fcntl(pipe_fd[1], F_SETFD, flags | FD_CLOEXEC) < 0) + { + LOG_ERRNO("failed to set FD_CLOEXEC on writeend of pipe"); + goto pipe_err; + } + } + + if (!spawn(term->reaper, NULL, argv, pipe_fd[0], -1, -1)) + goto pipe_err; + + /* Not needed anymore */ + free(argv); argv = NULL; + free(cmd); cmd = NULL; + + /* Close read end */ + close(pipe_fd[0]); + + ctx = malloc(sizeof(*ctx)); + *ctx = (struct pipe_context){ + .text = text, + .left = len, + }; + + if (!fdm_add(term->fdm, pipe_fd[1], EPOLLOUT, &fdm_write_pipe, ctx)) + goto pipe_err; + break; + pipe_err: + if (pipe_fd[0] >= 0) + close(pipe_fd[0]); + if (pipe_fd[1] >= 0) + close(pipe_fd[1]); + free(text); + free(argv); + free(cmd); + free(ctx); + break; + } + case BIND_ACTION_COUNT: assert(false); break; @@ -284,7 +406,10 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, tll_foreach(bindings, it) { tll_push_back( seat->kbd.bindings.key, - ((struct key_binding_normal){.bind = it->item, .action = i})); + ((struct key_binding_normal){ + .bind = it->item, + .action = i, + .pipe_cmd = wayl->conf->bindings.spawn[i]})); } tll_free(bindings); @@ -602,14 +727,14 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, /* Match symbol */ if (it->item.bind.sym == sym) { - execute_binding(seat, term, it->item.action, serial); + execute_binding(seat, term, it->item.action, it->item.pipe_cmd, serial); goto maybe_repeat; } /* Match raw key code */ tll_foreach(it->item.bind.key_codes, code) { if (code->item == key) { - execute_binding(seat, term, it->item.action, serial); + execute_binding(seat, term, it->item.action, it->item.pipe_cmd, serial); goto maybe_repeat; } } @@ -1259,7 +1384,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, continue; } - execute_binding(seat, term, binding->action, serial); + execute_binding(seat, term, binding->action, NULL, serial); break; } } diff --git a/wayland.h b/wayland.h index 9da2c856..b11af0d3 100644 --- a/wayland.h +++ b/wayland.h @@ -47,7 +47,7 @@ enum bind_action_normal { struct key_binding_normal { struct key_binding bind; enum bind_action_normal action; - const char *spawn; + const char *pipe_cmd; }; struct mouse_binding { -- cgit v1.3 From 1541531765f517067dcb92b4870d64e1be9bd230 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 16:39:07 +0200 Subject: conf: bindings: allow several mappings for the same action If the bindings has different pipe command associated with them, treat them as different actions. --- config.c | 203 ++++++++++++++++++++++++++++++++++++++++++-------------------- config.h | 20 +++++-- input.c | 28 ++++----- wayland.h | 2 +- 4 files changed, 166 insertions(+), 87 deletions(-) (limited to 'input.c') diff --git a/config.c b/config.c index f5820e98..044266f1 100644 --- a/config.c +++ b/config.c @@ -485,21 +485,19 @@ parse_section_csd(const char *key, const char *value, struct config *conf, } static bool -verify_key_combo(const struct config *conf, const char *combo, const char *path, - unsigned lineno) +verify_key_combo(const struct config *conf, enum bind_action_normal action, + const char *combo, const char *path, unsigned lineno) { - for (enum bind_action_normal action = 0; action < BIND_ACTION_COUNT; action++) { - if (conf->bindings.key[action] == NULL) - continue; - - char *copy = strdup(conf->bindings.key[action]); + tll_foreach(conf->bindings.key, it) { + char *copy = strdup(it->item.key); for (char *save = NULL, *collision = strtok_r(copy, " ", &save); collision != NULL; collision = strtok_r(NULL, " ", &save)) { if (strcmp(combo, collision) == 0) { - LOG_ERR("%s:%d: %s already mapped to %s", path, lineno, combo, binding_action_map[action]); + LOG_ERR("%s:%d: %s already mapped to %s", path, lineno, combo, + binding_action_map[it->item.action]); free(copy); return false; } @@ -530,11 +528,11 @@ parse_section_key_bindings( const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) { - const char *spawn = strchr(key, ':'); - if (spawn != NULL) - spawn++; + const char *pipe_cmd = strchr(key, ':'); + if (pipe_cmd != NULL) + pipe_cmd++; - const size_t key_len = spawn != NULL ? spawn - key - 1: strlen(key); + const size_t key_len = pipe_cmd != NULL ? pipe_cmd - key - 1: strlen(key); for (enum bind_action_normal action = 0; action < BIND_ACTION_COUNT; @@ -547,19 +545,46 @@ parse_section_key_bindings( continue; if (strcasecmp(value, "none") == 0) { - free(conf->bindings.key[action]); - conf->bindings.key[action] = NULL; + tll_foreach(conf->bindings.key, it) { + if (it->item.action == action) { + free(it->item.key); + free(it->item.pipe_cmd); + tll_remove(conf->bindings.key, it); + } + } return true; } - if (!verify_key_combo(conf, value, path, lineno)) { + if (!verify_key_combo(conf, action, value, path, lineno)) { return false; } - free(conf->bindings.key[action]); - free(conf->bindings.spawn[action]); - conf->bindings.key[action] = strdup(value); - conf->bindings.spawn[action] = spawn != NULL ? strdup(spawn) : NULL; + bool already_added = false; + tll_foreach(conf->bindings.key, it) { + if (it->item.action == action && + ((it->item.pipe_cmd == NULL && pipe_cmd == NULL) || + (it->item.pipe_cmd != NULL && pipe_cmd != NULL && + strcmp(it->item.pipe_cmd, pipe_cmd) == 0))) + { + + free(it->item.key); + free(it->item.pipe_cmd); + + it->item.key = strdup(value); + it->item.pipe_cmd = pipe_cmd != NULL ? strdup(pipe_cmd) : NULL; + already_added = true; + break; + } + } + + if (!already_added) { + struct config_key_binding_normal binding = { + .action = action, + .key = strdup(value), + .pipe_cmd = pipe_cmd != NULL ? strdup(pipe_cmd) : NULL, + }; + tll_push_back(conf->bindings.key, binding); + } return true; } @@ -581,7 +606,12 @@ parse_section_mouse_bindings( continue; if (strcmp(value, "NONE") == 0) { - conf->bindings.mouse[action] = (struct mouse_binding){0, 0, BIND_ACTION_NONE}; + tll_foreach(conf->bindings.mouse, it) { + if (it->item.action == action) { + tll_remove(conf->bindings.mouse, it); + break; + } + } return true; } @@ -603,16 +633,32 @@ parse_section_mouse_bindings( const int count = 1; /* Make sure button isn't already mapped to another action */ - for (enum bind_action_normal j = 0; j < BIND_ACTION_COUNT; j++) { - const struct mouse_binding *collision = &conf->bindings.mouse[j]; - if (collision->button == i && collision->count == count) { + tll_foreach(conf->bindings.mouse, it) { + if (it->item.button == i && it->item.count == count) { LOG_ERR("%s:%d: %s already mapped to %s", path, lineno, - value, binding_action_map[collision->action]); + value, binding_action_map[it->item.action]); return false; } } - conf->bindings.mouse[action] = (struct mouse_binding){i, count, action}; + bool already_added = false; + tll_foreach(conf->bindings.mouse, it) { + if (it->item.action == action) { + it->item.button = i; + it->item.count = count; + already_added = true; + break; + } + } + + if (!already_added) { + struct mouse_binding binding = { + .action = action, + .button = i, + .count = count, + }; + tll_push_back(conf->bindings.mouse, binding); + } return true; } @@ -896,42 +942,6 @@ config_load(struct config *conf, const char *conf_path) .cursor = 0, }, }, - - .bindings = { - .key = { - [BIND_ACTION_SCROLLBACK_UP] = strdup("Shift+Page_Up"), - [BIND_ACTION_SCROLLBACK_DOWN] = strdup("Shift+Page_Down"), - [BIND_ACTION_CLIPBOARD_COPY] = strdup("Control+Shift+C"), - [BIND_ACTION_CLIPBOARD_PASTE] = strdup("Control+Shift+V"), - [BIND_ACTION_SEARCH_START] = strdup("Control+Shift+R"), - [BIND_ACTION_FONT_SIZE_UP] = strdup("Control+plus Control+equal Control+KP_Add"), - [BIND_ACTION_FONT_SIZE_DOWN] = strdup("Control+minus Control+KP_Subtract"), - [BIND_ACTION_FONT_SIZE_RESET] = strdup("Control+0 Control+KP_0"), - [BIND_ACTION_SPAWN_TERMINAL] = strdup("Control+Shift+N"), - }, - .mouse = { - [BIND_ACTION_PRIMARY_PASTE] = {BTN_MIDDLE, 1, BIND_ACTION_PRIMARY_PASTE}, - }, - .search = { - [BIND_ACTION_SEARCH_CANCEL] = strdup("Control+g Escape"), - [BIND_ACTION_SEARCH_COMMIT] = strdup("Return"), - [BIND_ACTION_SEARCH_FIND_PREV] = strdup("Control+r"), - [BIND_ACTION_SEARCH_FIND_NEXT] = strdup("Control+s"), - [BIND_ACTION_SEARCH_EDIT_LEFT] = strdup("Left Control+b"), - [BIND_ACTION_SEARCH_EDIT_LEFT_WORD] = strdup("Control+Left Mod1+b"), - [BIND_ACTION_SEARCH_EDIT_RIGHT] = strdup("Right Control+f"), - [BIND_ACTION_SEARCH_EDIT_RIGHT_WORD] = strdup("Control+Right Mod1+f"), - [BIND_ACTION_SEARCH_EDIT_HOME] = strdup("Home Control+a"), - [BIND_ACTION_SEARCH_EDIT_END] = strdup("End Control+e"), - [BIND_ACTION_SEARCH_DELETE_PREV] = strdup("BackSpace"), - [BIND_ACTION_SEARCH_DELETE_PREV_WORD] = strdup("Mod1+BackSpace Control+BackSpace"), - [BIND_ACTION_SEARCH_DELETE_NEXT] = strdup("Delete "), - [BIND_ACTION_SEARCH_DELETE_NEXT_WORD] = strdup("Mod1+d Control+Delete"), - [BIND_ACTION_SEARCH_EXTEND_WORD] = strdup("Control+w"), - [BIND_ACTION_SEARCH_EXTEND_WORD_WS] = strdup("Control+Shift+W"), - }, - }, - .csd = { .preferred = CONF_CSD_PREFER_SERVER, .title_height = 26, @@ -951,6 +961,63 @@ config_load(struct config *conf, const char *conf_path) }, }; + struct config_key_binding_normal scrollback_up = {BIND_ACTION_SCROLLBACK_UP, strdup("Shift+Page_Up")}; + struct config_key_binding_normal scrollback_down = {BIND_ACTION_SCROLLBACK_DOWN, strdup("Shift+Page_Down")}; + struct config_key_binding_normal clipboard_copy = {BIND_ACTION_CLIPBOARD_COPY, strdup("Control+Shift+C")}; + struct config_key_binding_normal clipboard_paste = {BIND_ACTION_CLIPBOARD_PASTE, strdup("Control+Shift+V")}; + struct config_key_binding_normal search_start = {BIND_ACTION_SEARCH_START, strdup("Control+Shift+R")}; + struct config_key_binding_normal font_size_up = {BIND_ACTION_FONT_SIZE_UP, strdup("Control+plus Control+equal Control+KP_Add")}; + struct config_key_binding_normal font_size_down = {BIND_ACTION_FONT_SIZE_DOWN, strdup("Control+minus Control+KP_Subtract")}; + struct config_key_binding_normal font_size_reset = {BIND_ACTION_FONT_SIZE_RESET, strdup("Control+0 Control+KP_0")}; + struct config_key_binding_normal spawn_terminal = {BIND_ACTION_SPAWN_TERMINAL, strdup("Control+Shift+N")}; + + tll_push_back(conf->bindings.key, scrollback_up); + tll_push_back(conf->bindings.key, scrollback_down); + tll_push_back(conf->bindings.key, clipboard_copy); + tll_push_back(conf->bindings.key, clipboard_paste); + tll_push_back(conf->bindings.key, search_start); + tll_push_back(conf->bindings.key, font_size_up); + tll_push_back(conf->bindings.key, font_size_down); + tll_push_back(conf->bindings.key, font_size_reset); + tll_push_back(conf->bindings.key, spawn_terminal); + + struct mouse_binding primary_paste = {BIND_ACTION_PRIMARY_PASTE, BTN_MIDDLE, 1}; + tll_push_back(conf->bindings.mouse, primary_paste); + + struct config_key_binding_search search_cancel = {BIND_ACTION_SEARCH_CANCEL, strdup("Control+g Escape")}; + struct config_key_binding_search search_commit = {BIND_ACTION_SEARCH_COMMIT, strdup("Return")}; + struct config_key_binding_search search_find_prev = {BIND_ACTION_SEARCH_FIND_PREV, strdup("Control+r")}; + struct config_key_binding_search search_find_next = {BIND_ACTION_SEARCH_FIND_NEXT, strdup("Control+s")}; + struct config_key_binding_search search_edit_left = {BIND_ACTION_SEARCH_EDIT_LEFT, strdup("Left Control+b")}; + struct config_key_binding_search search_edit_left_word = {BIND_ACTION_SEARCH_EDIT_LEFT_WORD, strdup("Control+Left Mod1+b")}; + struct config_key_binding_search search_edit_right = {BIND_ACTION_SEARCH_EDIT_RIGHT, strdup("Right Control+f")}; + struct config_key_binding_search search_edit_right_word = {BIND_ACTION_SEARCH_EDIT_RIGHT_WORD, strdup("Control+Right Mod1+f")}; + struct config_key_binding_search search_edit_home = {BIND_ACTION_SEARCH_EDIT_HOME, strdup("Home Control+a")}; + struct config_key_binding_search search_edit_end = {BIND_ACTION_SEARCH_EDIT_END, strdup("End Control+e")}; + struct config_key_binding_search search_del_prev = {BIND_ACTION_SEARCH_DELETE_PREV, strdup("BackSpace")}; + struct config_key_binding_search search_del_prev_word = {BIND_ACTION_SEARCH_DELETE_PREV_WORD, strdup("Mod1+BackSpace Control+BackSpace")}; + struct config_key_binding_search search_del_next = {BIND_ACTION_SEARCH_DELETE_NEXT, strdup("Delete")}; + struct config_key_binding_search search_del_next_word = {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, strdup("Mod1+d Control+Delete")}; + struct config_key_binding_search search_ext_word = {BIND_ACTION_SEARCH_EXTEND_WORD, strdup("Control+w")}; + struct config_key_binding_search search_ext_word_ws = {BIND_ACTION_SEARCH_EXTEND_WORD_WS, strdup("Control+Shift+W")}; + + tll_push_back(conf->bindings.search, search_cancel); + tll_push_back(conf->bindings.search, search_commit); + tll_push_back(conf->bindings.search, search_find_prev); + tll_push_back(conf->bindings.search, search_find_next); + tll_push_back(conf->bindings.search, search_edit_left); + tll_push_back(conf->bindings.search, search_edit_left_word); + tll_push_back(conf->bindings.search, search_edit_right); + tll_push_back(conf->bindings.search, search_edit_right_word); + tll_push_back(conf->bindings.search, search_edit_home); + tll_push_back(conf->bindings.search, search_edit_end); + tll_push_back(conf->bindings.search, search_del_prev); + tll_push_back(conf->bindings.search, search_del_prev_word); + tll_push_back(conf->bindings.search, search_del_next); + tll_push_back(conf->bindings.search, search_del_next_word); + tll_push_back(conf->bindings.search, search_ext_word); + tll_push_back(conf->bindings.search, search_ext_word_ws); + char *default_path = NULL; if (conf_path == NULL) { if ((default_path = get_config_path()) == NULL) { @@ -995,12 +1062,16 @@ config_free(struct config conf) tll_free(conf.fonts); free(conf.server_socket_path); - for (enum bind_action_normal i = 0; i < BIND_ACTION_COUNT; i++) { - free(conf.bindings.key[i]); - free(conf.bindings.spawn[i]); + tll_foreach(conf.bindings.key, it) { + free(it->item.key); + free(it->item.pipe_cmd); } - for (enum bind_action_search i = 0; i < BIND_ACTION_SEARCH_COUNT; i++) - free(conf.bindings.search[i]); + tll_foreach(conf.bindings.search, it) + free(it->item.key); + + tll_free(conf.bindings.key); + tll_free(conf.bindings.mouse); + tll_free(conf.bindings.search); } struct config_font diff --git a/config.h b/config.h index 06ee197c..2b43b806 100644 --- a/config.h +++ b/config.h @@ -6,6 +6,7 @@ #include #include "terminal.h" +#include "wayland.h" struct config_font { char *pattern; @@ -13,6 +14,17 @@ struct config_font { int px_size; }; +struct config_key_binding_normal { + enum bind_action_normal action; + char *key; + char *pipe_cmd; +}; + +struct config_key_binding_search { + enum bind_action_search action; + char *key; +}; + struct config { char *term; char *shell; @@ -48,10 +60,8 @@ struct config { struct { /* Bindings for "normal" mode */ - char *key[BIND_ACTION_COUNT]; - char *spawn[BIND_ACTION_COUNT]; - - struct mouse_binding mouse[BIND_ACTION_COUNT]; + tll(struct config_key_binding_normal) key; + tll(struct mouse_binding) mouse; /* * Special modes @@ -59,7 +69,7 @@ struct config { /* While searching (not - action to *start* a search is in the * 'key' bindings above */ - char *search[BIND_ACTION_SEARCH_COUNT]; + tll(struct config_key_binding_search) search; } bindings; struct { diff --git a/input.c b/input.c index 00382c4f..e9978fb2 100644 --- a/input.c +++ b/input.c @@ -398,34 +398,33 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, munmap(map_str, size); close(fd); - for (enum bind_action_normal i = 0; i < BIND_ACTION_COUNT; i++) { + tll_foreach(wayl->conf->bindings.key, it) { key_binding_list_t bindings = tll_init(); input_parse_key_binding( - seat->kbd.xkb_keymap, wayl->conf->bindings.key[i], &bindings); + seat->kbd.xkb_keymap, it->item.key, &bindings); - tll_foreach(bindings, it) { + tll_foreach(bindings, it2) { tll_push_back( seat->kbd.bindings.key, ((struct key_binding_normal){ - .bind = it->item, - .action = i, - .pipe_cmd = wayl->conf->bindings.spawn[i]})); + .bind = it2->item, + .action = it->item.action, + .pipe_cmd = it->item.pipe_cmd})); } - tll_free(bindings); } - for (enum bind_action_search i = 0; i < BIND_ACTION_SEARCH_COUNT; i++) { + tll_foreach(wayl->conf->bindings.search, it) { key_binding_list_t bindings = tll_init(); input_parse_key_binding( - seat->kbd.xkb_keymap, wayl->conf->bindings.search[i], &bindings); + seat->kbd.xkb_keymap, it->item.key, &bindings); - tll_foreach(bindings, it) { + tll_foreach(bindings, it2) { tll_push_back( seat->kbd.bindings.search, - ((struct key_binding_search){.bind = it->item, .action = i})); + ((struct key_binding_search){ + .bind = it2->item, .action = it->item.action})); } - tll_free(bindings); } } @@ -1370,9 +1369,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } else { - for (size_t i = 0; i < ALEN(wayl->conf->bindings.mouse); i++) { - const struct mouse_binding *binding = - &wayl->conf->bindings.mouse[i]; + tll_foreach(wayl->conf->bindings.mouse, it) { + const struct mouse_binding *binding = &it->item; if (binding->button != button) { /* Wrong button */ diff --git a/wayland.h b/wayland.h index b11af0d3..dbf63c1b 100644 --- a/wayland.h +++ b/wayland.h @@ -51,9 +51,9 @@ struct key_binding_normal { }; struct mouse_binding { + enum bind_action_normal action; uint32_t button; int count; - enum bind_action_normal action; }; enum bind_action_search { -- cgit v1.3 From be9c566622959d2435caaab0004e498a79d683ca Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 16:47:01 +0200 Subject: input: comments --- input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index e9978fb2..ff4f9edf 100644 --- a/input.c +++ b/input.c @@ -184,7 +184,8 @@ execute_binding(struct seat *seat, struct terminal *term, } } - /* Make sure write-end is closed on exec() */ + /* Make sure write-end is closed on exec() - or the spawned + * program may not terminate*/ { int flags = fcntl(pipe_fd[1], F_GETFD); if (flags < 0 || @@ -211,6 +212,7 @@ execute_binding(struct seat *seat, struct terminal *term, .left = len, }; + /* Asynchronously write the output to the pipe */ if (!fdm_add(term->fdm, pipe_fd[1], EPOLLOUT, &fdm_write_pipe, ctx)) goto pipe_err; -- cgit v1.3 From 22c73eaf4ba37ff8a7982de893e3546cd209aa79 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 18:17:28 +0200 Subject: input: pipe-{visible,scrollback}: redirect stdout/stderr to /dev/null --- input.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index ff4f9edf..0e4cb675 100644 --- a/input.c +++ b/input.c @@ -163,6 +163,14 @@ execute_binding(struct seat *seat, struct terminal *term, goto pipe_err; } + int stdout_fd = open("/dev/null", O_WRONLY); + int stderr_fd = open("/dev/null", O_WRONLY); + + if (stdout_fd < 0 || stderr_fd < 0) { + LOG_ERRNO("failed to open /dev/null"); + goto pipe_err; + } + char *text; size_t len; @@ -196,7 +204,7 @@ execute_binding(struct seat *seat, struct terminal *term, } } - if (!spawn(term->reaper, NULL, argv, pipe_fd[0], -1, -1)) + if (!spawn(term->reaper, NULL, argv, pipe_fd[0], stdout_fd, stderr_fd)) goto pipe_err; /* Not needed anymore */ @@ -219,6 +227,10 @@ execute_binding(struct seat *seat, struct terminal *term, break; pipe_err: + if (stdout_fd >= 0) + close(stdout_fd); + if (stderr_fd >= 0) + close(stderr_fd); if (pipe_fd[0] >= 0) close(pipe_fd[0]); if (pipe_fd[1] >= 0) -- cgit v1.3