mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Some tidying and tweaks to options code.
This commit is contained in:
parent
5526627558
commit
458b6eb600
@ -117,7 +117,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (*optstr == '@')
|
if (*optstr == '@')
|
||||||
return (cmd_set_option_user(self, item, optstr, valstr));
|
return (cmd_set_option_user(self, item, optstr, valstr));
|
||||||
|
|
||||||
/* Find the option entry, try each table. */
|
/* Find the option entry. */
|
||||||
oe = NULL;
|
oe = NULL;
|
||||||
if (options_table_find(optstr, &oe) != 0) {
|
if (options_table_find(optstr, &oe) != 0) {
|
||||||
if (!args_has(args, 'q')) {
|
if (!args_has(args, 'q')) {
|
||||||
@ -184,7 +184,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start or stop timers if necessary. */
|
/* Update timers and so on for various options. */
|
||||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||||
RB_FOREACH(w, windows, &windows) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
if (w->active == NULL)
|
if (w->active == NULL)
|
||||||
@ -207,8 +207,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
RB_FOREACH(w, windows, &windows)
|
RB_FOREACH(w, windows, &windows)
|
||||||
w->flags |= WINDOW_STYLECHANGED;
|
w->flags |= WINDOW_STYLECHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When the pane-border-status option has been changed, resize panes. */
|
|
||||||
if (strcmp(oe->name, "pane-border-status") == 0) {
|
if (strcmp(oe->name, "pane-border-status") == 0) {
|
||||||
RB_FOREACH(w, windows, &windows)
|
RB_FOREACH(w, windows, &windows)
|
||||||
layout_fix_panes(w, w->sx, w->sy);
|
layout_fix_panes(w, w->sx, w->sy);
|
||||||
|
2
notify.c
2
notify.c
@ -77,6 +77,8 @@ notify_callback(struct cmdq_item *item, void *data)
|
|||||||
{
|
{
|
||||||
struct notify_entry *ne = data;
|
struct notify_entry *ne = data;
|
||||||
|
|
||||||
|
log_debug("%s: %s", __func__, ne->name);
|
||||||
|
|
||||||
if (strcmp(ne->name, "window-layout-changed") == 0)
|
if (strcmp(ne->name, "window-layout-changed") == 0)
|
||||||
control_notify_window_layout_changed(ne->window);
|
control_notify_window_layout_changed(ne->window);
|
||||||
if (strcmp(ne->name, "window-unlinked") == 0)
|
if (strcmp(ne->name, "window-unlinked") == 0)
|
||||||
|
@ -947,8 +947,8 @@ options_table_print_entry(const struct options_table_entry *oe,
|
|||||||
xsnprintf(out, sizeof out, "%lld", o->num);
|
xsnprintf(out, sizeof out, "%lld", o->num);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_KEY:
|
case OPTIONS_TABLE_KEY:
|
||||||
xsnprintf(out, sizeof out, "%s",
|
s = key_string_lookup_key(o->num);
|
||||||
key_string_lookup_key(o->num));
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_COLOUR:
|
case OPTIONS_TABLE_COLOUR:
|
||||||
s = colour_tostring(o->num);
|
s = colour_tostring(o->num);
|
||||||
|
58
options.c
58
options.c
@ -37,8 +37,6 @@ struct options {
|
|||||||
static int options_cmp(struct options_entry *, struct options_entry *);
|
static int options_cmp(struct options_entry *, struct options_entry *);
|
||||||
RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp);
|
RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp);
|
||||||
|
|
||||||
static void options_free1(struct options *, struct options_entry *);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
options_cmp(struct options_entry *o1, struct options_entry *o2)
|
options_cmp(struct options_entry *o1, struct options_entry *o2)
|
||||||
{
|
{
|
||||||
@ -66,6 +64,28 @@ options_free1(struct options *oo, struct options_entry *o)
|
|||||||
free(o);
|
free(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct options_entry *
|
||||||
|
options_new(struct options *oo, const char *name, char **s)
|
||||||
|
{
|
||||||
|
struct options_entry *o;
|
||||||
|
|
||||||
|
if (s != NULL)
|
||||||
|
*s = NULL;
|
||||||
|
|
||||||
|
if ((o = options_find1(oo, name)) == NULL) {
|
||||||
|
o = xmalloc(sizeof *o);
|
||||||
|
o->name = xstrdup(name);
|
||||||
|
RB_INSERT(options_tree, &oo->tree, o);
|
||||||
|
memcpy(&o->style, &grid_default_cell, sizeof o->style);
|
||||||
|
} else if (o->type == OPTIONS_STRING) {
|
||||||
|
if (s != NULL)
|
||||||
|
*s = o->str;
|
||||||
|
else
|
||||||
|
free(o->str);
|
||||||
|
}
|
||||||
|
return (o);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
options_free(struct options *oo)
|
options_free(struct options *oo)
|
||||||
{
|
{
|
||||||
@ -129,21 +149,14 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
s = NULL;
|
|
||||||
if ((o = options_find1(oo, name)) == NULL) {
|
|
||||||
o = xmalloc(sizeof *o);
|
|
||||||
o->name = xstrdup(name);
|
|
||||||
RB_INSERT(options_tree, &oo->tree, o);
|
|
||||||
memcpy(&o->style, &grid_default_cell, sizeof o->style);
|
|
||||||
} else if (o->type == OPTIONS_STRING)
|
|
||||||
s = o->str;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
o = options_new(oo, name, &s);
|
||||||
o->type = OPTIONS_STRING;
|
o->type = OPTIONS_STRING;
|
||||||
xvasprintf(&o->str, fmt, ap);
|
xvasprintf(&o->str, fmt, ap);
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,16 +177,10 @@ options_set_number(struct options *oo, const char *name, long long value)
|
|||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
|
|
||||||
if ((o = options_find1(oo, name)) == NULL) {
|
o = options_new(oo, name, NULL);
|
||||||
o = xmalloc(sizeof *o);
|
|
||||||
o->name = xstrdup(name);
|
|
||||||
RB_INSERT(options_tree, &oo->tree, o);
|
|
||||||
memcpy(&o->style, &grid_default_cell, sizeof o->style);
|
|
||||||
} else if (o->type == OPTIONS_STRING)
|
|
||||||
free(o->str);
|
|
||||||
|
|
||||||
o->type = OPTIONS_NUMBER;
|
o->type = OPTIONS_NUMBER;
|
||||||
o->num = value;
|
o->num = value;
|
||||||
|
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,15 +212,10 @@ options_set_style(struct options *oo, const char *name, const char *value,
|
|||||||
if (style_parse(&grid_default_cell, &tmpgc, value) == -1)
|
if (style_parse(&grid_default_cell, &tmpgc, value) == -1)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (o == NULL) {
|
o = options_new(oo, name, NULL);
|
||||||
o = xmalloc(sizeof *o);
|
|
||||||
o->name = xstrdup(name);
|
|
||||||
RB_INSERT(options_tree, &oo->tree, o);
|
|
||||||
} else if (o->type == OPTIONS_STRING)
|
|
||||||
free(o->str);
|
|
||||||
|
|
||||||
o->type = OPTIONS_STYLE;
|
o->type = OPTIONS_STYLE;
|
||||||
memcpy(&o->style, &tmpgc, sizeof o->style);
|
memcpy(&o->style, &tmpgc, sizeof o->style);
|
||||||
|
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user