summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-01-21 08:40:09 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-01-21 08:40:09 +0000
commit535286c05aee55c0127cdabada8e54582905ef8e (patch)
tree425407a0ae29629bd1f5ffacd18b5034be43602f
parent7f24020cbe477548795754f2f7f01aafc2cd3cb8 (diff)
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 :-).
-rw-r--r--cmd-send-prefix.c13
-rw-r--r--cmd-set-option.c34
-rw-r--r--key-string.c4
-rw-r--r--options-table.c25
-rw-r--r--options.c41
-rw-r--r--server-client.c16
-rw-r--r--tmux.119
-rw-r--r--tmux.c7
-rw-r--r--tmux.h11
9 files changed, 52 insertions, 118 deletions
diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c
index 398f440e..b541fddf 100644
--- a/cmd-send-prefix.c
+++ b/cmd-send-prefix.c
@@ -28,8 +28,8 @@ int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_send_prefix_entry = {
"send-prefix", NULL,
- "t:", 0, 0,
- CMD_TARGET_PANE_USAGE,
+ "2t:", 0, 0,
+ "[-2] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
@@ -42,13 +42,16 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args;
struct session *s;
struct window_pane *wp;
- struct keylist *keylist;
+ int key;
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
return (-1);
- keylist = options_get_data(&s->options, "prefix");
- window_pane_key(wp, s, ARRAY_FIRST(keylist));
+ if (args_has(args, '2'))
+ key = options_get_number(&s->options, "prefix2");
+ else
+ key = options_get_number(&s->options, "prefix");
+ window_pane_key(wp, s, key);
return (0);
}
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 9ddfba9c..88aa454a 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -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 *,
const struct options_table_entry *, struct options *,
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 char *);
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:
o = cmd_set_option_number(self, ctx, oe, oo, value);
break;
- case OPTIONS_TABLE_KEYS:
- o = cmd_set_option_keys(self, ctx, oe, oo, value);
+ case OPTIONS_TABLE_KEY:
+ o = cmd_set_option_key(self, ctx, oe, oo, value);
break;
case OPTIONS_TABLE_COLOUR:
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));
}
-/* Set a keys option. */
+/* Set a key option. */
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)
{
- struct keylist *keylist;
- char *copy, *ptr, *s;
- int key;
-
- keylist = xmalloc(sizeof *keylist);
- ARRAY_INIT(keylist);
-
- 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);
+ int key;
+
+ if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
+ ctx->error(ctx, "bad key: %s", value);
+ return (NULL);
}
- xfree(copy);
- return (options_set_data(oo, oe->name, keylist, xfree));
+ return (options_set_number(oo, oe->name, key));
}
/* Set a colour option. */
diff --git a/key-string.c b/key-string.c
index 29b6a844..08cf0b9c 100644
--- a/key-string.c
+++ b/key-string.c
@@ -188,6 +188,10 @@ key_string_lookup_key(int key)
*out = '\0';
+ /* Handle no key. */
+ if (key == KEYC_NONE)
+ return ("none");
+
/*
* 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
diff --git a/options-table.c b/options-table.c
index 8bc61149..918a9f51 100644
--- a/options-table.c
+++ b/options-table.c
@@ -262,8 +262,13 @@ const struct options_table_entry session_options_table[] = {
},
{ .name = "prefix",
- .type = OPTIONS_TABLE_KEYS,
- /* set in main() */
+ .type = OPTIONS_TABLE_KEY,
+ .default_num = '\002',
+ },
+
+ { .name = "prefix2",
+ .type = OPTIONS_TABLE_KEY,
+ .default_num = KEYC_NONE,
},
{ .name = "repeat-time",
@@ -683,10 +688,8 @@ const char *
options_table_print_entry(
const struct options_table_entry *oe, struct options_entry *o)
{
- static char out[BUFSIZ];
- const char *s;
- struct keylist *keylist;
- u_int i;
+ static char out[BUFSIZ];
+ const char *s;
*out = '\0';
switch (oe->type) {
@@ -696,14 +699,8 @@ options_table_print_entry(
case OPTIONS_TABLE_NUMBER:
xsnprintf(out, sizeof out, "%lld", o->num);
break;
- case OPTIONS_TABLE_KEYS:
- keylist = o->data;
- 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);
- }
+ case OPTIONS_TABLE_KEY:
+ xsnprintf(out, sizeof out, "%s", key_string_lookup_key(o->num));
break;
case OPTIONS_TABLE_COLOUR:
s = colour_tostring(o->num);
diff --git a/options.c b/options.c
index f7efdc29..6ee4bf1d 100644
--- a/options.c
+++ b/options.c
@@ -54,8 +54,6 @@ options_free(struct options *oo)
xfree(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
- else if (o->type == OPTIONS_DATA)
- o->freefn(o->data);
xfree(o);
}
}
@@ -97,8 +95,6 @@ options_remove(struct options *oo, const char *name)
xfree(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
- else if (o->type == OPTIONS_DATA)
- o->freefn(o->data);
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);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
- else if (o->type == OPTIONS_DATA)
- o->freefn(o->data);
va_start(ap, fmt);
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);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
- else if (o->type == OPTIONS_DATA)
- o->freefn(o->data);
o->type = OPTIONS_NUMBER;
o->num = value;
@@ -166,36 +158,3 @@ options_get_number(struct options *oo, const char *name)
fatalx("option not a number");
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);
-}
diff --git a/server-client.c b/server-client.c
index 1ea1da91..138d9a80 100644
--- a/server-client.c
+++ b/server-client.c
@@ -273,9 +273,7 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
struct options *oo;
struct timeval tv;
struct key_binding *bd;
- struct keylist *keylist;
int xtimeout, isprefix;
- u_int i;
/* Check the client is good to accept input. */
if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
@@ -360,14 +358,12 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
}
/* Is this a prefix key? */
- keylist = options_get_data(&c->session->options, "prefix");
- isprefix = 0;
- for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
- if (key == ARRAY_ITEM(keylist, i)) {
- isprefix = 1;
- break;
- }
- }
+ if (key == options_get_number(&c->session->options, "prefix"))
+ isprefix = 1;
+ else if (key == options_get_number(&c->session->options, "prefix2"))
+ isprefix = 1;
+ else
+ isprefix = 0;
/* No previous prefix key. */
if (!(c->flags & CLIENT_PREFIX)) {
diff --git a/tmux.1 b/tmux.1
index 5403d6f8..0733ea4b 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1652,9 +1652,13 @@ All arguments are sent sequentially from first to last.
The
.Fl R
flag causes the terminal state to be reset.
-.It Ic send-prefix Op Fl t Ar target-pane
-Send the prefix key to a window as if it was pressed.
-If multiple prefix keys are configured, only the first is sent.
+.It Xo Ic send-prefix
+.Op Fl 2
+.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
.Op Fl acn
.Op Fl t Ar key-table
@@ -2029,11 +2033,10 @@ Set the pane border colour for the currently active pane.
.It Ic pane-border-bg Ar colour
.It Ic pane-border-fg Ar colour
Set the pane border colour for panes aside from the active pane.
-.It Ic prefix Ar keys
-Set the keys accepted as a prefix key.
-.Ar keys
-is a comma-separated list of key names, each of which individually behave as
-the prefix key.
+.It Ic prefix Ar key
+Set the key accepted as a prefix key.
+.It Ic prefix2 Ar key
+Set a secondary key accepted as a prefix key.
.It Ic repeat-time Ar time
Allow multiple commands to be entered without pressing the prefix-key again
in the specified
diff --git a/tmux.c b/tmux.c
index cab9d54e..35d43909 100644
--- a/tmux.c
+++ b/tmux.c
@@ -232,7 +232,6 @@ int
main(int argc, char **argv)
{
struct passwd *pw;
- struct keylist *keylist;
char *s, *path, *label, *home, **var;
int opt, flags, quiet, keys;
@@ -329,12 +328,6 @@ main(int argc, char **argv)
options_init(&global_w_options, NULL);
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. */
if (flags & IDENTIFY_UTF8) {
options_set_number(&global_s_options, "status-utf8", 1);
diff --git a/tmux.h b/tmux.h
index 617741d7..dba364fa 100644
--- a/tmux.h
+++ b/tmux.h
@@ -673,9 +673,6 @@ struct options_entry {
char *str;
long long num;
- void *data;
-
- void (*freefn)(void *);
SPLAY_ENTRY(options_entry) entry;
};
@@ -685,9 +682,6 @@ struct options {
struct options *parent;
};
-/* Key list for prefix option. */
-ARRAY_DECL(keylist, int);
-
/* Scheduled job. */
struct job {
char *cmd;
@@ -1294,7 +1288,7 @@ SPLAY_HEAD(key_bindings, key_binding);
enum options_table_type {
OPTIONS_TABLE_STRING,
OPTIONS_TABLE_NUMBER,
- OPTIONS_TABLE_KEYS,
+ OPTIONS_TABLE_KEY,
OPTIONS_TABLE_COLOUR,
OPTIONS_TABLE_ATTRIBUTES,
OPTIONS_TABLE_FLAG,
@@ -1413,9 +1407,6 @@ char *options_get_string(struct options *, const char *);
struct options_entry *options_set_number(
struct options *, const char *, long long);
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 */
extern const struct options_table_entry server_options_table[];