Add key-table option to set the default key table for a session, allows

different key bindings for different sessions and a few other things.
This commit is contained in:
nicm 2015-12-12 18:32:24 +00:00
parent 6a50cf89b4
commit 5ed17e84fa
10 changed files with 52 additions and 10 deletions

View File

@ -119,6 +119,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
}
c->session = s;
server_client_set_key_table(c, NULL);
status_timer_start(c);
notify_attached_session_changed(c);
session_update_activity(s, NULL);
@ -150,6 +151,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
}
c->session = s;
server_client_set_key_table(c, NULL);
status_timer_start(c);
notify_attached_session_changed(c);
session_update_activity(s, NULL);

View File

@ -262,6 +262,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
} else if (c->session != NULL)
c->last_session = c->session;
c->session = s;
server_client_set_key_table(c, NULL);
status_timer_start(c);
notify_attached_session_changed(c);
session_update_activity(s, NULL);

View File

@ -183,6 +183,10 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
w->active->flags |= PANE_CHANGED;
}
}
if (strcmp(oe->name, "key-table") == 0) {
TAILQ_FOREACH(c, &clients, entry)
server_client_set_key_table(c, NULL);
}
if (strcmp(oe->name, "status") == 0 ||
strcmp(oe->name, "status-interval") == 0)
status_timer_start_all();

View File

@ -124,6 +124,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
if (c->session != NULL && c->session != s)
c->last_session = c->session;
c->session = s;
server_client_set_key_table(c, NULL);
status_timer_start(c);
session_update_activity(s, NULL);
gettimeofday(&s->last_attached_time, NULL);

View File

@ -1035,6 +1035,7 @@ void
format_defaults_client(struct format_tree *ft, struct client *c)
{
struct session *s;
const char *name;
if (ft->s == NULL)
ft->s = c->session;
@ -1052,7 +1053,8 @@ format_defaults_client(struct format_tree *ft, struct client *c)
format_add_tv(ft, "client_created", &c->creation_time);
format_add_tv(ft, "client_activity", &c->activity_time);
if (strcmp(c->keytable->name, "root") == 0)
name = server_client_get_key_table(c);
if (strcmp(c->keytable->name, name) == 0)
format_add(ft, "client_prefix", "%d", 0);
else
format_add(ft, "client_prefix", "%d", 1);

View File

@ -211,6 +211,12 @@ const struct options_table_entry options_table[] = {
.default_num = 2000
},
{ .name = "key-table",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "root"
},
{ .name = "lock-after-time",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SESSION,

View File

@ -32,7 +32,6 @@
#include "tmux.h"
void server_client_key_table(struct client *, const char *);
void server_client_free(int, short, void *);
void server_client_check_focus(struct window_pane *);
void server_client_check_resize(struct window_pane *);
@ -72,13 +71,32 @@ server_client_check_nested(struct client *c)
/* Set client key table. */
void
server_client_key_table(struct client *c, const char *name)
server_client_set_key_table(struct client *c, const char *name)
{
if (name == NULL)
name = server_client_get_key_table(c);
key_bindings_unref_table(c->keytable);
c->keytable = key_bindings_get_table(name, 1);
c->keytable->references++;
}
/* Get default key table. */
const char *
server_client_get_key_table(struct client *c)
{
struct session *s = c->session;
const char *name;
if (s == NULL)
return ("root");
name = options_get_string(s->options, "key-table");
if (*name == '\0')
return ("root");
return (name);
}
/* Create a new client. */
void
server_client_create(int fd)
@ -598,7 +616,7 @@ retry:
* again in the root table.
*/
if ((c->flags & CLIENT_REPEAT) && !bd->can_repeat) {
server_client_key_table(c, "root");
server_client_set_key_table(c, NULL);
c->flags &= ~CLIENT_REPEAT;
server_status_client(c);
goto retry;
@ -625,7 +643,7 @@ retry:
evtimer_add(&c->repeat_timer, &tv);
} else {
c->flags &= ~CLIENT_REPEAT;
server_client_key_table(c, "root");
server_client_set_key_table(c, NULL);
}
server_status_client(c);
@ -640,15 +658,15 @@ retry:
* root table and try again.
*/
if (c->flags & CLIENT_REPEAT) {
server_client_key_table(c, "root");
server_client_set_key_table(c, NULL);
c->flags &= ~CLIENT_REPEAT;
server_status_client(c);
goto retry;
}
/* If no match and we're not in the root table, that's it. */
if (strcmp(c->keytable->name, "root") != 0) {
server_client_key_table(c, "root");
if (strcmp(c->keytable->name, server_client_get_key_table(c)) != 0) {
server_client_set_key_table(c, NULL);
server_status_client(c);
return;
}
@ -659,7 +677,7 @@ retry:
*/
if (key == (key_code)options_get_number(s->options, "prefix") ||
key == (key_code)options_get_number(s->options, "prefix2")) {
server_client_key_table(c, "prefix");
server_client_set_key_table(c, "prefix");
server_status_client(c);
return;
}
@ -834,7 +852,7 @@ server_client_repeat_timer(__unused int fd, __unused short events, void *data)
struct client *c = data;
if (c->flags & CLIENT_REPEAT) {
server_client_key_table(c, "root");
server_client_set_key_table(c, NULL);
c->flags &= ~CLIENT_REPEAT;
server_status_client(c);
}

View File

@ -384,6 +384,7 @@ server_destroy_session(struct session *s)
} else {
c->last_session = NULL;
c->session = s_new;
server_client_set_key_table(c, NULL);
status_timer_start(c);
notify_attached_session_changed(c);
session_update_activity(s_new, NULL);

5
tmux.1
View File

@ -2572,6 +2572,11 @@ is in milliseconds.
Set the maximum number of lines held in window history.
This setting applies only to new windows - existing window histories are not
resized and retain the limit at the point they were created.
.It Ic key-table Ar key-table
Set the default key table to
.Ar key-table
instead of
.Em root .
.It Ic lock-after-time Ar number
Lock the session (like the
.Ic lock-session

2
tmux.h
View File

@ -1800,6 +1800,8 @@ void server_update_socket(void);
void server_add_accept(int);
/* server-client.c */
void server_client_set_key_table(struct client *, const char *);
const char *server_client_get_key_table(struct client *);
int server_client_check_nested(struct client *);
void server_client_handle_key(struct client *, key_code);
void server_client_create(int);