aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-07-15 17:45:09 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-07-15 17:45:09 +0000
commit8bfbc8c61d14369a023444f49a4708e551cb7342 (patch)
tree196948a0af01df5e240be708e62d323cd06d63be
parentff90170738dad3ab6d302790672c57a3e10e9075 (diff)
downloadrtmux-8bfbc8c61d14369a023444f49a4708e551cb7342.tar.gz
rtmux-8bfbc8c61d14369a023444f49a4708e551cb7342.tar.bz2
rtmux-8bfbc8c61d14369a023444f49a4708e551cb7342.zip
The man page says that kill-window removes the window entirely, unlinking it
from any sessions. In fact the implementation only affected the current session, making it the same as unlink-window but destroying the window if it was linked into only one session (unlinkw gives an error). Change the behaviour to match what it documented and was originally intended.
-rw-r--r--cmd-kill-window.c35
-rw-r--r--window.c15
2 files changed, 37 insertions, 13 deletions
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index b4d47005..397ffff9 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-kill-window.c,v 1.16 2009-07-14 06:43:32 nicm Exp $ */
+/* $Id: cmd-kill-window.c,v 1.17 2009-07-15 17:45:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -44,24 +44,35 @@ 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;
+ u_int i, j;
int destroyed;
- if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
+ if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return (-1);
+ w = wl->window;
- destroyed = session_detach(s, wl);
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s)
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ s = ARRAY_ITEM(&sessions, i);
+ if (s == NULL || !session_has(s, w))
continue;
- if (destroyed) {
- c->session = NULL;
- server_write_client(c, MSG_EXIT, NULL, 0);
- } else
- server_redraw_client(c);
+ 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/window.c b/window.c
index 3823158a..e290d8be 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.92 2009-07-15 17:43:21 nicm Exp $ */
+/* $Id: window.c,v 1.93 2009-07-15 17:45:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -80,6 +80,19 @@ winlink_cmp(struct winlink *wl1, struct winlink *wl2)
}
struct winlink *
+winlink_find_by_window(struct winlinks *wwl, struct window *w)
+{
+ struct winlink *wl;
+
+ RB_FOREACH(wl, winlinks, wwl) {
+ if (wl->window == w)
+ return (wl);
+ }
+
+ return (NULL);
+}
+
+struct winlink *
winlink_find_by_index(struct winlinks *wwl, int idx)
{
struct winlink wl;