Pass window into mode functions.

This commit is contained in:
nicm 2018-12-18 13:20:44 +00:00
parent 4e3d661284
commit bde0224deb
9 changed files with 37 additions and 25 deletions

View File

@ -60,13 +60,14 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
{
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct key_table *table;
struct key_binding *bd;
if (wp->mode == NULL || wp->mode->key_table == NULL) {
if (options_get_number(wp->window->options, "xterm-keys"))
key |= KEYC_XTERM;
window_pane_key(wp, NULL, s, key, NULL);
window_pane_key(wp, NULL, s, wl, key, NULL);
return;
}
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
@ -86,6 +87,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
struct client *c = cmd_find_client(item, NULL, 1);
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct mouse_event *m = &item->shared->mouse;
struct utf8_data *ud, *uc;
wchar_t wc;
@ -111,9 +113,9 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
if (!m->valid)
wp->mode->command(wp, c, s, args, NULL);
wp->mode->command(wp, c, s, wl, args, NULL);
else
wp->mode->command(wp, c, s, args, m);
wp->mode->command(wp, c, s, wl, args, m);
return (CMD_RETURN_NORMAL);
}
@ -123,7 +125,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "no mouse target");
return (CMD_RETURN_ERROR);
}
window_pane_key(wp, NULL, s, m->key, m);
window_pane_key(wp, NULL, s, wl, m->key, m);
return (CMD_RETURN_NORMAL);
}

View File

@ -923,6 +923,7 @@ server_client_handle_key(struct client *c, key_code key)
{
struct mouse_event *m = &c->tty.mouse;
struct session *s = c->session;
struct winlink *wl;
struct window *w;
struct window_pane *wp;
struct timeval tv;
@ -935,7 +936,8 @@ server_client_handle_key(struct client *c, key_code key)
/* Check the client is good to accept input. */
if (s == NULL || (c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
return;
w = s->curw->window;
wl = s->curw;
w = wl->window;
/* Update the activity timer. */
if (gettimeofday(&c->activity_time, NULL) != 0)
@ -1126,7 +1128,7 @@ forward_key:
if (c->flags & CLIENT_READONLY)
return;
if (wp != NULL)
window_pane_key(wp, c, s, key, m);
window_pane_key(wp, c, s, wl, key, m);
}
/* Client functions that need to happen every loop. */

9
tmux.h
View File

@ -52,6 +52,7 @@ struct options_entry;
struct session;
struct tmuxpeer;
struct tmuxproc;
struct winlink;
/* Client-server protocol version. */
#define PROTOCOL_VERSION 8
@ -699,11 +700,12 @@ struct window_mode {
void (*free)(struct window_pane *);
void (*resize)(struct window_pane *, u_int, u_int);
void (*key)(struct window_pane *, struct client *,
struct session *, key_code, struct mouse_event *);
struct session *, struct winlink *, key_code,
struct mouse_event *);
const char *(*key_table)(struct window_pane *);
void (*command)(struct window_pane *, struct client *,
struct session *, struct args *,
struct session *, struct winlink *, struct args *,
struct mouse_event *);
};
#define WINDOW_MODE_TIMEOUT 180
@ -2193,7 +2195,8 @@ int window_pane_set_mode(struct window_pane *,
struct args *);
void window_pane_reset_mode(struct window_pane *);
void window_pane_key(struct window_pane *, struct client *,
struct session *, key_code, struct mouse_event *);
struct session *, struct winlink *, key_code,
struct mouse_event *);
int window_pane_visible(struct window_pane *);
u_int window_pane_search(struct window_pane *, const char *);
const char *window_printable_flags(struct winlink *);

View File

@ -31,8 +31,8 @@ static void window_buffer_free(struct window_pane *);
static void window_buffer_resize(struct window_pane *, u_int,
u_int);
static void window_buffer_key(struct window_pane *,
struct client *, struct session *, key_code,
struct mouse_event *);
struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *);
#define WINDOW_BUFFER_DEFAULT_COMMAND "paste-buffer -b '%%'"
@ -338,7 +338,8 @@ window_buffer_do_paste(void* modedata, void *itemdata, struct client *c,
static void
window_buffer_key(struct window_pane *wp, struct client *c,
__unused struct session *s, key_code key, struct mouse_event *m)
__unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m)
{
struct window_buffer_modedata *data = wp->modedata;
struct mode_tree_data *mtd = data->data;

View File

@ -31,8 +31,8 @@ static void window_client_free(struct window_pane *);
static void window_client_resize(struct window_pane *, u_int,
u_int);
static void window_client_key(struct window_pane *,
struct client *, struct session *, key_code,
struct mouse_event *);
struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *);
#define WINDOW_CLIENT_DEFAULT_COMMAND "detach-client -t '%%'"
@ -312,7 +312,8 @@ window_client_do_detach(void* modedata, void *itemdata,
static void
window_client_key(struct window_pane *wp, struct client *c,
__unused struct session *s, key_code key, struct mouse_event *m)
__unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m)
{
struct window_client_modedata *data = wp->modedata;
struct mode_tree_data *mtd = data->data;

View File

@ -29,7 +29,8 @@ static struct screen *window_clock_init(struct window_pane *,
static void window_clock_free(struct window_pane *);
static void window_clock_resize(struct window_pane *, u_int, u_int);
static void window_clock_key(struct window_pane *, struct client *,
struct session *, key_code, struct mouse_event *);
struct session *, struct winlink *, key_code,
struct mouse_event *);
static void window_clock_timer_callback(int, short, void *);
static void window_clock_draw_screen(struct window_pane *);
@ -190,8 +191,8 @@ window_clock_resize(struct window_pane *wp, u_int sx, u_int sy)
static void
window_clock_key(struct window_pane *wp, __unused struct client *c,
__unused struct session *sess, __unused key_code key,
__unused struct mouse_event *m)
__unused struct session *s, __unused struct winlink *wl,
__unused key_code key, __unused struct mouse_event *m)
{
window_pane_reset_mode(wp);
}

View File

@ -26,7 +26,8 @@
static const char *window_copy_key_table(struct window_pane *);
static void window_copy_command(struct window_pane *, struct client *,
struct session *, struct args *, struct mouse_event *);
struct session *, struct winlink *, struct args *,
struct mouse_event *);
static struct screen *window_copy_init(struct window_pane *,
struct cmd_find_state *, struct args *);
static void window_copy_free(struct window_pane *);
@ -514,7 +515,7 @@ window_copy_key_table(struct window_pane *wp)
static void
window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
struct args *args, struct mouse_event *m)
__unused struct winlink *wl, struct args *args, struct mouse_event *m)
{
struct window_copy_mode_data *data = wp->modedata;
struct screen *sn = &data->screen;

View File

@ -29,8 +29,8 @@ static struct screen *window_tree_init(struct window_pane *,
static void window_tree_free(struct window_pane *);
static void window_tree_resize(struct window_pane *, u_int, u_int);
static void window_tree_key(struct window_pane *,
struct client *, struct session *, key_code,
struct mouse_event *);
struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *);
#define WINDOW_TREE_DEFAULT_COMMAND "switch-client -t '%%'"
@ -1120,7 +1120,8 @@ window_tree_mouse(struct window_tree_modedata *data, key_code key, u_int x,
static void
window_tree_key(struct window_pane *wp, struct client *c,
__unused struct session *s, key_code key, struct mouse_event *m)
__unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m)
{
struct window_tree_modedata *data = wp->modedata;
struct window_tree_itemdata *item, *new_item;

View File

@ -1258,7 +1258,7 @@ window_pane_reset_mode(struct window_pane *wp)
void
window_pane_key(struct window_pane *wp, struct client *c, struct session *s,
key_code key, struct mouse_event *m)
struct winlink *wl, key_code key, struct mouse_event *m)
{
struct window_pane *wp2;
@ -1268,7 +1268,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s,
if (wp->mode != NULL) {
wp->modelast = time(NULL);
if (wp->mode->key != NULL)
wp->mode->key(wp, c, s, (key & ~KEYC_XTERM), m);
wp->mode->key(wp, c, s, wl, (key & ~KEYC_XTERM), m);
return;
}