diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-17 20:37:04 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-17 20:37:04 +0000 |
commit | 4bc25501db8414c43e694bbd75cc3e2c8e3c40d5 (patch) | |
tree | dd5fc5c9f31edad51426459d45326b13a8a1df23 | |
parent | ac7475a98ccdb093fb64cb987f661dda0598b077 (diff) |
Make it so using kill-pane to destroy the last pane in a window destroys the
window instead of being an error.
-rw-r--r-- | usr.bin/tmux/cmd-kill-pane.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-kill-window.c | 30 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 35 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 3 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
5 files changed, 44 insertions, 34 deletions
diff --git a/usr.bin/tmux/cmd-kill-pane.c b/usr.bin/tmux/cmd-kill-pane.c index c3b7b71297e..ca642e5df8c 100644 --- a/usr.bin/tmux/cmd-kill-pane.c +++ b/usr.bin/tmux/cmd-kill-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-kill-pane.c,v 1.2 2009/07/13 23:11:35 nicm Exp $ */ +/* $OpenBSD: cmd-kill-pane.c,v 1.3 2009/07/17 20:37:03 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -61,8 +61,9 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } if (window_count_panes(wl->window) == 1) { - ctx->error(ctx, "can't kill pane: %d", data->pane); - return (-1); + /* Only one pane, kill the window. */ + server_kill_window(wl->window); + return (0); } window_remove_pane(wl->window, wp); diff --git a/usr.bin/tmux/cmd-kill-window.c b/usr.bin/tmux/cmd-kill-window.c index a083e0caf4f..f5ded5e6342 100644 --- a/usr.bin/tmux/cmd-kill-window.c +++ b/usr.bin/tmux/cmd-kill-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-kill-window.c,v 1.3 2009/07/15 08:00:49 nicm Exp $ */ +/* $OpenBSD: cmd-kill-window.c,v 1.4 2009/07/17 20:37:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -44,37 +44,11 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; struct winlink *wl; - struct window *w; - struct session *s; - struct client *c; - u_int i, j; - int destroyed; if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) return (-1); - w = wl->window; - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s == NULL || !session_has(s, w)) - continue; - if ((wl = winlink_find_by_window(&s->windows, w)) == NULL) - continue; - - destroyed = session_detach(s, wl); - for (j = 0; j < ARRAY_LENGTH(&clients); j++) { - c = ARRAY_ITEM(&clients, j); - if (c == NULL || c->session != s) - continue; - - if (destroyed) { - c->session = NULL; - server_write_client(c, MSG_EXIT, NULL, 0); - } else - server_redraw_client(c); - } - } - recalculate_sizes(); + server_kill_window(wl->window); return (0); } diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 8d42ca75cb5..6d3df51b6af 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.7 2009/07/17 07:09:46 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.8 2009/07/17 20:37:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -228,3 +228,36 @@ wrong: return (-1); } + +void +server_kill_window(struct window *w) +{ + struct session *s; + struct winlink *wl; + struct client *c; + u_int i, j; + int destroyed; + + + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + s = ARRAY_ITEM(&sessions, i); + if (s == NULL || !session_has(s, w)) + continue; + if ((wl = winlink_find_by_window(&s->windows, w)) == NULL) + continue; + + destroyed = session_detach(s, wl); + for (j = 0; j < ARRAY_LENGTH(&clients); j++) { + c = ARRAY_ITEM(&clients, j); + if (c == NULL || c->session != s) + continue; + + if (destroyed) { + c->session = NULL; + server_write_client(c, MSG_EXIT, NULL, 0); + } else + server_redraw_client(c); + } + } + recalculate_sizes(); +} diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 9ced913da4b..be9b3af4b17 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.35 2009/07/17 18:45:08 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.36 2009/07/17 20:37:03 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -768,6 +768,7 @@ returns success. .Xc .D1 (alias: Ic killp ) Destroy the given pane. +If no panes remain in the containing window, it is also destroyed. .It Xo Ic kill-server .Xc Kill the diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ed504446be7..919a1367679 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.36 2009/07/17 18:45:08 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.37 2009/07/17 20:37:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1284,6 +1284,7 @@ void server_redraw_window(struct window *); void server_status_window(struct window *); void server_lock(void); int server_unlock(const char *); +void server_kill_window(struct window *); /* status.c */ int status_redraw(struct client *); |