From 815815989a103cda0d88fa0670b774b1e3530509 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 4 Oct 2007 00:02:10 +0000 Subject: Next/last/previous window, some other tweaks. --- Makefile | 5 ++- cmd-last-window.c | 55 ++++++++++++++++++++++++ cmd-list-sessions.c | 6 +-- cmd-new-session.c | 4 +- cmd-new-window.c | 18 ++++---- cmd-next-window.c | 55 ++++++++++++++++++++++++ cmd-previous-window.c | 55 ++++++++++++++++++++++++ key-bindings.c | 26 ++++++------ server-fn.c | 113 +++++++++++++++++++++++--------------------------- server-msg.c | 6 +-- server.c | 20 +++------ tmux.h | 26 +++++++----- 12 files changed, 272 insertions(+), 117 deletions(-) create mode 100644 cmd-last-window.c create mode 100644 cmd-next-window.c create mode 100644 cmd-previous-window.c diff --git a/Makefile b/Makefile index bc417a29..db78143d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.14 2007-10-03 23:32:26 nicm Exp $ +# $Id: Makefile,v 1.15 2007-10-04 00:02:10 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean @@ -20,7 +20,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c window.c \ session.c local.c log.c client.c client-msg.c client-fn.c key-string.c \ key-bindings.c cmd.c cmd-new-session.c cmd-detach-session.c \ - cmd-list-sessions.c cmd-new-window.c + cmd-list-sessions.c cmd-new-window.c cmd-next-window.c \ + cmd-previous-window.c cmd-last-window.c YACC= yacc -d diff --git a/cmd-last-window.c b/cmd-last-window.c new file mode 100644 index 00000000..0dd90f0d --- /dev/null +++ b/cmd-last-window.c @@ -0,0 +1,55 @@ +/* $Id: cmd-last-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#include + +#include "tmux.h" + +/* + * Move to last window. + */ + +void cmd_last_window_exec(void *, struct cmd_ctx *); + +const struct cmd_entry cmd_last_window_entry = { + CMD_LASTWINDOW, "last-window", "last", 0, + NULL, + NULL, + cmd_last_window_exec, + NULL, + NULL, + NULL +}; + +void +cmd_last_window_exec(unused void *ptr, struct cmd_ctx *ctx) +{ + struct client *c = ctx->client; + struct session *s = ctx->session; + + if (session_last(s) == 0) + server_redraw_session(s); + else + ctx->error(ctx, "no last window"); + + if (!(ctx->flags & CMD_KEY)) + server_write_client(c, MSG_EXIT, NULL, 0); +} diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 47f3f0a0..0661653a 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-sessions.c,v 1.1 2007-10-03 21:31:07 nicm Exp $ */ +/* $Id: cmd-list-sessions.c,v 1.2 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -27,9 +27,7 @@ * List all sessions. */ -int cmd_list_sessions_parse(void **, int, char **, char **); -const char *cmd_list_sessions_usage(void); -void cmd_list_sessions_exec(void *, struct cmd_ctx *); +void cmd_list_sessions_exec(void *, struct cmd_ctx *); const struct cmd_entry cmd_list_sessions_entry = { CMD_LISTSESSIONS, "list-sessions", "ls", CMD_NOSESSION, diff --git a/cmd-new-session.c b/cmd-new-session.c index 229115a5..0458f5e9 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.2 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: cmd-new-session.c,v 1.3 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -128,7 +128,7 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx) server_write_client(c, MSG_EXIT, NULL, 0); else { server_write_client(c, MSG_READY, NULL, 0); - server_draw_client(c); + server_redraw_client(c); } } diff --git a/cmd-new-window.c b/cmd-new-window.c index 9a78ab31..556ca961 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-window.c,v 1.1 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: cmd-new-window.c,v 1.2 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -120,15 +120,15 @@ cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx) ctx->error(ctx, "command failed: %s", cmd); return; } - if (!data->flag_detached) + if (!data->flag_detached) { session_select(s, i); - - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c != NULL && c->session == s) { - if (!data->flag_detached) - server_draw_client(c); - server_draw_status(c); + server_redraw_session(s); + } else { + /* XXX */ + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session == s) + server_redraw_status(c); } } diff --git a/cmd-next-window.c b/cmd-next-window.c new file mode 100644 index 00000000..216f209c --- /dev/null +++ b/cmd-next-window.c @@ -0,0 +1,55 @@ +/* $Id: cmd-next-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#include + +#include "tmux.h" + +/* + * Move to next window. + */ + +void cmd_next_window_exec(void *, struct cmd_ctx *); + +const struct cmd_entry cmd_next_window_entry = { + CMD_NEXTWINDOW, "next-window", "next", 0, + NULL, + NULL, + cmd_next_window_exec, + NULL, + NULL, + NULL +}; + +void +cmd_next_window_exec(unused void *ptr, struct cmd_ctx *ctx) +{ + struct client *c = ctx->client; + struct session *s = ctx->session; + + if (session_next(s) == 0) + server_redraw_session(s); + else + ctx->error(ctx, "no next window"); + + if (!(ctx->flags & CMD_KEY)) + server_write_client(c, MSG_EXIT, NULL, 0); +} diff --git a/cmd-previous-window.c b/cmd-previous-window.c new file mode 100644 index 00000000..87151d53 --- /dev/null +++ b/cmd-previous-window.c @@ -0,0 +1,55 @@ +/* $Id: cmd-previous-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#include + +#include "tmux.h" + +/* + * Move to previous window. + */ + +void cmd_previous_window_exec(void *, struct cmd_ctx *); + +const struct cmd_entry cmd_previous_window_entry = { + CMD_PREVIOUSWINDOW, "previous-window", "prev", 0, + NULL, + NULL, + cmd_previous_window_exec, + NULL, + NULL, + NULL +}; + +void +cmd_previous_window_exec(unused void *ptr, struct cmd_ctx *ctx) +{ + struct client *c = ctx->client; + struct session *s = ctx->session; + + if (session_previous(s) == 0) + server_redraw_session(s); + else + ctx->error(ctx, "no previous window"); + + if (!(ctx->flags & CMD_KEY)) + server_write_client(c, MSG_EXIT, NULL, 0); +} diff --git a/key-bindings.c b/key-bindings.c index 397533ef..6693a583 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -1,4 +1,4 @@ -/* $Id: key-bindings.c,v 1.2 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: key-bindings.c,v 1.3 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -18,6 +18,7 @@ #include +#include #include #include @@ -81,17 +82,17 @@ key_bindings_init(void) { 's', &cmd_list_sessions_entry }, { 'C', &cmd_new_window_entry }, { 'c', &cmd_new_window_entry }, -/* { 'N', &cmd_next_window }, - { 'n', &cmd_next_window }, - { 'P', &cmd_previous_window }, - { 'p', &cmd_previous_window }, - { 'R', &cmd_refresh_client }, - { 'r', &cmd_refresh_client }, - { 'L', &cmd_last_window }, - { 'l', &cmd_last_window }, - { 'I', &cmd_windo_info }, - { 'i', &cmd_window_info }, - { META, &cmd_meta_entry }, + { 'N', &cmd_next_window_entry }, + { 'n', &cmd_next_window_entry }, + { 'P', &cmd_previous_window_entry }, + { 'p', &cmd_previous_window_entry }, + { 'L', &cmd_last_window_entry }, + { 'l', &cmd_last_window_entry }, +/* { 'R', &cmd_refresh_client_entry }, + { 'r', &cmd_refresh_client_entry }, + { 'I', &cmd_windo_info_entry }, + { 'i', &cmd_window_info_entry }, + { META, &cmd_meta_entry_entry }, *//* { '0', cmdx_fn_select, 0, NULL }, { '1', cmdx_fn_select, 1, NULL }, { '2', cmdx_fn_select, 2, NULL }, @@ -141,6 +142,7 @@ key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...) xvasprintf(&msg, fmt, ap); va_end(ap); + *msg = toupper((u_char) *msg); server_write_message(ctx->client, msg); xfree(msg); } diff --git a/server-fn.c b/server-fn.c index ca95da2c..bceccbdc 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.15 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: server-fn.c,v 1.16 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -74,7 +74,6 @@ server_find_sessid(struct sessid *sid, char **cause) return (s); } -/* Write command to a client. */ void server_write_client( struct client *c, enum hdrtype type, const void *buf, size_t len) @@ -91,56 +90,60 @@ server_write_client( buffer_write(c->out, buf, len); } -/* Write command to a client with two buffers. */ void -server_write_client2(struct client *c, enum hdrtype type, - const void *buf1, size_t len1, const void *buf2, size_t len2) +server_write_session( + struct session *s, enum hdrtype type, const void *buf, size_t len) { - struct hdr hdr; - - log_debug("writing %d to client %d", type, c->fd); - - hdr.type = type; - hdr.size = len1 + len2; + struct client *c; + u_int i; - buffer_write(c->out, &hdr, sizeof hdr); - if (buf1 != NULL) - buffer_write(c->out, buf1, len1); - if (buf2 != NULL) - buffer_write(c->out, buf2, len2); + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session == s) + server_write_client(c, type, buf, len); + } } -/* Write command to all clients attached to a specific window. */ void -server_write_clients( +server_write_window( struct window *w, enum hdrtype type, const void *buf, size_t len) { struct client *c; - struct hdr hdr; u_int i; - hdr.type = type; - hdr.size = len; - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); - if (c != NULL && c->session != NULL) { + if (c != NULL && c->session->window == w) { if (c->flags & CLIENT_HOLD) /* XXX OUTPUT only */ continue; - if (c->session->window == w) { - log_debug( - "writing %d to clients: %d", type, c->fd); - buffer_write(c->out, &hdr, sizeof hdr); - if (buf != NULL) - buffer_write(c->out, buf, len); - } + server_write_client(c, type, buf, len); } } } -/* Draw window on client. */ void -server_draw_client(struct client *c) +server_redraw_status(struct client *c) +{ + struct hdr hdr; + size_t size; + + if (status_lines == 0) + return; + + buffer_ensure(c->out, sizeof hdr); + buffer_add(c->out, sizeof hdr); + size = BUFFER_USED(c->out); + + status_write(c); + + size = BUFFER_USED(c->out) - size; + hdr.type = MSG_DATA; + hdr.size = size; + memcpy(BUFFER_IN(c->out) - size - sizeof hdr, &hdr, sizeof hdr); +} + +void +server_redraw_client(struct client *c) { struct hdr hdr; size_t size; @@ -161,47 +164,35 @@ server_draw_client(struct client *c) } else buffer_reverse_add(c->out, sizeof hdr); - server_draw_status(c); + server_redraw_status(c); } -/* Draw status line. */ void -server_draw_status(struct client *c) +server_redraw_session(struct session *s) { - struct hdr hdr; - size_t size; - - if (status_lines == 0) - return; - - buffer_ensure(c->out, sizeof hdr); - buffer_add(c->out, sizeof hdr); - size = BUFFER_USED(c->out); - - status_write(c); + struct client *c; + u_int i; - size = BUFFER_USED(c->out) - size; - hdr.type = MSG_DATA; - hdr.size = size; - memcpy(BUFFER_IN(c->out) - size - sizeof hdr, &hdr, sizeof hdr); + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session == s) + server_redraw_client(c); + } } -/* Send error message command to client. */ void -server_write_error(struct client *c, const char *fmt, ...) +server_redraw_window(struct window *w) { - va_list ap; - char *msg; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); + struct client *c; + u_int i; - server_write_client(c, MSG_ERROR, msg, strlen(msg)); - xfree(msg); + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session->window == w) + server_redraw_client(c); + } } -/* Write message command to a client. */ void server_write_message(struct client *c, const char *fmt, ...) { diff --git a/server-msg.c b/server-msg.c index 1a67e28a..3352970a 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.21 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: server-msg.c,v 1.22 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -123,7 +123,7 @@ server_msg_fn_command(struct hdr *hdr, struct client *c) else { ctx.session = server_find_sessid(&data.sid, &cause); if (ctx.session == NULL) { - server_write_error(c, "%s", cause); + server_msg_fn_command_error(&ctx, "%s", cause); xfree(cause); return (0); } @@ -212,7 +212,7 @@ server_msg_fn_keys(struct hdr *hdr, struct client *c) fatalx("bad MSG_KEYS size"); if (c->flags & CLIENT_HOLD) { - server_draw_client(c); + server_redraw_client(c); c->flags &= ~CLIENT_HOLD; } diff --git a/server.c b/server.c index ed5a68b4..c6684ec4 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.21 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: server.c,v 1.22 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -316,14 +316,12 @@ server_handle_window(struct window *w) struct client *c; struct session *s; struct buffer *b; - u_int i, j, p; + u_int i, j; b = buffer_create(BUFSIZ); window_data(w, b); - if (BUFFER_USED(b) != 0) { - server_write_clients( - w, MSG_DATA, BUFFER_OUT(b), BUFFER_USED(b)); - } + if (BUFFER_USED(b) != 0) + server_write_window(w, MSG_DATA, BUFFER_OUT(b), BUFFER_USED(b)); buffer_destroy(b); if (!(w->flags & WINDOW_BELL)) @@ -331,19 +329,13 @@ server_handle_window(struct window *w) for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { s = ARRAY_ITEM(&sessions, i); - if (s == NULL) - continue; - if (window_index(&s->windows, w, &p) != 0) + if (s == NULL || !session_has(s, w)) continue; for (j = 0; j < ARRAY_LENGTH(&clients); j++) { c = ARRAY_ITEM(&clients, j); if (c == NULL || c->session != s) continue; - /* - if (s->window != w) - server_write_message(c, "Bell in window %u", p); - */ server_write_client(c, MSG_DATA, "\007", 1); } } @@ -379,7 +371,7 @@ server_lost_window(struct window *w) c->session = NULL; server_write_client(c, MSG_EXIT, NULL, 0); } else - server_draw_client(c); + server_redraw_client(c); } } } diff --git a/tmux.h b/tmux.h index fc3762d1..cb6805ce 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.39 2007-10-03 23:32:26 nicm Exp $ */ +/* $Id: tmux.h,v 1.40 2007-10-04 00:02:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -458,9 +458,12 @@ struct client_ctx { /* Key/command line command. */ enum cmd_type { CMD_DETACHSESSION, + CMD_LASTWINDOW, CMD_LISTSESSIONS, CMD_NEWSESSION, CMD_NEWWINDOW, + CMD_NEXTWINDOW, + CMD_PREVIOUSWINDOW, }; struct cmd_ctx { @@ -523,9 +526,12 @@ void cmd_free(struct cmd *); void cmd_send_string(struct buffer *, const char *); char *cmd_recv_string(struct buffer *); extern const struct cmd_entry cmd_detach_session_entry; +extern const struct cmd_entry cmd_last_window_entry; extern const struct cmd_entry cmd_list_sessions_entry; extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_new_window_entry; +extern const struct cmd_entry cmd_next_window_entry; +extern const struct cmd_entry cmd_previous_window_entry; /* bind.c */ const struct bind *cmdx_lookup_bind(const char *); @@ -568,17 +574,17 @@ int server_msg_dispatch(struct client *); /* server-fn.c */ struct session *server_find_sessid(struct sessid *, char **); -void server_write_error(struct client *, const char *, ...); -void server_write_message(struct client *, const char *, ...); void server_write_client( struct client *, enum hdrtype, const void *, size_t); -void server_write_client2(struct client *, - enum hdrtype, const void *, size_t, const void *, size_t); -void server_write_clients( - struct window *, enum hdrtype, const void *, size_t); -void server_window_changed(struct client *); -void server_draw_client(struct client *); -void server_draw_status(struct client *); +void server_write_session( + struct session *, enum hdrtype, const void *, size_t); +void server_write_window( + struct window *, enum hdrtype, const void *, size_t); +void server_redraw_status(struct client *); +void server_redraw_client(struct client *); +void server_redraw_session(struct session *); +void server_redraw_window(struct window *); +void server_write_message(struct client *, const char *, ...); /* status.c */ void status_write(struct client *c); -- cgit v1.2.3