mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Last window option.
This commit is contained in:
parent
2cd99f0ebb
commit
34f87e521b
3
CHANGES
3
CHANGES
@ -1,5 +1,6 @@
|
||||
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.
|
||||
* Wrap on next/previous. From Maximilian Gass.
|
||||
|
||||
@ -25,5 +26,5 @@
|
||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||
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 $
|
||||
|
||||
|
21
command.c
21
command.c
@ -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>
|
||||
@ -29,6 +29,7 @@ int cmd_fn_next(struct buffer *, int);
|
||||
int cmd_fn_previous(struct buffer *, int);
|
||||
int cmd_fn_refresh(struct buffer *, int);
|
||||
int cmd_fn_rename(struct buffer *, int);
|
||||
int cmd_fn_last(struct buffer *, int);
|
||||
|
||||
struct cmd {
|
||||
int key;
|
||||
@ -58,7 +59,9 @@ struct cmd cmd_table[] = {
|
||||
{ '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 },
|
||||
{ 'L', cmd_fn_last, 0 },
|
||||
{ 'l', cmd_fn_last, 0 }
|
||||
};
|
||||
|
||||
/* Dispatch to a command. */
|
||||
@ -163,3 +166,17 @@ cmd_fn_rename(struct buffer *srv_out, unused int arg)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
21
server.c
21
server.c
@ -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>
|
||||
@ -75,6 +75,7 @@ void process_refresh_msg(struct client *, struct hdr *);
|
||||
void process_sessions_msg(struct client *, struct hdr *);
|
||||
void process_windows_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 *);
|
||||
|
||||
/* Fork and start server process. */
|
||||
@ -768,6 +769,9 @@ process_client(struct client *c)
|
||||
case MSG_RENAME:
|
||||
process_rename_msg(c, &hdr);
|
||||
break;
|
||||
case MSG_LAST:
|
||||
process_last_msg(c, &hdr);
|
||||
break;
|
||||
default:
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
@ -1061,6 +1065,21 @@ process_rename_msg(struct client *c, struct hdr *hdr)
|
||||
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. */
|
||||
void
|
||||
rename_callback(struct client *c, const char *string)
|
||||
|
26
session.c
26
session.c
@ -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>
|
||||
@ -51,6 +51,7 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
|
||||
|
||||
s = xmalloc(sizeof *s);
|
||||
s->tim = time(NULL);
|
||||
s->window = s->last = NULL;
|
||||
ARRAY_INIT(&s->windows);
|
||||
|
||||
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);
|
||||
session_attach(s, w);
|
||||
|
||||
s->last = s->window;
|
||||
s->window = w;
|
||||
return (0);
|
||||
}
|
||||
@ -128,7 +130,7 @@ int
|
||||
session_detach(struct session *s, struct window *w)
|
||||
{
|
||||
if (s->window == w) {
|
||||
if (session_next(s) != 0)
|
||||
if (session_last(s) == -1)
|
||||
session_previous(s);
|
||||
}
|
||||
|
||||
@ -168,6 +170,7 @@ session_next(struct session *s)
|
||||
if (w == s->window)
|
||||
return (1);
|
||||
}
|
||||
s->last = s->window;
|
||||
s->window = w;
|
||||
return (0);
|
||||
}
|
||||
@ -187,6 +190,7 @@ session_previous(struct session *s)
|
||||
if (w == s->window)
|
||||
return (1);
|
||||
}
|
||||
s->last = s->window;
|
||||
s->window = w;
|
||||
return (0);
|
||||
}
|
||||
@ -200,6 +204,24 @@ session_select(struct session *s, u_int i)
|
||||
w = window_at(&s->windows, i);
|
||||
if (w == NULL)
|
||||
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;
|
||||
return (0);
|
||||
}
|
||||
|
7
tmux.h
7
tmux.h
@ -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>
|
||||
@ -281,7 +281,8 @@ enum hdrtype {
|
||||
MSG_SESSIONS,
|
||||
MSG_WINDOWS,
|
||||
MSG_PAUSE,
|
||||
MSG_RENAME
|
||||
MSG_RENAME,
|
||||
MSG_LAST
|
||||
};
|
||||
|
||||
/* Message header structure. */
|
||||
@ -403,6 +404,7 @@ struct session {
|
||||
time_t tim;
|
||||
|
||||
struct window *window;
|
||||
struct window *last;
|
||||
struct windows windows;
|
||||
};
|
||||
ARRAY_DECL(sessions, struct session *);
|
||||
@ -492,6 +494,7 @@ int session_has(struct session *, struct window *);
|
||||
int session_next(struct session *);
|
||||
int session_previous(struct session *);
|
||||
int session_select(struct session *, u_int);
|
||||
int session_last(struct session *);
|
||||
|
||||
/* buffer.c */
|
||||
struct buffer *buffer_create(size_t);
|
||||
|
Loading…
Reference in New Issue
Block a user