summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-kill-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-10-22 23:11:42 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-10-22 23:11:42 +0000
commita93bb0ab56992f9bad58cde08d3a8e44394352cd (patch)
treed3dc171b16806f8733b192b59a5baa5990a41e2d /usr.bin/tmux/cmd-kill-window.c
parent848af55a918bad3d12f57da063c30ab88d596c7c (diff)
Merge unlink-window into kill-window.
Diffstat (limited to 'usr.bin/tmux/cmd-kill-window.c')
-rw-r--r--usr.bin/tmux/cmd-kill-window.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-kill-window.c b/usr.bin/tmux/cmd-kill-window.c
index ef51ca8692b..c5f08fda15e 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.15 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-kill-window.c,v 1.16 2014/10/22 23:11:41 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,23 +34,48 @@ const struct cmd_entry cmd_kill_window_entry = {
cmd_kill_window_exec
};
+const struct cmd_entry cmd_unlink_window_entry = {
+ "unlink-window", "unlinkw",
+ "kt:", 0, 0,
+ "[-k] " CMD_TARGET_WINDOW_USAGE,
+ 0,
+ cmd_kill_window_exec
+};
+
enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
- struct args *args = self->args;
- struct winlink *wl, *wl2, *wl3;
- struct session *s;
+ struct args *args = self->args;
+ struct winlink *wl, *wl2, *wl3;
+ struct window *w;
+ struct session *s;
+ struct session_group *sg;
+ u_int references;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
+ w = wl->window;
- if (args_has(args, 'a')) {
- RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
- if (wl != wl2)
- server_kill_window(wl2->window);
+ if (self->entry == &cmd_unlink_window_entry) {
+ sg = session_group_find(s);
+ if (sg != NULL)
+ references = session_group_count(sg);
+ else
+ references = 1;
+ if (!args_has(self->args, 'k') && w->references == references) {
+ cmdq_error(cmdq, "window only linked to one session");
+ return (CMD_RETURN_ERROR);
}
- } else
- server_kill_window(wl->window);
+ server_unlink_window(s, wl);
+ } else {
+ if (args_has(args, 'a')) {
+ RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
+ if (wl != wl2)
+ server_kill_window(wl2->window);
+ }
+ } else
+ server_kill_window(wl->window);
+ }
recalculate_sizes();
return (CMD_RETURN_NORMAL);