From de24fbb35ce763c5e905c726733a561f5fa34724 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 19 Oct 2007 10:21:36 +0000 Subject: [PATCH] Add a bell-action option. --- CHANGES | 6 +++- TODO | 1 - cmd-set-option.c | 17 +++++++++++- input.c | 4 +-- resize.c | 6 ++-- server-fn.c | 72 ++++++++++++++++++++++++++++++++++++++++++++---- server.c | 23 ++++++++++++---- tmux.c | 5 +++- tmux.h | 29 ++++++++++++------- 9 files changed, 134 insertions(+), 29 deletions(-) diff --git a/CHANGES b/CHANGES index 069adf4b..9167bea9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ 19 October 2007 +* (nicm) bell-style option with three choices: "none" completely ignore bell; + "any" pass through a bell in any window to current; "current" ignore bells + except in current window. This applies only to the bell terminal signal, + the status bar always reflects any bells. * (nicm) Refresh session command. 12 October 2007 @@ -131,5 +135,5 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.42 2007-10-19 09:21:24 nicm Exp $ +$Id: CHANGES,v 1.43 2007-10-19 10:21:24 nicm Exp $ diff --git a/TODO b/TODO index 235ff6ce..2e88f497 100644 --- a/TODO +++ b/TODO @@ -46,7 +46,6 @@ -- For 0.1 -------------------------------------------------------------------- - man page -- sort out bell: passing through should be optional - commands: rename sessions swap windows diff --git a/cmd-set-option.c b/cmd-set-option.c index d76f0adf..b383c0a8 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.8 2007-10-19 09:21:26 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.9 2007-10-19 10:21:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -171,6 +171,21 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx) server_redraw_client(c); } } + } else if (strcmp(data->option, "bell-action") == 0) { + if (data->value == NULL) { + ctx->error(ctx, "invalid value"); + return; + } + if (strcmp(data->value, "any") == 0) + bell_action = BELL_ANY; + else if (strcmp(data->value, "none") == 0) + bell_action = BELL_NONE; + else if (strcmp(data->value, "current") == 0) + bell_action = BELL_CURRENT; + else { + ctx->error(ctx, "unknown bell-action: %s", data->value); + return; + } } else { ctx->error(ctx, "unknown option: %s", data->option); return; diff --git a/input.c b/input.c index c0619299..6d43c760 100644 --- a/input.c +++ b/input.c @@ -1,4 +1,4 @@ -/* $Id: input.c,v 1.23 2007-10-12 11:44:30 nicm Exp $ */ +/* $Id: input.c,v 1.24 2007-10-19 10:21:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -390,7 +390,7 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx) break; case '\007': /* BELL */ ictx->flags |= INPUT_BELL; - break; + return; case '\010': /* BS */ if (ictx->s->cx > 0) ictx->s->cx--; diff --git a/resize.c b/resize.c index 4b32f972..71392604 100644 --- a/resize.c +++ b/resize.c @@ -1,4 +1,4 @@ -/* $Id: resize.c,v 1.3 2007-10-05 18:25:05 nicm Exp $ */ +/* $Id: resize.c,v 1.4 2007-10-19 10:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -113,8 +113,8 @@ recalculate_sizes(void) log_debug("window size %u,%u (was %u,%u)", ssx, ssy, w->screen.sx, w->screen.sy); - server_clear_window(w); + server_clear_window_cur(w); window_resize(w, ssx, ssy); - server_redraw_window(w); + server_redraw_window_cur(w); } } diff --git a/server-fn.c b/server-fn.c index 58a35b15..65a4ab99 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.20 2007-10-12 11:24:15 nicm Exp $ */ +/* $Id: server-fn.c,v 1.21 2007-10-19 10:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -105,7 +105,7 @@ server_write_session( } void -server_write_window( +server_write_window_cur( struct window *w, enum hdrtype type, const void *buf, size_t len) { struct client *c; @@ -122,6 +122,25 @@ server_write_window( } } +void +server_write_window_all( + struct window *w, enum hdrtype type, const void *buf, size_t len) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL) + continue; + if (session_has(c->session, w)) { + if (c->flags & CLIENT_HOLD) /* XXX OUTPUT only */ + continue; + server_write_client(c, type, buf, len); + } + } +} + void server_status_client(struct client *c) { @@ -222,7 +241,7 @@ server_status_session(struct session *s) } void -server_clear_window(struct window *w) +server_clear_window_cur(struct window *w) { struct client *c; u_int i; @@ -235,7 +254,22 @@ server_clear_window(struct window *w) } void -server_redraw_window(struct window *w) +server_clear_window_all(struct window *w) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL) + continue; + if (session_has(c->session, w)) + server_redraw_client(c); + } +} + +void +server_redraw_window_cur(struct window *w) { struct client *c; u_int i; @@ -248,7 +282,35 @@ server_redraw_window(struct window *w) } void -server_status_window(struct window *w) +server_redraw_window_all(struct window *w) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL) + continue; + if (session_has(c->session, w)) + server_redraw_client(c); + } +} + +void +server_status_window_cur(struct window *w) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session != NULL && c->session->window == w) + server_status_client(c); + } +} + +void +server_status_window_all(struct window *w) { struct client *c; u_int i; diff --git a/server.c b/server.c index edaa07f3..dfc96fc4 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.27 2007-10-12 11:24:15 nicm Exp $ */ +/* $Id: server.c,v 1.28 2007-10-19 10:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -328,8 +328,10 @@ server_handle_window(struct window *w) b = buffer_create(BUFSIZ); window_data(w, b); - if (BUFFER_USED(b) != 0) - server_write_window(w, MSG_DATA, BUFFER_OUT(b), BUFFER_USED(b)); + if (BUFFER_USED(b) != 0) { + server_write_window_cur( + w, MSG_DATA, BUFFER_OUT(b), BUFFER_USED(b)); + } buffer_destroy(b); if (!(w->flags & WINDOW_BELL)) @@ -341,8 +343,19 @@ server_handle_window(struct window *w) session_addbell(s, w); } - server_write_window(w, MSG_DATA, "\007", 1); - server_status_window(w); + switch (bell_action) { + case BELL_ANY: + server_write_window_all(w, MSG_DATA, "\007", 1); + break; + case BELL_CURRENT: + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + s = ARRAY_ITEM(&sessions, i); + if (s != NULL && s->window == w) + server_write_session(s, MSG_DATA, "\007", 1); + } + break; + } + server_status_window_all(w); w->flags &= ~WINDOW_BELL; } diff --git a/tmux.c b/tmux.c index 5314f863..25c269f3 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.32 2007-10-12 17:52:41 nicm Exp $ */ +/* $Id: tmux.c,v 1.33 2007-10-19 10:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,6 +42,7 @@ int prefix_key = META; u_int status_lines; u_char status_colour; char *default_command; +int bell_action; void sighandler(int); @@ -199,6 +200,8 @@ main(int argc, char **argv) status_lines = 1; status_colour = 0x02; + bell_action = BELL_ANY; + shell = getenv("SHELL"); if (shell == NULL || *shell == '\0') shell = "/bin/ksh"; diff --git a/tmux.h b/tmux.h index 1757812a..edfab258 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.59 2007-10-19 09:21:26 nicm Exp $ */ +/* $Id: tmux.h,v 1.60 2007-10-19 10:21:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -495,11 +495,15 @@ ARRAY_DECL(bindings, struct binding *); /* tmux.c */ extern volatile sig_atomic_t sigwinch; extern volatile sig_atomic_t sigterm; -extern int prefix_key; -extern int debug_level; -extern u_int status_lines; -extern u_char status_colour; -extern char *default_command; +#define BELL_NONE 0 +#define BELL_ANY 1 +#define BELL_CURRENT 2 +extern int bell_action; +extern int prefix_key; +extern int debug_level; +extern u_int status_lines; +extern u_char status_colour; +extern char *default_command; void usage(char **, const char *, ...); void logfile(const char *); void siginit(void); @@ -571,16 +575,21 @@ void server_write_client( struct client *, enum hdrtype, const void *, size_t); void server_write_session( struct session *, enum hdrtype, const void *, size_t); -void server_write_window( +void server_write_window_cur( + struct window *, enum hdrtype, const void *, size_t); +void server_write_window_all( struct window *, enum hdrtype, const void *, size_t); void server_status_client(struct client *); void server_clear_client(struct client *); void server_redraw_client(struct client *); void server_status_session(struct session *); void server_redraw_session(struct session *); -void server_status_window(struct window *); -void server_clear_window(struct window *); -void server_redraw_window(struct window *); +void server_status_window_cur(struct window *); +void server_status_window_all(struct window *); +void server_clear_window_cur(struct window *); +void server_clear_window_all(struct window *); +void server_redraw_window_cur(struct window *); +void server_redraw_window_all(struct window *); void server_write_message(struct client *, const char *, ...); /* status.c */