summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-06-27 00:22:23 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-06-27 00:22:23 +0000
commit1614421baddf7c0248e941128db3ea2e704e6c70 (patch)
tree3f374b65b71373d0f2dba67a55cd0699c9044926 /usr.bin
parentfa5bd8327c7cdb17542e820cdd0162eb31df213a (diff)
New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it is switched to the most recently active session.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-set-option.c3
-rw-r--r--usr.bin/tmux/server-fn.c38
-rw-r--r--usr.bin/tmux/tmux.19
-rw-r--r--usr.bin/tmux/tmux.c5
4 files changed, 46 insertions, 9 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index a5d5d408f3d..acb6165b32a 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.36 2010/05/14 19:03:09 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.37 2010/06/27 00:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -87,6 +87,7 @@ const struct set_option_entry set_session_option_table[] = {
{ "default-path", SET_OPTION_STRING, 0, 0, NULL },
{ "default-shell", SET_OPTION_STRING, 0, 0, NULL },
{ "default-terminal", SET_OPTION_STRING, 0, 0, NULL },
+ { "detach-on-destroy", SET_OPTION_FLAG, 0, 0, NULL },
{ "display-panes-colour", SET_OPTION_COLOUR, 0, 0, NULL },
{ "display-panes-active-colour", SET_OPTION_COLOUR, 0, 0, NULL },
{ "display-panes-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c
index 155bdfe380d..b4fc48f1a36 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.38 2010/06/26 23:55:50 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.39 2010/06/27 00:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,7 +24,8 @@
#include "tmux.h"
-void server_callback_identify(int, short, void *);
+struct session *server_next_session(struct session *);
+void server_callback_identify(int, short, void *);
void
server_fill_environ(struct session *s, struct environ *env)
@@ -358,18 +359,47 @@ server_destroy_session_group(struct session *s)
}
}
+struct session *
+server_next_session(struct session *s)
+{
+ struct session *s_loop, *s_out;
+ u_int i;
+
+ s_out = NULL;
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ s_loop = ARRAY_ITEM(&sessions, i);
+ if (s_loop == s)
+ continue;
+ if (s_out == NULL ||
+ timercmp(&s_loop->activity_time, &s_out->activity_time, <))
+ s_out = s_loop;
+ }
+ return (s_out);
+}
+
void
server_destroy_session(struct session *s)
{
struct client *c;
+ struct session *s_new;
u_int i;
+ if (!options_get_number(&s->options, "detach-on-destroy"))
+ s_new = server_next_session(s);
+ else
+ s_new = NULL;
+
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session != s)
continue;
- c->session = NULL;
- server_write_client(c, MSG_EXIT, NULL, 0);
+ if (s_new == NULL) {
+ c->session = NULL;
+ server_write_client(c, MSG_EXIT, NULL, 0);
+ } else {
+ c->session = s_new;
+ server_redraw_client(c);
+ }
}
recalculate_sizes();
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 1bb0d90371b..45a8104b684 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.178 2010/06/21 21:44:09 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.179 2010/06/27 00:22:22 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: June 21 2010 $
+.Dd $Mdocdate: June 27 2010 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1557,6 +1557,11 @@ Available window options are listed under
.Pp
Available server options are:
.Bl -tag -width Ds
+.It Ic detach-on-destroy
+If on (the default), the client is detached when the session it is attached to
+is destroyed.
+If off, the client is switched to the most recently active of the remaining
+sessions.
.It Ic escape-time
Set the time in milliseconds for which
.Nm
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 56fc91743db..bdddc047111 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.80 2010/06/26 18:20:53 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.81 2010/06/27 00:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -341,8 +341,9 @@ main(int argc, char **argv)
options_set_string(so, "default-command", "%s", "");
options_set_string(so, "default-shell", "%s", getshell());
options_set_string(so, "default-terminal", "screen");
- options_set_number(so, "display-panes-colour", 4);
+ options_set_number(so, "detach-on-destroy", 1);
options_set_number(so, "display-panes-active-colour", 1);
+ options_set_number(so, "display-panes-colour", 4);
options_set_number(so, "display-panes-time", 1000);
options_set_number(so, "display-time", 750);
options_set_number(so, "history-limit", 2000);