Merge branch 'obsd-master'

Conflicts:
	Makefile
	cmd-link-window.c
	cmd-unlink-window.c
This commit is contained in:
Thomas Adam 2014-10-29 12:50:05 +00:00
commit 35ffd093d7
21 changed files with 134 additions and 213 deletions

View File

@ -88,7 +88,6 @@ dist_tmux_SOURCES = \
cmd-kill-server.c \
cmd-kill-session.c \
cmd-kill-window.c \
cmd-link-window.c \
cmd-list-buffers.c \
cmd-list-clients.c \
cmd-list-keys.c \
@ -130,7 +129,6 @@ dist_tmux_SOURCES = \
cmd-swap-window.c \
cmd-switch-client.c \
cmd-unbind-key.c \
cmd-unlink-window.c \
cmd-wait-for.c \
cmd.c \
colour.c \

34
cfg.c
View File

@ -29,7 +29,7 @@
struct cmd_q *cfg_cmd_q;
int cfg_finished;
int cfg_references;
struct causelist cfg_causes;
ARRAY_DECL (, char *) cfg_causes = ARRAY_INITIALIZER;
struct client *cfg_client;
int
@ -39,7 +39,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
char delim[3] = { '\\', '\\', '\0' };
u_int found;
size_t line = 0;
char *buf, *cause1, *msg, *p;
char *buf, *cause1, *p;
struct cmd_list *cmdlist;
log_debug("loading %s", path);
@ -66,8 +66,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
free(buf);
if (cause1 == NULL)
continue;
xasprintf(&msg, "%s:%zu: %s", path, line, cause1);
ARRAY_ADD(&cfg_causes, msg);
cfg_add_cause("%s:%zu: %s", path, line, cause1);
free(cause1);
continue;
}
@ -112,6 +111,33 @@ cfg_default_done(unused struct cmd_q *cmdq)
}
}
void
cfg_add_cause(const char* fmt, ...)
{
va_list ap;
char* msg;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end (ap);
ARRAY_ADD(&cfg_causes, msg);
}
void
cfg_print_causes(struct cmd_q *cmdq)
{
char *cause;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
cmdq_print(cmdq, "%s", cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
void
cfg_show_causes(struct session *s)
{

View File

@ -162,7 +162,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
xasprintf(&searchstr, "*%s*", str);
RB_FOREACH(wm, winlinks, &s->windows)
cmd_find_window_match (&find_list, match_flags, wm, str, searchstr);
cmd_find_window_match(&find_list, match_flags, wm, str, searchstr);
free(searchstr);
if (ARRAY_LENGTH(&find_list) == 0) {

View File

@ -34,23 +34,48 @@ const struct cmd_entry cmd_kill_window_entry = {
cmd_kill_window_exec
};
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_kill_window_exec
};
enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl, *wl2, *wl3;
struct session *s;
struct args *args = self->args;
struct winlink *wl, *wl2, *wl3;
struct window *w;
struct session *s;
struct session_group *sg;
u_int references;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
if (args_has(args, 'a')) {
RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
if (wl != wl2)
server_kill_window(wl2->window);
if (self->entry == &cmd_unlink_window_entry) {
sg = session_group_find(s);
if (sg != NULL)
references = session_group_count(sg);
else
references = 1;
if (!args_has(self->args, 'k') && w->references == references) {
cmdq_error(cmdq, "window only linked to one session");
return (CMD_RETURN_ERROR);
}
} else
server_kill_window(wl->window);
server_unlink_window(s, wl);
} else {
if (args_has(args, 'a')) {
RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
if (wl != wl2)
server_kill_window(wl2->window);
}
} else
server_kill_window(wl->window);
}
recalculate_sizes();
return (CMD_RETURN_NORMAL);

View File

@ -1,63 +0,0 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
* Link a window into another session.
*/
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
cmd_link_window_exec
};
enum cmd_retval
cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *src, *dst;
struct winlink *wl;
char *cause;
int idx, kflag, dflag;
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
return (CMD_RETURN_ERROR);
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
return (CMD_RETURN_ERROR);
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
cmdq_error(cmdq, "can't link window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
recalculate_sizes();
return (CMD_RETURN_NORMAL);
}

View File

@ -36,6 +36,14 @@ const struct cmd_entry cmd_move_window_entry = {
cmd_move_window_exec
};
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
cmd_move_window_exec
};
enum cmd_retval
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
@ -46,7 +54,8 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
int idx, kflag, dflag;
if (args_has(args, 'r')) {
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
session_renumber_windows(s);
@ -62,12 +71,14 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
cmdq_error(cmdq, "can't move window: %s", cause);
if (server_link_window(src, wl, dst, idx, kflag, !dflag,
&cause) != 0) {
cmdq_error(cmdq, "can't link window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
server_unlink_window(src, wl);
if (self->entry == &cmd_move_window_entry)
server_unlink_window(src, wl);
recalculate_sizes();
return (CMD_RETURN_NORMAL);

View File

@ -93,17 +93,16 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
struct client *c = cmdq->client;
struct cmd *cmd = cmdq->cmd;
va_list ap;
char *msg, *cause;
char *msg;
size_t msglen;
va_start(ap, fmt);
msglen = xvasprintf(&msg, fmt, ap);
va_end(ap);
if (c == NULL) {
xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
ARRAY_ADD(&cfg_causes, cause);
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
if (c == NULL)
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
@ -180,8 +179,6 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
do {
next = TAILQ_NEXT(cmdq->item, qentry);
while (cmdq->cmd != NULL) {
cmd_print(cmdq->cmd, s, sizeof s);
log_debug("cmdq %p: %s (client %d)", cmdq, s,
@ -213,6 +210,7 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
}
next = TAILQ_NEXT(cmdq->item, qentry);
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
cmd_list_free(cmdq->item->cmdlist);

View File

@ -99,8 +99,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
wp->flags &= ~PANE_INPUTOFF;
else if (args_has(self->args, 'd'))
wp->flags |= PANE_INPUTOFF;
else {
window_set_active_pane(wl->window, wp);
else if (window_set_active_pane(wl->window, wp)) {
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
}

View File

@ -28,7 +28,6 @@
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
void cmd_source_file_show(struct cmd_q *);
void cmd_source_file_done(struct cmd_q *);
const struct cmd_entry cmd_source_file_entry = {
@ -59,11 +58,12 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
free(cause);
return (CMD_RETURN_ERROR);
}
ARRAY_ADD(&cfg_causes, cause);
cfg_add_cause("%s", cause);
free(cause);
/* FALLTHROUGH */
case 0:
if (cfg_references == 0)
cmd_source_file_show(cmdq);
cfg_print_causes(cmdq);
cmdq_free(cmdq1);
return (CMD_RETURN_NORMAL);
}
@ -75,20 +75,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_WAIT);
}
void
cmd_source_file_show(struct cmd_q *cmdq)
{
u_int i;
char *cause;
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
cmdq_print(cmdq, "%s", cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
void
cmd_source_file_done(struct cmd_q *cmdq1)
{
@ -105,6 +91,6 @@ cmd_source_file_done(struct cmd_q *cmdq1)
return;
if (cfg_references == 0)
cmd_source_file_show(cmdq);
cfg_print_causes(cmdq);
cmdq_continue(cmdq);
}

View File

@ -1,68 +0,0 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#include "tmux.h"
/*
* Unlink a window, unless it would be destroyed by doing so (only one link).
*/
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_unlink_window_exec
};
enum cmd_retval
cmd_unlink_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
struct window *w;
struct session *s, *s2;
struct session_group *sg;
u_int references;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
sg = session_group_find(s);
if (sg != NULL) {
references = 0;
TAILQ_FOREACH(s2, &sg->sessions, gentry)
references++;
} else
references = 1;
if (!args_has(self->args, 'k') && w->references == references) {
cmdq_error(cmdq, "window is only linked to one session");
return (CMD_RETURN_ERROR);
}
server_unlink_window(s, wl);
recalculate_sizes();
return (CMD_RETURN_NORMAL);
}

View File

@ -555,6 +555,7 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "pane_id", "%%%u", wp->id);
format_add(ft, "pane_active", "%d", wp == wp->window->active);
format_add(ft, "pane_dead", "%d", wp->fd == -1);
format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF));
if (window_pane_visible(wp)) {
format_add(ft, "pane_left", "%u", wp->xoff);

View File

@ -167,16 +167,16 @@ key_bindings_init(void)
RB_INIT(&key_bindings);
cmdq = cmdq_new (NULL);
cmdq = cmdq_new(NULL);
for (i = 0; i < nitems(defaults); i++) {
error = cmd_string_parse(defaults[i], &cmdlist,
"<default-keys>", i, &cause);
if (error != 0)
fatalx("bad default key");
cmdq_run (cmdq, cmdlist);
cmd_list_free (cmdlist);
cmdq_run(cmdq, cmdlist);
cmd_list_free(cmdlist);
}
cmdq_free (cmdq);
cmdq_free(cmdq);
}
void

View File

@ -159,7 +159,7 @@ server_client_lost(struct client *c)
evbuffer_free(c->stdin_data);
evbuffer_free(c->stdout_data);
if (c->stderr_data != c->stdout_data)
evbuffer_free (c->stderr_data);
evbuffer_free(c->stderr_data);
status_free_jobs(&c->status_new);
status_free_jobs(&c->status_old);
@ -647,7 +647,7 @@ server_client_reset_state(struct client *c)
if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status)
tty_cursor(&c->tty, 0, 0);
else {
o = status && options_get_number (oo, "status-position") == 0;
o = status && options_get_number(oo, "status-position") == 0;
tty_cursor(&c->tty, wp->xoff + s->cx, o + wp->yoff + s->cy);
}

View File

@ -166,25 +166,18 @@ server_start(int lockfd, char *lockfile)
cfg_cmd_q->emptyfn = cfg_default_done;
cfg_finished = 0;
cfg_references = 1;
ARRAY_INIT(&cfg_causes);
cfg_client = ARRAY_FIRST(&clients);
if (cfg_client != NULL)
cfg_client->references++;
if (access(TMUX_CONF, R_OK) == 0) {
if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) {
xasprintf(&cause, "%s: %s", TMUX_CONF, cause);
ARRAY_ADD(&cfg_causes, cause);
}
} else if (errno != ENOENT) {
xasprintf(&cause, "%s: %s", TMUX_CONF, strerror(errno));
ARRAY_ADD(&cfg_causes, cause);
}
if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
cfg_add_cause("%s: %s", TMUX_CONF, cause);
} else if (errno != ENOENT)
cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
if (cfg_file != NULL) {
if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) {
xasprintf(&cause, "%s: %s", cfg_file, cause);
ARRAY_ADD(&cfg_causes, cause);
}
if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
cfg_add_cause("%s: %s", cfg_file, cause);
}
cmdq_continue(cfg_cmd_q);

View File

@ -126,7 +126,7 @@ session_create(const char *name, int argc, char **argv, const char *path,
s->name = NULL;
do {
s->id = next_session_id++;
free (s->name);
free(s->name);
xasprintf(&s->name, "%u", s->id);
} while (RB_FIND(sessions, &sessions, s) != NULL);
}
@ -491,6 +491,19 @@ session_group_remove(struct session *s)
}
}
/* Count number of sessions in session group. */
u_int
session_group_count(struct session_group *sg)
{
struct session *s;
u_int n;
n = 0;
TAILQ_FOREACH(s, &sg->sessions, gentry)
n++;
return (n);
}
/* Synchronize a session to its session group. */
void
session_group_synchronize_to(struct session *s)
@ -578,8 +591,9 @@ session_group_synchronize1(struct session *target, struct session *s)
/* Then free the old winlinks list. */
while (!RB_EMPTY(&old_windows)) {
wl = RB_ROOT(&old_windows);
if (winlink_find_by_window_id(&s->windows, wl->window->id) == NULL)
notify_window_unlinked(s, wl->window);
wl2 = winlink_find_by_window_id(&s->windows, wl->window->id);
if (wl2 == NULL)
notify_window_unlinked(s, wl->window);
winlink_remove(&old_windows, wl);
}
}

1
tmux.1
View File

@ -3104,6 +3104,7 @@ The following variables are available, where appropriate:
.It Li "pane_height" Ta "" Ta "Height of pane"
.It Li "pane_id" Ta "#D" Ta "Unique pane ID"
.It Li "pane_in_mode" Ta "" Ta "If pane is in a mode"
.It Li "pane_input_off" Ta "" Ta "If input to pane is disabled"
.It Li "pane_index" Ta "#P" Ta "Index of pane"
.It Li "pane_left" Ta "" Ta "Left of pane"
.It Li "pane_pid" Ta "" Ta "PID of first process in pane"

9
tmux.h
View File

@ -379,9 +379,6 @@ struct tty_term_code_entry {
const char *name;
};
/* List of error causes. */
ARRAY_DECL(causelist, char *);
/* Message codes. */
enum msgtype {
MSG_VERSION = 12,
@ -1498,10 +1495,11 @@ __dead void shell_exec(const char *, const char *);
extern struct cmd_q *cfg_cmd_q;
extern int cfg_finished;
extern int cfg_references;
extern struct causelist cfg_causes;
extern struct client *cfg_client;
int load_cfg(const char *, struct cmd_q *, char **);
void cfg_default_done(struct cmd_q *);
void cfg_add_cause(const char *, ...);
void cfg_print_causes(struct cmd_q *);
void cfg_show_causes(struct session *);
/* format.c */
@ -2114,7 +2112,7 @@ void window_destroy(struct window *);
struct window_pane *window_get_active_at(struct window *, u_int, u_int);
void window_set_active_at(struct window *, u_int, u_int);
struct window_pane *window_find_string(struct window *, const char *);
void window_set_active_pane(struct window *, struct window_pane *);
int window_set_active_pane(struct window *, struct window_pane *);
struct window_pane *window_add_pane(struct window *, u_int);
void window_resize(struct window *, u_int, u_int);
int window_zoom(struct window_pane *);
@ -2294,6 +2292,7 @@ struct session_group *session_group_find(struct session *);
u_int session_group_index(struct session_group *);
void session_group_add(struct session *, struct session *);
void session_group_remove(struct session *);
u_int session_group_count(struct session_group *);
void session_group_synchronize_to(struct session *);
void session_group_synchronize_from(struct session *);
void session_group_synchronize1(struct session *, struct session *);

View File

@ -382,7 +382,7 @@ tty_keys_build(struct tty *tty)
const char *s;
if (tty->key_tree != NULL)
tty_keys_free (tty);
tty_keys_free(tty);
tty->key_tree = NULL;
for (i = 0; i < nitems(tty_default_raw_keys); i++) {

View File

@ -98,7 +98,7 @@ window_choose_add(struct window_pane *wp, struct window_choose_data *wcd)
item->pos = ARRAY_LENGTH(&data->list) - 1;
item->state = 0;
data->width = xsnprintf (tmp, sizeof tmp , "%u", item->pos);
data->width = xsnprintf(tmp, sizeof tmp , "%u", item->pos);
}
void
@ -787,9 +787,9 @@ window_choose_write_line(
key = window_choose_key_index(data, data->top + py);
if (key != -1)
xsnprintf (label, sizeof label, "(%c)", key);
xsnprintf(label, sizeof label, "(%c)", key);
else
xsnprintf (label, sizeof label, "(%d)", item->pos);
xsnprintf(label, sizeof label, "(%d)", item->pos);
screen_write_nputs(ctx, screen_size_x(s) - 1, &gc, utf8flag,
"%*s %s %s", data->width + 2, label,
/*

View File

@ -1585,7 +1585,7 @@ window_copy_copy_line(struct window_pane *wp,
s = tty_acs_get(NULL, ud.data[0]);
if (s != NULL && strlen(s) <= sizeof ud.data) {
ud.size = strlen(s);
memcpy (ud.data, s, ud.size);
memcpy(ud.data, s, ud.size);
}
}

View File

@ -385,11 +385,11 @@ window_resize(struct window *w, u_int sx, u_int sy)
w->sy = sy;
}
void
int
window_set_active_pane(struct window *w, struct window_pane *wp)
{
if (wp == w->active)
return;
return (0);
w->last = w->active;
w->active = wp;
while (!window_pane_visible(w->active)) {
@ -397,9 +397,10 @@ window_set_active_pane(struct window *w, struct window_pane *wp)
if (w->active == NULL)
w->active = TAILQ_LAST(&w->panes, window_panes);
if (w->active == wp)
return;
return (1);
}
w->active->active_point = next_active_point++;
return (1);
}
struct window_pane *