示例#1
0
void
window_name_callback(unused int fd, unused short events, void *data)
{
	struct window	*w = data;
	char		*name, *wname;

	if (w->active == NULL)
		return;

	if (!options_get_number(&w->options, "automatic-rename")) {
		if (event_initialized(&w->name_timer))
			event_del(&w->name_timer);
		return;
	}
	queue_window_name(w);

	if (w->active->screen != &w->active->base)
		name = NULL;
	else
		name = osdep_get_name(w->active->fd, w->active->tty);
	if (name == NULL)
		wname = default_window_name(w);
	else {
		/*
		 * If tmux is using the default command, it will be a login
		 * shell and argv[0] may have a - prefix. Remove this if it is
		 * present. Ick.
		 */
		if (w->active->cmd != NULL && *w->active->cmd == '\0' &&
		    name != NULL && name[0] == '-' && name[1] != '\0')
			wname = parse_window_name(name + 1);
		else
			wname = parse_window_name(name);
		free(name);
	}

	if (w->active->fd == -1) {
		xasprintf(&name, "%s[dead]", wname);
		free(wname);
		wname = name;
	}

	if (strcmp(wname, w->name)) {
		window_set_name(w, wname);
		server_status_window(w);
	}
	free(wname);
}
示例#2
0
enum cmd_retval
cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args				*args = self->args;
	const struct options_table_entry	*table, *oe;
	struct session				*s;
	struct winlink				*wl;
	struct client				*c;
	struct options				*oo;
	struct window				*w;
	const char				*optstr, *valstr;
	u_int					 i;

	/* Get the option name and value. */
	optstr = args->argv[0];
	if (*optstr == '\0') {
		cmdq_error(cmdq, "invalid option");
		return (CMD_RETURN_ERROR);
	}
	if (args->argc < 2)
		valstr = NULL;
	else
		valstr = args->argv[1];

	/* Is this a user option? */
	if (*optstr == '@')
		return (cmd_set_option_user(self, cmdq, optstr, valstr));

	/* Find the option entry, try each table. */
	table = oe = NULL;
	if (options_table_find(optstr, &table, &oe) != 0) {
		cmdq_error(cmdq, "ambiguous option: %s", optstr);
		return (CMD_RETURN_ERROR);
	}
	if (oe == NULL) {
		cmdq_error(cmdq, "unknown option: %s", optstr);
		return (CMD_RETURN_ERROR);
	}

	/* Work out the tree from the table. */
	if (table == server_options_table)
		oo = &global_options;
	else if (table == window_options_table) {
		if (args_has(self->args, 'g'))
			oo = &global_w_options;
		else {
			wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
			if (wl == NULL) {
				cmdq_error(cmdq,
				    "couldn't set '%s'%s", optstr,
				    (!args_has(args, 't') && !args_has(args,
				    'g')) ? " need target window or -g" : "");
				return (CMD_RETURN_ERROR);
			}
			oo = &wl->window->options;
		}
	} else if (table == session_options_table) {
		if (args_has(self->args, 'g'))
			oo = &global_s_options;
		else {
			s = cmd_find_session(cmdq, args_get(args, 't'), 0);
			if (s == NULL) {
				cmdq_error(cmdq,
				    "couldn't set '%s'%s", optstr,
				    (!args_has(args, 't') && !args_has(args,
				    'g')) ? " need target session or -g" : "");
				return (CMD_RETURN_ERROR);
			}
			oo = &s->options;
		}
	} else {
		cmdq_error(cmdq, "unknown table");
		return (CMD_RETURN_ERROR);
	}

	/* Unset or set the option. */
	if (args_has(args, 'u')) {
		if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0)
			return (CMD_RETURN_ERROR);
	} else {
		if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
			if (!args_has(args, 'q'))
				cmdq_print(cmdq, "already set: %s", optstr);
			return (CMD_RETURN_NORMAL);
		}
		if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
			return (CMD_RETURN_ERROR);
	}

	/* Start or stop timers when automatic-rename changed. */
	if (strcmp(oe->name, "automatic-rename") == 0) {
		for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
			if ((w = ARRAY_ITEM(&windows, i)) == NULL)
				continue;
			if (options_get_number(&w->options, "automatic-rename"))
				queue_window_name(w);
			else if (event_initialized(&w->name_timer))
				evtimer_del(&w->name_timer);
		}
	}

	/* Update sizes and redraw. May not need it but meh. */
	recalculate_sizes();
	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (c != NULL && c->session != NULL)
			server_redraw_client(c);
	}

	return (CMD_RETURN_NORMAL);
}