diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-01 01:12:10 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-01 01:12:10 +0000 |
commit | 3acf300bbec4893d8bd3e914fabe1e4849df2862 (patch) | |
tree | 4cbb09d22f1d9f77f28f53b557c4a3103f61f37e | |
parent | a6ac7fbb40bf907ea1f044367f9f66bf1fdea65b (diff) |
Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.
Pointed out by joshe@.
-rw-r--r-- | usr.bin/tmux/cmd-attach-session.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-switch-client.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 12 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
8 files changed, 28 insertions, 24 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 0a2a2b27584..6404c14dec6 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.13 2010/12/21 22:37:59 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.14 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -74,6 +74,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) } ctx->curclient->session = s; + session_update_activity(s); server_redraw_client(ctx->curclient); } else { if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { @@ -96,6 +97,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) server_write_session(s, MSG_DETACH, NULL, 0); ctx->cmdclient->session = s; + session_update_activity(s); server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); update = options_get_string(&s->options, "update-environment"); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index e7befc5a330..194361b4866 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.32 2010/12/20 00:17:22 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.33 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -284,12 +284,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (old_s != NULL) ctx->cmdclient->last_session = old_s; ctx->cmdclient->session = s; + session_update_activity(s); server_redraw_client(ctx->cmdclient); } else { old_s = ctx->curclient->session; if (old_s != NULL) ctx->curclient->last_session = old_s; ctx->curclient->session = s; + session_update_activity(s); server_redraw_client(ctx->curclient); } } diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index e28c8fd7b5c..9eb3b8fe702 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.9 2010/12/20 00:17:22 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.10 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -173,6 +173,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx) if (c->session != NULL) c->last_session = c->session; c->session = s; + session_update_activity(s); recalculate_sizes(); server_check_unattached(); diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 38434adf28b..1652eb8c66e 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.46 2010/12/29 21:49:06 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.47 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -761,11 +761,8 @@ server_client_msg_dispatch(struct client *c) if (gettimeofday(&c->activity_time, NULL) != 0) fatal("gettimeofday"); - if (c->session != NULL) { - memcpy(&c->session->activity_time, - &c->activity_time, - sizeof c->session->activity_time); - } + if (c->session != NULL) + session_update_activity(c->session); tty_start_tty(&c->tty); server_redraw_client(c); diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 9c810b71965..1589cf7daa8 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.48 2010/12/23 21:56:38 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.49 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -396,6 +396,7 @@ server_destroy_session(struct session *s) } else { c->last_session = NULL; c->session = s_new; + session_update_activity(s_new); server_redraw_client(c); } } diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 11b871bbc6a..2d71a474087 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.98 2010/12/30 23:16:18 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.99 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -494,12 +494,8 @@ server_lock_server(void) t = time(NULL); RB_FOREACH(s, sessions, &sessions) { - if (s->flags & SESSION_UNATTACHED) { - if (gettimeofday(&s->activity_time, NULL) != 0) - fatal("gettimeofday failed"); + if (s->flags & SESSION_UNATTACHED) continue; - } - timeout = options_get_number(&s->options, "lock-after-time"); if (timeout <= 0 || t <= s->activity_time.tv_sec + timeout) return; /* not timed out */ @@ -519,12 +515,8 @@ server_lock_sessions(void) t = time(NULL); RB_FOREACH(s, sessions, &sessions) { - if (s->flags & SESSION_UNATTACHED) { - if (gettimeofday(&s->activity_time, NULL) != 0) - fatal("gettimeofday failed"); + if (s->flags & SESSION_UNATTACHED) continue; - } - timeout = options_get_number(&s->options, "lock-after-time"); if (timeout > 0 && t > s->activity_time.tv_sec + timeout) { server_lock_session(s); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 860fc9fa25e..31bdc553e3a 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.26 2010/12/30 23:16:18 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.27 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -97,7 +97,7 @@ session_create(const char *name, const char *cmd, const char *cwd, if (gettimeofday(&s->creation_time, NULL) != 0) fatal("gettimeofday failed"); - memcpy(&s->activity_time, &s->creation_time, sizeof s->activity_time); + session_update_activity(s); s->cwd = xstrdup(cwd); @@ -164,6 +164,14 @@ session_destroy(struct session *s) RB_INSERT(sessions, &dead_sessions, s); } +/* Update session active time. */ +void +session_update_activity(struct session *s) +{ + if (gettimeofday(&s->activity_time, NULL) != 0) + fatal("gettimeofday"); +} + /* Find the next usable session. */ struct session * session_next_session(struct session *s) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 3c747bcd7ba..dd72c9720e4 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.258 2010/12/30 23:20:13 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.259 2011/01/01 01:12:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1980,6 +1980,7 @@ struct session *session_create(const char *, const char *, const char *, struct environ *, struct termios *, int, u_int, u_int, char **); void session_destroy(struct session *); +void session_update_activity(struct session *); struct session *session_next_session(struct session *); struct session *session_previous_session(struct session *); struct winlink *session_new(struct session *, |