mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Sync OpenBSD patchset 1007:
Drop the ability to have a list of keys in the prefix in favour of two separate options, prefix and prefix2. This simplifies the code and gets rid the data options type which was only used for this one option. Also add a -2 flag to send-prefix to send the secondary prefix key, fixing a cause of minor irritation. People who want three prefix keys are out of luck :-).
This commit is contained in:
parent
d4c2a935f2
commit
a7b0b30bdd
@ -28,8 +28,8 @@ int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_send_prefix_entry = {
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
"send-prefix", NULL,
|
"send-prefix", NULL,
|
||||||
"t:", 0, 0,
|
"2t:", 0, 0,
|
||||||
CMD_TARGET_PANE_USAGE,
|
"[-2] " CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@ -42,13 +42,16 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct keylist *keylist;
|
int key;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
keylist = options_get_data(&s->options, "prefix");
|
if (args_has(args, '2'))
|
||||||
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
key = options_get_number(&s->options, "prefix2");
|
||||||
|
else
|
||||||
|
key = options_get_number(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, s, key);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
|
|||||||
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
||||||
const struct options_table_entry *, struct options *,
|
const struct options_table_entry *, struct options *,
|
||||||
const char *);
|
const char *);
|
||||||
struct options_entry *cmd_set_option_keys(struct cmd *, struct cmd_ctx *,
|
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *,
|
||||||
const struct options_table_entry *, struct options *,
|
const struct options_table_entry *, struct options *,
|
||||||
const char *);
|
const char *);
|
||||||
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
||||||
@ -236,8 +236,8 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
|||||||
case OPTIONS_TABLE_NUMBER:
|
case OPTIONS_TABLE_NUMBER:
|
||||||
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_KEYS:
|
case OPTIONS_TABLE_KEY:
|
||||||
o = cmd_set_option_keys(self, ctx, oe, oo, value);
|
o = cmd_set_option_key(self, ctx, oe, oo, value);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_COLOUR:
|
case OPTIONS_TABLE_COLOUR:
|
||||||
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
||||||
@ -298,31 +298,19 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
|||||||
return (options_set_number(oo, oe->name, ll));
|
return (options_set_number(oo, oe->name, ll));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a keys option. */
|
/* Set a key option. */
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
cmd_set_option_keys(unused struct cmd *self, struct cmd_ctx *ctx,
|
cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
{
|
{
|
||||||
struct keylist *keylist;
|
int key;
|
||||||
char *copy, *ptr, *s;
|
|
||||||
int key;
|
|
||||||
|
|
||||||
keylist = xmalloc(sizeof *keylist);
|
if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
|
||||||
ARRAY_INIT(keylist);
|
ctx->error(ctx, "bad key: %s", value);
|
||||||
|
return (NULL);
|
||||||
ptr = copy = xstrdup(value);
|
|
||||||
while ((s = strsep(&ptr, ",")) != NULL) {
|
|
||||||
if ((key = key_string_lookup_string(s)) == KEYC_NONE) {
|
|
||||||
ctx->error(ctx, "unknown key: %s", s);
|
|
||||||
xfree(copy);
|
|
||||||
xfree(keylist);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
ARRAY_ADD(keylist, key);
|
|
||||||
}
|
}
|
||||||
xfree(copy);
|
|
||||||
|
|
||||||
return (options_set_data(oo, oe->name, keylist, xfree));
|
return (options_set_number(oo, oe->name, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a colour option. */
|
/* Set a colour option. */
|
||||||
|
@ -188,6 +188,10 @@ key_string_lookup_key(int key)
|
|||||||
|
|
||||||
*out = '\0';
|
*out = '\0';
|
||||||
|
|
||||||
|
/* Handle no key. */
|
||||||
|
if (key == KEYC_NONE)
|
||||||
|
return ("none");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Special case: display C-@ as C-Space. Could do this below in
|
* Special case: display C-@ as C-Space. Could do this below in
|
||||||
* the (key >= 0 && key <= 32), but this way we let it be found
|
* the (key >= 0 && key <= 32), but this way we let it be found
|
||||||
|
@ -261,8 +261,13 @@ const struct options_table_entry session_options_table[] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "prefix",
|
{ .name = "prefix",
|
||||||
.type = OPTIONS_TABLE_KEYS,
|
.type = OPTIONS_TABLE_KEY,
|
||||||
/* set in main() */
|
.default_num = '\002',
|
||||||
|
},
|
||||||
|
|
||||||
|
{ .name = "prefix2",
|
||||||
|
.type = OPTIONS_TABLE_KEY,
|
||||||
|
.default_num = KEYC_NONE,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "repeat-time",
|
{ .name = "repeat-time",
|
||||||
@ -682,10 +687,8 @@ const char *
|
|||||||
options_table_print_entry(
|
options_table_print_entry(
|
||||||
const struct options_table_entry *oe, struct options_entry *o)
|
const struct options_table_entry *oe, struct options_entry *o)
|
||||||
{
|
{
|
||||||
static char out[BUFSIZ];
|
static char out[BUFSIZ];
|
||||||
const char *s;
|
const char *s;
|
||||||
struct keylist *keylist;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
*out = '\0';
|
*out = '\0';
|
||||||
switch (oe->type) {
|
switch (oe->type) {
|
||||||
@ -695,14 +698,8 @@ options_table_print_entry(
|
|||||||
case OPTIONS_TABLE_NUMBER:
|
case OPTIONS_TABLE_NUMBER:
|
||||||
xsnprintf(out, sizeof out, "%lld", o->num);
|
xsnprintf(out, sizeof out, "%lld", o->num);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_KEYS:
|
case OPTIONS_TABLE_KEY:
|
||||||
keylist = o->data;
|
xsnprintf(out, sizeof out, "%s", key_string_lookup_key(o->num));
|
||||||
for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
|
|
||||||
s = key_string_lookup_key(ARRAY_ITEM(keylist, i));
|
|
||||||
strlcat(out, s, sizeof out);
|
|
||||||
if (i != ARRAY_LENGTH(keylist) - 1)
|
|
||||||
strlcat(out, ",", sizeof out);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_COLOUR:
|
case OPTIONS_TABLE_COLOUR:
|
||||||
s = colour_tostring(o->num);
|
s = colour_tostring(o->num);
|
||||||
|
41
options.c
41
options.c
@ -54,8 +54,6 @@ options_free(struct options *oo)
|
|||||||
xfree(o->name);
|
xfree(o->name);
|
||||||
if (o->type == OPTIONS_STRING)
|
if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
else if (o->type == OPTIONS_DATA)
|
|
||||||
o->freefn(o->data);
|
|
||||||
xfree(o);
|
xfree(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,8 +95,6 @@ options_remove(struct options *oo, const char *name)
|
|||||||
xfree(o->name);
|
xfree(o->name);
|
||||||
if (o->type == OPTIONS_STRING)
|
if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
else if (o->type == OPTIONS_DATA)
|
|
||||||
o->freefn(o->data);
|
|
||||||
xfree(o);
|
xfree(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +110,6 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
|
|||||||
SPLAY_INSERT(options_tree, &oo->tree, o);
|
SPLAY_INSERT(options_tree, &oo->tree, o);
|
||||||
} else if (o->type == OPTIONS_STRING)
|
} else if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
else if (o->type == OPTIONS_DATA)
|
|
||||||
o->freefn(o->data);
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
o->type = OPTIONS_STRING;
|
o->type = OPTIONS_STRING;
|
||||||
@ -147,8 +141,6 @@ options_set_number(struct options *oo, const char *name, long long value)
|
|||||||
SPLAY_INSERT(options_tree, &oo->tree, o);
|
SPLAY_INSERT(options_tree, &oo->tree, o);
|
||||||
} else if (o->type == OPTIONS_STRING)
|
} else if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
else if (o->type == OPTIONS_DATA)
|
|
||||||
o->freefn(o->data);
|
|
||||||
|
|
||||||
o->type = OPTIONS_NUMBER;
|
o->type = OPTIONS_NUMBER;
|
||||||
o->num = value;
|
o->num = value;
|
||||||
@ -166,36 +158,3 @@ options_get_number(struct options *oo, const char *name)
|
|||||||
fatalx("option not a number");
|
fatalx("option not a number");
|
||||||
return (o->num);
|
return (o->num);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct options_entry *
|
|
||||||
options_set_data(
|
|
||||||
struct options *oo, const char *name, void *value, void (*freefn)(void *))
|
|
||||||
{
|
|
||||||
struct options_entry *o;
|
|
||||||
|
|
||||||
if ((o = options_find1(oo, name)) == NULL) {
|
|
||||||
o = xmalloc(sizeof *o);
|
|
||||||
o->name = xstrdup(name);
|
|
||||||
SPLAY_INSERT(options_tree, &oo->tree, o);
|
|
||||||
} else if (o->type == OPTIONS_STRING)
|
|
||||||
xfree(o->str);
|
|
||||||
else if (o->type == OPTIONS_DATA)
|
|
||||||
o->freefn(o->data);
|
|
||||||
|
|
||||||
o->type = OPTIONS_DATA;
|
|
||||||
o->data = value;
|
|
||||||
o->freefn = freefn;
|
|
||||||
return (o);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
options_get_data(struct options *oo, const char *name)
|
|
||||||
{
|
|
||||||
struct options_entry *o;
|
|
||||||
|
|
||||||
if ((o = options_find(oo, name)) == NULL)
|
|
||||||
fatalx("missing option");
|
|
||||||
if (o->type != OPTIONS_DATA)
|
|
||||||
fatalx("option not data");
|
|
||||||
return (o->data);
|
|
||||||
}
|
|
||||||
|
@ -272,9 +272,7 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
|
|||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
struct keylist *keylist;
|
|
||||||
int xtimeout, isprefix;
|
int xtimeout, isprefix;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
/* Check the client is good to accept input. */
|
/* Check the client is good to accept input. */
|
||||||
if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
|
if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
|
||||||
@ -359,14 +357,12 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Is this a prefix key? */
|
/* Is this a prefix key? */
|
||||||
keylist = options_get_data(&c->session->options, "prefix");
|
if (key == options_get_number(&c->session->options, "prefix"))
|
||||||
isprefix = 0;
|
isprefix = 1;
|
||||||
for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
|
else if (key == options_get_number(&c->session->options, "prefix2"))
|
||||||
if (key == ARRAY_ITEM(keylist, i)) {
|
isprefix = 1;
|
||||||
isprefix = 1;
|
else
|
||||||
break;
|
isprefix = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No previous prefix key. */
|
/* No previous prefix key. */
|
||||||
if (!(c->flags & CLIENT_PREFIX)) {
|
if (!(c->flags & CLIENT_PREFIX)) {
|
||||||
|
19
tmux.1
19
tmux.1
@ -1656,9 +1656,13 @@ All arguments are sent sequentially from first to last.
|
|||||||
The
|
The
|
||||||
.Fl R
|
.Fl R
|
||||||
flag causes the terminal state to be reset.
|
flag causes the terminal state to be reset.
|
||||||
.It Ic send-prefix Op Fl t Ar target-pane
|
.It Xo Ic send-prefix
|
||||||
Send the prefix key to a window as if it was pressed.
|
.Op Fl 2
|
||||||
If multiple prefix keys are configured, only the first is sent.
|
.Op Fl t Ar target-pane
|
||||||
|
.Xc
|
||||||
|
Send the prefix key, or with
|
||||||
|
.Fl 2
|
||||||
|
the secondary prefix key, to a window as if it was pressed.
|
||||||
.It Xo Ic unbind-key
|
.It Xo Ic unbind-key
|
||||||
.Op Fl acn
|
.Op Fl acn
|
||||||
.Op Fl t Ar key-table
|
.Op Fl t Ar key-table
|
||||||
@ -2033,11 +2037,10 @@ Set the pane border colour for the currently active pane.
|
|||||||
.It Ic pane-border-bg Ar colour
|
.It Ic pane-border-bg Ar colour
|
||||||
.It Ic pane-border-fg Ar colour
|
.It Ic pane-border-fg Ar colour
|
||||||
Set the pane border colour for panes aside from the active pane.
|
Set the pane border colour for panes aside from the active pane.
|
||||||
.It Ic prefix Ar keys
|
.It Ic prefix Ar key
|
||||||
Set the keys accepted as a prefix key.
|
Set the key accepted as a prefix key.
|
||||||
.Ar keys
|
.It Ic prefix2 Ar key
|
||||||
is a comma-separated list of key names, each of which individually behave as
|
Set a secondary key accepted as a prefix key.
|
||||||
the prefix key.
|
|
||||||
.It Ic repeat-time Ar time
|
.It Ic repeat-time Ar time
|
||||||
Allow multiple commands to be entered without pressing the prefix-key again
|
Allow multiple commands to be entered without pressing the prefix-key again
|
||||||
in the specified
|
in the specified
|
||||||
|
7
tmux.c
7
tmux.c
@ -235,7 +235,6 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct keylist *keylist;
|
|
||||||
char *s, *path, *label, *home, **var;
|
char *s, *path, *label, *home, **var;
|
||||||
int opt, flags, quiet, keys;
|
int opt, flags, quiet, keys;
|
||||||
|
|
||||||
@ -335,12 +334,6 @@ main(int argc, char **argv)
|
|||||||
options_init(&global_w_options, NULL);
|
options_init(&global_w_options, NULL);
|
||||||
options_table_populate_tree(window_options_table, &global_w_options);
|
options_table_populate_tree(window_options_table, &global_w_options);
|
||||||
|
|
||||||
/* Set the prefix option (its a list, so not in the table). */
|
|
||||||
keylist = xmalloc(sizeof *keylist);
|
|
||||||
ARRAY_INIT(keylist);
|
|
||||||
ARRAY_ADD(keylist, '\002');
|
|
||||||
options_set_data(&global_s_options, "prefix", keylist, xfree);
|
|
||||||
|
|
||||||
/* Enable UTF-8 if the first client is on UTF-8 terminal. */
|
/* Enable UTF-8 if the first client is on UTF-8 terminal. */
|
||||||
if (flags & IDENTIFY_UTF8) {
|
if (flags & IDENTIFY_UTF8) {
|
||||||
options_set_number(&global_s_options, "status-utf8", 1);
|
options_set_number(&global_s_options, "status-utf8", 1);
|
||||||
|
11
tmux.h
11
tmux.h
@ -669,9 +669,6 @@ struct options_entry {
|
|||||||
|
|
||||||
char *str;
|
char *str;
|
||||||
long long num;
|
long long num;
|
||||||
void *data;
|
|
||||||
|
|
||||||
void (*freefn)(void *);
|
|
||||||
|
|
||||||
SPLAY_ENTRY(options_entry) entry;
|
SPLAY_ENTRY(options_entry) entry;
|
||||||
};
|
};
|
||||||
@ -681,9 +678,6 @@ struct options {
|
|||||||
struct options *parent;
|
struct options *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Key list for prefix option. */
|
|
||||||
ARRAY_DECL(keylist, int);
|
|
||||||
|
|
||||||
/* Scheduled job. */
|
/* Scheduled job. */
|
||||||
struct job {
|
struct job {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
@ -1290,7 +1284,7 @@ SPLAY_HEAD(key_bindings, key_binding);
|
|||||||
enum options_table_type {
|
enum options_table_type {
|
||||||
OPTIONS_TABLE_STRING,
|
OPTIONS_TABLE_STRING,
|
||||||
OPTIONS_TABLE_NUMBER,
|
OPTIONS_TABLE_NUMBER,
|
||||||
OPTIONS_TABLE_KEYS,
|
OPTIONS_TABLE_KEY,
|
||||||
OPTIONS_TABLE_COLOUR,
|
OPTIONS_TABLE_COLOUR,
|
||||||
OPTIONS_TABLE_ATTRIBUTES,
|
OPTIONS_TABLE_ATTRIBUTES,
|
||||||
OPTIONS_TABLE_FLAG,
|
OPTIONS_TABLE_FLAG,
|
||||||
@ -1409,9 +1403,6 @@ char *options_get_string(struct options *, const char *);
|
|||||||
struct options_entry *options_set_number(
|
struct options_entry *options_set_number(
|
||||||
struct options *, const char *, long long);
|
struct options *, const char *, long long);
|
||||||
long long options_get_number(struct options *, const char *);
|
long long options_get_number(struct options *, const char *);
|
||||||
struct options_entry *options_set_data(
|
|
||||||
struct options *, const char *, void *, void (*)(void *));
|
|
||||||
void *options_get_data(struct options *, const char *);
|
|
||||||
|
|
||||||
/* options-table.c */
|
/* options-table.c */
|
||||||
extern const struct options_table_entry server_options_table[];
|
extern const struct options_table_entry server_options_table[];
|
||||||
|
Loading…
Reference in New Issue
Block a user