From a1722d5c2e545e4cce376848aab8a39465d3a036 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 15:50:42 +0000 Subject: Remove unnecessary initializers of cmd_ctx. --- key-bindings.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'key-bindings.c') diff --git a/key-bindings.c b/key-bindings.c index 5ebde40c..6909b4b6 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -262,18 +262,15 @@ key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...) void key_bindings_dispatch(struct key_binding *bd, struct client *c) { - struct cmd_ctx ctx; + struct cmd_ctx *ctx; struct cmd *cmd; int readonly; - ctx.msgdata = NULL; - ctx.curclient = c; - - ctx.error = key_bindings_error; - ctx.print = key_bindings_print; - ctx.info = key_bindings_info; - - ctx.cmdclient = NULL; + ctx = cmd_get_ctx(); + ctx->curclient = c; + ctx->error = key_bindings_error; + ctx->print = key_bindings_print; + ctx->info = key_bindings_info; readonly = 1; TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) { @@ -281,9 +278,10 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c) readonly = 0; } if (!readonly && c->flags & CLIENT_READONLY) { - key_bindings_info(&ctx, "Client is read-only"); + key_bindings_info(ctx, "client is read-only"); return; } - cmd_list_exec(bd->cmdlist, &ctx); + cmd_list_exec(bd->cmdlist, ctx); + cmd_free_ctx(ctx); } -- cgit From 2243cfbe7559e6cf48194ff95dcd7eb6df5fe41d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 15:54:29 +0000 Subject: Need to set clients in context before changing their reference count. --- key-bindings.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'key-bindings.c') diff --git a/key-bindings.c b/key-bindings.c index 6909b4b6..0f944c4c 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -266,8 +266,7 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c) struct cmd *cmd; int readonly; - ctx = cmd_get_ctx(); - ctx->curclient = c; + ctx = cmd_get_ctx(NULL, c); ctx->error = key_bindings_error; ctx->print = key_bindings_print; ctx->info = key_bindings_info; -- cgit From 20636d956dd36c1f14152569a4d44a50eea9083d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:54:10 +0000 Subject: Add a command queue to standardize and simplify commands that call other commands and allow a command to block execution of subsequent commands. This allows run-shell and if-shell to be synchronous which has been much requested. Each client has a default command queue and commands are consumed one at a time from it. A command may suspend execution from the queue by returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() - for example run-shell does this from the callback that is fired after the job is freed. When the command queue becomes empty, command clients are automatically exited (unless attaching). A callback is also fired - this is used for nested commands in, for example, if-shell which can block execution of the client's cmdq until a new cmdq becomes empty. Also merge all the old error/info/print functions together and lose the old curclient/cmdclient distinction - a cmdq is bound to one client (or none if in the configuration file), this is a command client if c->session is NULL otherwise an attached client. --- key-bindings.c | 79 +++++----------------------------------------------------- 1 file changed, 6 insertions(+), 73 deletions(-) (limited to 'key-bindings.c') diff --git a/key-bindings.c b/key-bindings.c index 0f944c4c..4e889b7e 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -182,11 +182,11 @@ key_bindings_init(void) RB_INIT(&key_bindings); for (i = 0; i < nitems(table); i++) { - cmdlist = xmalloc(sizeof *cmdlist); - TAILQ_INIT(&cmdlist->list); + cmdlist = xcalloc(1, sizeof *cmdlist); cmdlist->references = 1; + TAILQ_INIT(&cmdlist->list); - cmd = xmalloc(sizeof *cmd); + cmd = xcalloc(1, sizeof *cmd); cmd->entry = table[i].entry; if (cmd->entry->key_binding != NULL) cmd->entry->key_binding(cmd, table[i].key); @@ -199,88 +199,21 @@ key_bindings_init(void) } } -void printflike2 -key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - char *msg; - - if (ctx->curclient->session == NULL) - return; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); - - *msg = toupper((u_char) *msg); - status_message_set(ctx->curclient, "%s", msg); - free(msg); -} - -void printflike2 -key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...) -{ - struct winlink *wl; - va_list ap; - - if (ctx->curclient->session == NULL) - return; - - wl = ctx->curclient->session->curw; - if (wl->window->active->mode != &window_copy_mode) { - window_pane_reset_mode(wl->window->active); - window_pane_set_mode(wl->window->active, &window_copy_mode); - window_copy_init_for_output(wl->window->active); - } - - va_start(ap, fmt); - window_copy_vadd(wl->window->active, fmt, ap); - va_end(ap); -} - -void printflike2 -key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - char *msg; - - if (ctx->curclient->session == NULL) - return; - - if (options_get_number(&global_options, "quiet")) - return; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); - - *msg = toupper((u_char) *msg); - status_message_set(ctx->curclient, "%s", msg); - free(msg); -} - void key_bindings_dispatch(struct key_binding *bd, struct client *c) { - struct cmd_ctx *ctx; struct cmd *cmd; int readonly; - ctx = cmd_get_ctx(NULL, c); - ctx->error = key_bindings_error; - ctx->print = key_bindings_print; - ctx->info = key_bindings_info; - readonly = 1; TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) { if (!(cmd->entry->flags & CMD_READONLY)) readonly = 0; } - if (!readonly && c->flags & CLIENT_READONLY) { - key_bindings_info(ctx, "client is read-only"); + if (!readonly && (c->flags & CLIENT_READONLY)) { + cmdq_info(c->cmdq, "client is read-only"); return; } - cmd_list_exec(bd->cmdlist, ctx); - cmd_free_ctx(ctx); + cmdq_run(c->cmdq, bd->cmdlist); } -- cgit From c71844de631186f3df7ff5a6e3aab613da1e4853 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:57:59 +0000 Subject: Add resize-pane -Z to temporary zoom the active pane to occupy the full window or unzoom (restored to the normal layout) if it already zoomed, bound to C-b z by default. The pane is unzoomed on pretty much any excuse whatsoever. We considered making this a new layout but the requirements are quite different from layouts so decided it is better as a special case. Each current layout cell is saved, a temporary one-cell layout generated and all except the active pane set to NULL. Prompted by suggestions and scripts from several. Thanks to Aaron Jensen and Thiago Padilha for testing an earlier version. --- key-bindings.c | 1 + 1 file changed, 1 insertion(+) (limited to 'key-bindings.c') diff --git a/key-bindings.c b/key-bindings.c index 4e889b7e..625ffddf 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -150,6 +150,7 @@ key_bindings_init(void) { 't', 0, &cmd_clock_mode_entry }, { 'w', 0, &cmd_choose_window_entry }, { 'x', 0, &cmd_confirm_before_entry }, + { 'z', 0, &cmd_resize_pane_entry }, { '{', 0, &cmd_swap_pane_entry }, { '}', 0, &cmd_swap_pane_entry }, { '~', 0, &cmd_show_messages_entry }, -- cgit