Merge branch 'obsd-master'

Conflicts:
	cmd-find.c
This commit is contained in:
Thomas Adam 2015-10-25 09:21:37 +00:00
commit 4acc8d0ff5
12 changed files with 78 additions and 19 deletions

View File

@ -50,6 +50,7 @@ struct cmd_find_state {
int idx;
};
struct session *cmd_find_try_TMUX(struct client *, struct window *);
int cmd_find_client_better(struct client *, struct client *);
struct client *cmd_find_best_client(struct client **, u_int);
int cmd_find_session_better(struct session *, struct session *,
@ -108,6 +109,33 @@ const char *cmd_find_pane_table[][2] = {
{ NULL, NULL }
};
/* Get session from TMUX if present. */
struct session *
cmd_find_try_TMUX(struct client *c, struct window *w)
{
struct environ_entry *envent;
char tmp[256];
long long pid;
u_int session;
struct session *s;
envent = environ_find(&c->environ, "TMUX");
if (envent == NULL)
return (NULL);
if (sscanf(envent->value, "%255[^,],%lld,%d", tmp, &pid, &session) != 3)
return (NULL);
if (pid != getpid())
return (NULL);
log_debug("client %d TMUX is %s (session @%u)", c->ibuf.fd,
envent->value, session);
s = session_find_by_id(session);
if (s == NULL || (w != NULL && !session_has(s, w)))
return (NULL);
return (s);
}
/* Is this client better? */
int
cmd_find_client_better(struct client *c, struct client *than)
@ -191,6 +219,12 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs)
u_int ssize;
struct session *s;
if (fs->cmdq->client != NULL) {
fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w);
if (fs->s != NULL)
return (cmd_find_best_winlink_with_window(fs));
}
ssize = 0;
RB_FOREACH(s, sessions, &sessions) {
if (!session_has(s, fs->w))
@ -276,7 +310,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
return (0);
unknown_pane:
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL);
if (fs->s == NULL)
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
if (fs->s == NULL)
return (-1);
fs->wl = fs->s->curw;

View File

@ -133,7 +133,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
} else
free(cp);
cwd = fd;
} else if (c != NULL && c->session == NULL)

View File

@ -107,7 +107,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
} else
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)

View File

@ -100,7 +100,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
} else
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)

View File

@ -1022,7 +1022,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
{
struct grid *gd = wp->base.grid;
u_int idx;
int status;
int status, scroll_position;
if (ft->w == NULL)
ft->w = wp->window;
@ -1070,6 +1070,10 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
scroll_position = window_copy_scroll_position(wp);
if (scroll_position != -1)
format_add(ft, "scroll_position", "%d", scroll_position);
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);
format_add(ft, "alternate_saved_y", "%u", wp->saved_cy);

View File

@ -597,7 +597,7 @@ server_client_handle_key(struct client *c, int key)
m->valid = 0;
/* Treat everything as a regular key when pasting is detected. */
if (server_client_assume_paste(s)) {
if (!KEYC_IS_MOUSE(key) && server_client_assume_paste(s)) {
if (!(c->flags & CLIENT_READONLY))
window_pane_key(wp, c, s, key, m);
return;

View File

@ -177,6 +177,10 @@ server_start(struct event_base *base, int lockfd, char *lockfile)
}
close(pair[0]);
if (pledge("stdio rpath wpath cpath fattr unix recvfd proc exec tty "
"ps", NULL) != 0)
fatal("pledge failed");
/*
* Must daemonise before loading configuration as the PID changes so
* $TMUX would be wrong for sessions created in the config file.

1
tmux.1
View File

@ -3411,6 +3411,7 @@ The following variables are available, where appropriate:
.It Li "pid" Ta "" Ta "Server PID"
.It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane"
.It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane"
.It Li "scroll_position" Ta "" Ta "Scroll position in copy mode"
.It Li "session_alerts" Ta "" Ta "List of window indexes with alerts"
.It Li "session_attached" Ta "" Ta "Number of clients session is attached to"
.It Li "session_activity" Ta "" Ta "Integer time of session last activity"

5
tmux.c
View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <event.h>
#include <fcntl.h>
@ -260,6 +261,10 @@ main(int argc, char **argv)
if (shell_cmd != NULL && argc != 0)
usage();
if (pledge("stdio rpath wpath cpath flock fattr unix sendfd recvfd "
"proc exec tty ps", NULL) != 0)
err(1, "pledge");
if (!(flags & CLIENT_UTF8)) {
/*
* If the user has set whichever of LC_ALL, LC_CTYPE or LANG

1
tmux.h
View File

@ -2083,6 +2083,7 @@ void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
void window_copy_vadd(struct window_pane *, const char *, va_list);
void window_copy_pageup(struct window_pane *);
void window_copy_start_drag(struct client *, struct mouse_event *);
int window_copy_scroll_position(struct window_pane *);
/* window-choose.c */
extern const struct window_mode window_choose_mode;

24
tty.c
View File

@ -228,7 +228,7 @@ tty_start_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_KMOUS))
tty_puts(tty, "\033[?1000l\033[?1002l\033[?1006l\033[?1005l");
if (tty_term_has(tty->term, TTYC_XT)) {
if (tty_term_flag(tty->term, TTYC_XT)) {
if (options_get_number(&global_options, "focus-events")) {
tty->flags |= TTY_FOCUS;
tty_puts(tty, "\033[?1004h");
@ -293,7 +293,7 @@ tty_stop_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_KMOUS))
tty_raw(tty, "\033[?1000l\033[?1002l\033[?1006l\033[?1005l");
if (tty_term_has(tty->term, TTYC_XT)) {
if (tty_term_flag(tty->term, TTYC_XT)) {
if (tty->flags & TTY_FOCUS) {
tty->flags &= ~TTY_FOCUS;
tty_raw(tty, "\033[?1004l");
@ -338,10 +338,8 @@ tty_free(struct tty *tty)
tty_close(tty);
free(tty->ccolour);
if (tty->path != NULL)
free(tty->path);
if (tty->termname != NULL)
free(tty->termname);
free(tty->path);
free(tty->termname);
}
void
@ -1647,6 +1645,13 @@ tty_try_256(struct tty *tty, u_char colour, const char *type)
{
char s[32];
/*
* If the user has specified -2 to the client, setaf and setab may not
* work (or they may not want to use them), so send the usual sequence.
*/
if (tty->term_flags & TERM_256COLOURS)
goto fallback;
/*
* If the terminfo entry has 256 colours and setaf and setab exist,
* assume that they work correctly.
@ -1664,13 +1669,6 @@ tty_try_256(struct tty *tty, u_char colour, const char *type)
return (0);
}
/*
* If the user has specified -2 to the client, setaf and setab may not
* work, so send the usual sequence.
*/
if (tty->term_flags & TERM_256COLOURS)
goto fallback;
return (-1);
fallback:

View File

@ -2219,6 +2219,16 @@ window_copy_scroll_down(struct window_pane *wp, u_int ny)
screen_write_stop(&ctx);
}
int
window_copy_scroll_position(struct window_pane *wp)
{
struct window_copy_mode_data *data = wp->modedata;
if (wp->mode != &window_copy_mode)
return (-1);
return (data->oy);
}
void
window_copy_rectangle_toggle(struct window_pane *wp)
{