Last window option.

This commit is contained in:
Nicholas Marriott 2007-09-20 18:03:23 +00:00
parent 2cd99f0ebb
commit 34f87e521b
5 changed files with 70 additions and 8 deletions

View File

@ -1,5 +1,6 @@
20 September 2007 20 September 2007
* Record last window and ^L key to switch to it. Largely from Maximilian Gass.
* Reset ignored signals in child after forkpty, makes ^C work. * Reset ignored signals in child after forkpty, makes ^C work.
* Wrap on next/previous. From Maximilian Gass. * Wrap on next/previous. From Maximilian Gass.
@ -25,5 +26,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.7 2007-09-20 09:43:33 nicm Exp $ $Id: CHANGES,v 1.8 2007-09-20 18:03:23 nicm Exp $

View File

@ -1,4 +1,4 @@
/* $Id: command.c,v 1.3 2007-08-27 13:45:26 nicm Exp $ */ /* $Id: command.c,v 1.4 2007-09-20 18:03:23 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -29,6 +29,7 @@ int cmd_fn_next(struct buffer *, int);
int cmd_fn_previous(struct buffer *, int); int cmd_fn_previous(struct buffer *, int);
int cmd_fn_refresh(struct buffer *, int); int cmd_fn_refresh(struct buffer *, int);
int cmd_fn_rename(struct buffer *, int); int cmd_fn_rename(struct buffer *, int);
int cmd_fn_last(struct buffer *, int);
struct cmd { struct cmd {
int key; int key;
@ -58,7 +59,9 @@ struct cmd cmd_table[] = {
{ 'R', cmd_fn_refresh, 0 }, { 'R', cmd_fn_refresh, 0 },
{ 'r', cmd_fn_refresh, 0 }, { 'r', cmd_fn_refresh, 0 },
{ 'T', cmd_fn_rename, 0 }, { 'T', cmd_fn_rename, 0 },
{ 't', cmd_fn_rename, 0 } { 't', cmd_fn_rename, 0 },
{ 'L', cmd_fn_last, 0 },
{ 'l', cmd_fn_last, 0 }
}; };
/* Dispatch to a command. */ /* Dispatch to a command. */
@ -163,3 +166,17 @@ cmd_fn_rename(struct buffer *srv_out, unused int arg)
return (0); return (0);
} }
/* Handle last command. */
int
cmd_fn_last(struct buffer *srv_out, unused int arg)
{
struct hdr hdr;
hdr.type = MSG_LAST;
hdr.size = 0;
buffer_write(srv_out, &hdr, sizeof hdr);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.8 2007-08-27 20:36:52 nicm Exp $ */ /* $Id: server.c,v 1.9 2007-09-20 18:03:23 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -75,6 +75,7 @@ void process_refresh_msg(struct client *, struct hdr *);
void process_sessions_msg(struct client *, struct hdr *); void process_sessions_msg(struct client *, struct hdr *);
void process_windows_msg(struct client *, struct hdr *); void process_windows_msg(struct client *, struct hdr *);
void process_rename_msg(struct client *, struct hdr *); void process_rename_msg(struct client *, struct hdr *);
void process_last_msg(struct client *, struct hdr *);
void rename_callback(struct client *, const char *); void rename_callback(struct client *, const char *);
/* Fork and start server process. */ /* Fork and start server process. */
@ -768,6 +769,9 @@ process_client(struct client *c)
case MSG_RENAME: case MSG_RENAME:
process_rename_msg(c, &hdr); process_rename_msg(c, &hdr);
break; break;
case MSG_LAST:
process_last_msg(c, &hdr);
break;
default: default:
fatalx("unexpected message"); fatalx("unexpected message");
} }
@ -1061,6 +1065,21 @@ process_rename_msg(struct client *c, struct hdr *hdr)
c->session->window->name, MAXNAMELEN, rename_callback); c->session->window->name, MAXNAMELEN, rename_callback);
} }
/* Last window message from client */
void
process_last_msg(struct client *c, struct hdr *hdr)
{
if (c->session == NULL)
return;
if (hdr->size != 0)
fatalx("bad MSG_LAST size");
if (session_last(c->session) == 0)
changed_window(c);
else
write_message(c, "No last window");
}
/* Callback for rename. */ /* Callback for rename. */
void void
rename_callback(struct client *c, const char *string) rename_callback(struct client *c, const char *string)

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.8 2007-09-20 08:21:59 nicm Exp $ */ /* $Id: session.c,v 1.9 2007-09-20 18:03:23 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -51,6 +51,7 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
s = xmalloc(sizeof *s); s = xmalloc(sizeof *s);
s->tim = time(NULL); s->tim = time(NULL);
s->window = s->last = NULL;
ARRAY_INIT(&s->windows); ARRAY_INIT(&s->windows);
if (session_new(s, cmd, sx, sy) != 0) { if (session_new(s, cmd, sx, sy) != 0) {
@ -112,6 +113,7 @@ session_new(struct session *s, const char *cmd, u_int sx, u_int sy)
return (-1); return (-1);
session_attach(s, w); session_attach(s, w);
s->last = s->window;
s->window = w; s->window = w;
return (0); return (0);
} }
@ -128,7 +130,7 @@ int
session_detach(struct session *s, struct window *w) session_detach(struct session *s, struct window *w)
{ {
if (s->window == w) { if (s->window == w) {
if (session_next(s) != 0) if (session_last(s) == -1)
session_previous(s); session_previous(s);
} }
@ -168,6 +170,7 @@ session_next(struct session *s)
if (w == s->window) if (w == s->window)
return (1); return (1);
} }
s->last = s->window;
s->window = w; s->window = w;
return (0); return (0);
} }
@ -187,6 +190,7 @@ session_previous(struct session *s)
if (w == s->window) if (w == s->window)
return (1); return (1);
} }
s->last = s->window;
s->window = w; s->window = w;
return (0); return (0);
} }
@ -200,6 +204,24 @@ session_select(struct session *s, u_int i)
w = window_at(&s->windows, i); w = window_at(&s->windows, i);
if (w == NULL) if (w == NULL)
return (-1); return (-1);
s->last = s->window;
s->window = w;
return (0);
}
/* Move session to last used window. */
int
session_last(struct session *s)
{
struct window *w;
w = s->last;
if (w == NULL)
return (-1);
if (w == s->window)
return (1);
s->last = s->window;
s->window = w; s->window = w;
return (0); return (0);
} }

7
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.8 2007-09-20 09:43:33 nicm Exp $ */ /* $Id: tmux.h,v 1.9 2007-09-20 18:03:23 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -281,7 +281,8 @@ enum hdrtype {
MSG_SESSIONS, MSG_SESSIONS,
MSG_WINDOWS, MSG_WINDOWS,
MSG_PAUSE, MSG_PAUSE,
MSG_RENAME MSG_RENAME,
MSG_LAST
}; };
/* Message header structure. */ /* Message header structure. */
@ -403,6 +404,7 @@ struct session {
time_t tim; time_t tim;
struct window *window; struct window *window;
struct window *last;
struct windows windows; struct windows windows;
}; };
ARRAY_DECL(sessions, struct session *); ARRAY_DECL(sessions, struct session *);
@ -492,6 +494,7 @@ int session_has(struct session *, struct window *);
int session_next(struct session *); int session_next(struct session *);
int session_previous(struct session *); int session_previous(struct session *);
int session_select(struct session *, u_int); int session_select(struct session *, u_int);
int session_last(struct session *);
/* buffer.c */ /* buffer.c */
struct buffer *buffer_create(size_t); struct buffer *buffer_create(size_t);