1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code

This commit is contained in:
Nicholas Marriott 2013-02-23 13:03:47 +00:00
commit 57eb334d5b
20 changed files with 63 additions and 31 deletions

View File

@ -26,13 +26,15 @@ endif
if IS_GCC if IS_GCC
CFLAGS += -std=c99 CFLAGS += -std=c99
if IS_DEBUG if IS_DEBUG
CFLAGS += -g -ggdb -O0 CFLAGS += -O0 -g
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2 CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
CFLAGS += -Wdeclaration-after-statement CFLAGS += -Wdeclaration-after-statement
CPPFLAGS += -DDEBUG CPPFLAGS += -DDEBUG
else
CFLAGS += -O2
endif endif
if IS_GCC4 if IS_GCC4
CPPFLAGS += -iquote. -I/usr/local/include CPPFLAGS += -iquote. -I/usr/local/include

View File

@ -97,7 +97,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
template = BREAK_PANE_TEMPLATE; template = BREAK_PANE_TEMPLATE;
ft = format_create(); ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL) if ((c = cmd_find_client(ctx, NULL, 1)) != NULL)
format_client(ft, c); format_client(ft, c);
format_session(ft, s); format_session(ft, s);
format_winlink(ft, s, wl); format_winlink(ft, s, wl);

View File

@ -94,7 +94,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
char *prompt, *ptr, *input = NULL; char *prompt, *ptr, *input = NULL;
size_t n; size_t n;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if (c->prompt_string != NULL) if (c->prompt_string != NULL)

View File

@ -79,7 +79,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if ((prompt = args_get(args, 'p')) != NULL) if ((prompt = args_get(args, 'p')) != NULL)

View File

@ -61,7 +61,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(c, msgtype, NULL, 0); server_write_client(c, msgtype, NULL, 0);
} }
} else { } else {
c = cmd_find_client(ctx, args_get(args, 't')); c = cmd_find_client(ctx, args_get(args, 't'), 0);
if (c == NULL) if (c == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@ -55,9 +55,6 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
time_t t; time_t t;
size_t len; size_t len;
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 't')) { if (args_has(args, 't')) {
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
if (wl == NULL) if (wl == NULL)
@ -80,7 +77,8 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
template = DISPLAY_MESSAGE_TEMPLATE; template = DISPLAY_MESSAGE_TEMPLATE;
ft = format_create(); ft = format_create();
format_client(ft, c); if ((c = cmd_find_client(ctx, args_get(args, 'c'), 1)) != NULL)
format_client(ft, c);
format_session(ft, s); format_session(ft, s);
format_winlink(ft, s, wl); format_winlink(ft, s, wl);
format_window_pane(ft, wp); format_window_pane(ft, wp);

View File

@ -42,7 +42,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args; struct args *args = self->args;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
server_set_identify(c); server_set_identify(c);

View File

@ -74,7 +74,7 @@ cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
server_lock_session(s); server_lock_session(s);
} else { } else {
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
server_lock_client(c); server_lock_client(c);
} }

View File

@ -126,7 +126,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
template = NEW_WINDOW_TEMPLATE; template = NEW_WINDOW_TEMPLATE;
ft = format_create(); ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL) if ((c = cmd_find_client(ctx, NULL, 1)) != NULL)
format_client(ft, c); format_client(ft, c);
format_session(ft, s); format_session(ft, s);
format_winlink(ft, s, wl); format_winlink(ft, s, wl);

View File

@ -56,7 +56,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
c = cmd_find_client(ctx, NULL); c = cmd_find_client(ctx, NULL, 1);
/* Destroy the old pipe. */ /* Destroy the old pipe. */
old_fd = wp->pipe_fd; old_fd = wp->pipe_fd;

View File

@ -44,7 +44,7 @@ cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *size; const char *size;
u_int w, h; u_int w, h;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if (args_has(args, 'C')) { if (args_has(args, 'C')) {

View File

@ -48,7 +48,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
char *tim; char *tim;
u_int i; u_int i;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {

View File

@ -151,7 +151,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
template = SPLIT_WINDOW_TEMPLATE; template = SPLIT_WINDOW_TEMPLATE;
ft = format_create(); ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL) if ((c = cmd_find_client(ctx, NULL, 1)) != NULL)
format_client(ft, c); format_client(ft, c);
format_session(ft, s); format_session(ft, s);
format_winlink(ft, s, wl); format_winlink(ft, s, wl);

View File

@ -45,7 +45,7 @@ cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args; struct args *args = self->args;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
tty_stop_tty(&c->tty); tty_stop_tty(&c->tty);

View File

@ -64,7 +64,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
struct client *c; struct client *c;
struct session *s; struct session *s;
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 'c'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if (args_has(args, 'r')) { if (args_has(args, 'r')) {

12
cmd.c
View File

@ -516,15 +516,19 @@ cmd_choose_client(struct clients *cc)
/* Find the target client or report an error and return NULL. */ /* Find the target client or report an error and return NULL. */
struct client * struct client *
cmd_find_client(struct cmd_ctx *ctx, const char *arg) cmd_find_client(struct cmd_ctx *ctx, const char *arg, int quiet)
{ {
struct client *c; struct client *c;
char *tmparg; char *tmparg;
size_t arglen; size_t arglen;
/* A NULL argument means the current client. */ /* A NULL argument means the current client. */
if (arg == NULL) if (arg == NULL) {
return (cmd_current_client(ctx)); c = cmd_current_client(ctx);
if (c == NULL && !quiet)
ctx->error(ctx, "no clients");
return (c);
}
tmparg = xstrdup(arg); tmparg = xstrdup(arg);
/* Trim a single trailing colon if any. */ /* Trim a single trailing colon if any. */
@ -536,7 +540,7 @@ cmd_find_client(struct cmd_ctx *ctx, const char *arg)
c = cmd_lookup_client(tmparg); c = cmd_lookup_client(tmparg);
/* If no client found, report an error. */ /* If no client found, report an error. */
if (c == NULL) if (c == NULL && !quiet)
ctx->error(ctx, "client not found: %s", tmparg); ctx->error(ctx, "client not found: %s", tmparg);
free(tmparg); free(tmparg);

View File

@ -17,6 +17,7 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h>
#include <event.h> #include <event.h>
#include <fcntl.h> #include <fcntl.h>
@ -95,6 +96,8 @@ server_client_create(int fd)
c->tty.mouse.event = MOUSE_EVENT_UP; c->tty.mouse.event = MOUSE_EVENT_UP;
c->tty.mouse.flags = 0; c->tty.mouse.flags = 0;
c->flags |= CLIENT_FOCUSED;
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c); evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
@ -545,7 +548,8 @@ server_client_check_resize(struct window_pane *wp)
void void
server_client_check_focus(struct window_pane *wp) server_client_check_focus(struct window_pane *wp)
{ {
struct session *s; u_int i;
struct client *c;
/* If we don't care about focus, forget it. */ /* If we don't care about focus, forget it. */
if (!(wp->base.mode & MODE_FOCUSON)) if (!(wp->base.mode & MODE_FOCUSON))
@ -560,13 +564,20 @@ server_client_check_focus(struct window_pane *wp)
goto not_focused; goto not_focused;
/* /*
* If our window is the current window in any attached sessions, we're * If our window is the current window in any focused clients with an
* focused. * attached session, we're focused.
*/ */
RB_FOREACH(s, sessions, &sessions) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
if (s->flags & SESSION_UNATTACHED) c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue; continue;
if (s->curw->window == wp->window)
if (!(c->flags & CLIENT_FOCUSED))
continue;
if (c->session->flags & SESSION_UNATTACHED)
continue;
if (c->session->curw->window == wp->window)
goto focused; goto focused;
} }

6
tmux.h
View File

@ -237,6 +237,9 @@ enum key_code {
KEYC_KP_ENTER, KEYC_KP_ENTER,
KEYC_KP_ZERO, KEYC_KP_ZERO,
KEYC_KP_PERIOD, KEYC_KP_PERIOD,
KEYC_FOCUS_IN,
KEYC_FOCUS_OUT,
}; };
/* Termcap codes. */ /* Termcap codes. */
@ -1316,6 +1319,7 @@ struct client {
#define CLIENT_READONLY 0x800 #define CLIENT_READONLY 0x800
#define CLIENT_REDRAWWINDOW 0x1000 #define CLIENT_REDRAWWINDOW 0x1000
#define CLIENT_CONTROL 0x2000 #define CLIENT_CONTROL 0x2000
#define CLIENT_FOCUSED 0x4000
int flags; int flags;
struct event identify_timer; struct event identify_timer;
@ -1728,7 +1732,7 @@ struct cmd *cmd_parse(int, char **, char **);
size_t cmd_print(struct cmd *, char *, size_t); size_t cmd_print(struct cmd *, char *, size_t);
struct session *cmd_current_session(struct cmd_ctx *, int); struct session *cmd_current_session(struct cmd_ctx *, int);
struct client *cmd_current_client(struct cmd_ctx *); struct client *cmd_current_client(struct cmd_ctx *);
struct client *cmd_find_client(struct cmd_ctx *, const char *); struct client *cmd_find_client(struct cmd_ctx *, const char *, int);
struct session *cmd_find_session(struct cmd_ctx *, const char *, int); struct session *cmd_find_session(struct cmd_ctx *, const char *, int);
struct winlink *cmd_find_window( struct winlink *cmd_find_window(
struct cmd_ctx *, const char *, struct session **); struct cmd_ctx *, const char *, struct session **);

View File

@ -174,6 +174,10 @@ const struct tty_default_key_raw tty_default_raw_keys[] = {
{ "\033[8@", KEYC_END|KEYC_CTRL|KEYC_SHIFT }, { "\033[8@", KEYC_END|KEYC_CTRL|KEYC_SHIFT },
{ "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT }, { "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT },
{ "\033[5@", KEYC_PPAGE|KEYC_CTRL|KEYC_SHIFT }, { "\033[5@", KEYC_PPAGE|KEYC_CTRL|KEYC_SHIFT },
/* Focus tracking. */
{ "\033[I", KEYC_FOCUS_IN },
{ "\033[O", KEYC_FOCUS_OUT },
}; };
/* Default terminfo(5) keys. */ /* Default terminfo(5) keys. */
@ -559,6 +563,15 @@ complete_key:
evtimer_del(&tty->key_timer); evtimer_del(&tty->key_timer);
tty->flags &= ~TTY_TIMER; tty->flags &= ~TTY_TIMER;
/* Check for focus events. */
if (key == KEYC_FOCUS_OUT) {
tty->client->flags &= ~CLIENT_FOCUSED;
return (1);
} else if (key == KEYC_FOCUS_IN) {
tty->client->flags |= CLIENT_FOCUSED;
return (1);
}
/* Fire the key. */ /* Fire the key. */
if (key != KEYC_NONE) if (key != KEYC_NONE)
server_client_handle_key(tty->client, key); server_client_handle_key(tty->client, key);

4
tty.c
View File

@ -221,7 +221,7 @@ tty_start_tty(struct tty *tty)
tty_puts(tty, "\033[?1000l\033[?1006l\033[?1005l"); tty_puts(tty, "\033[?1000l\033[?1006l\033[?1005l");
if (tty_term_has(tty->term, TTYC_XT)) if (tty_term_has(tty->term, TTYC_XT))
tty_puts(tty, "\033[c\033[>4;1m\033[?1004l"); tty_puts(tty, "\033[c\033[>4;1m\033[?1004h");
tty->cx = UINT_MAX; tty->cx = UINT_MAX;
tty->cy = UINT_MAX; tty->cy = UINT_MAX;
@ -284,7 +284,7 @@ tty_stop_tty(struct tty *tty)
tty_raw(tty, "\033[?1000l\033[?1006l\033[?1005l"); tty_raw(tty, "\033[?1000l\033[?1006l\033[?1005l");
if (tty_term_has(tty->term, TTYC_XT)) if (tty_term_has(tty->term, TTYC_XT))
tty_raw(tty, "\033[>4m"); tty_raw(tty, "\033[>4m\033[?1004l");
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP)); tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));