Add a separate mode struct for the active window mode if any.

This commit is contained in:
nicm 2019-03-07 20:24:21 +00:00
parent 3c24bc5617
commit f98c66ece8
12 changed files with 638 additions and 558 deletions

View File

@ -199,7 +199,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
size_t len; size_t len;
if (self->entry == &cmd_clear_history_entry) { if (self->entry == &cmd_clear_history_entry) {
if (wp->mode == &window_copy_mode) if (wp->mode != NULL && wp->mode->mode == &window_copy_mode)
window_pane_reset_mode(wp); window_pane_reset_mode(wp);
grid_clear_history(wp->base.grid); grid_clear_history(wp->base.grid);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -74,18 +74,18 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (wp->mode != &window_copy_mode) { if (wp->mode == NULL || wp->mode->mode != &window_copy_mode) {
flag = window_pane_set_mode(wp, &window_copy_mode, NULL, NULL); flag = window_pane_set_mode(wp, &window_copy_mode, NULL, NULL);
if (flag != 0) if (flag != 0)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
window_copy_init_from_pane(wp, args_has(self->args, 'e')); window_copy_init_from_pane(wp, args_has(self->args, 'e'));
} }
if (args_has(args, 'M')) { if (args_has(args, 'M')) {
if (wp->mode != NULL && wp->mode != &window_copy_mode) if (wp->mode != NULL && wp->mode->mode != &window_copy_mode)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
window_copy_start_drag(c, &shared->mouse); window_copy_start_drag(c, &shared->mouse);
} }
if (wp->mode == &window_copy_mode && args_has(self->args, 'u')) if (args_has(self->args, 'u'))
window_copy_pageup(wp, 0); window_copy_pageup(wp, 0);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -58,19 +58,20 @@ const struct cmd_entry cmd_send_prefix_entry = {
static void static void
cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key) cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
{ {
struct window_pane *wp = item->target.wp; struct window_pane *wp = item->target.wp;
struct session *s = item->target.s; struct session *s = item->target.s;
struct winlink *wl = item->target.wl; struct winlink *wl = item->target.wl;
struct key_table *table; struct window_mode_entry *wme = wp->mode;
struct key_binding *bd; struct key_table *table;
struct key_binding *bd;
if (wp->mode == NULL || wp->mode->key_table == NULL) { if (wme == NULL || wme->mode->key_table == NULL) {
if (options_get_number(wp->window->options, "xterm-keys")) if (options_get_number(wp->window->options, "xterm-keys"))
key |= KEYC_XTERM; key |= KEYC_XTERM;
window_pane_key(wp, NULL, s, wl, key, NULL); window_pane_key(wp, NULL, s, wl, key, NULL);
return; return;
} }
table = key_bindings_get_table(wp->mode->key_table(wp), 1); table = key_bindings_get_table(wme->mode->key_table(wme), 1);
bd = key_bindings_get(table, key & ~KEYC_XTERM); bd = key_bindings_get(table, key & ~KEYC_XTERM);
if (bd != NULL) { if (bd != NULL) {
@ -83,18 +84,19 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
static enum cmd_retval static enum cmd_retval
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{ {
struct args *args = self->args; struct args *args = self->args;
struct client *c = cmd_find_client(item, NULL, 1); struct client *c = cmd_find_client(item, NULL, 1);
struct window_pane *wp = item->target.wp; struct window_pane *wp = item->target.wp;
struct session *s = item->target.s; struct session *s = item->target.s;
struct winlink *wl = item->target.wl; struct winlink *wl = item->target.wl;
struct mouse_event *m = &item->shared->mouse; struct mouse_event *m = &item->shared->mouse;
struct utf8_data *ud, *uc; struct window_mode_entry *wme = wp->mode;
wchar_t wc; struct utf8_data *ud, *uc;
int i, literal; wchar_t wc;
key_code key; int i, literal;
u_int np = 1; key_code key;
char *cause = NULL; u_int np = 1;
char *cause = NULL;
if (args_has(args, 'N')) { if (args_has(args, 'N')) {
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause); np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
@ -103,19 +105,18 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (args_has(args, 'X') || args->argc == 0) if (wme != NULL && (args_has(args, 'X') || args->argc == 0))
wp->modeprefix = np; wme->prefix = np;
} }
if (args_has(args, 'X')) { if (args_has(args, 'X')) {
if (wp->mode == NULL || wp->mode->command == NULL) { if (wme == NULL || wme->mode->command == NULL) {
cmdq_error(item, "not in a mode"); cmdq_error(item, "not in a mode");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (!m->valid) if (!m->valid)
wp->mode->command(wp, c, s, wl, args, NULL); m = NULL;
else wme->mode->command(wme, c, s, wl, args, m);
wp->mode->command(wp, c, s, wl, args, m);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@ -1535,7 +1535,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base); format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
if (wp->mode != NULL) if (wp->mode != NULL)
format_add(ft, "pane_mode", "%s", wp->mode->name); format_add(ft, "pane_mode", "%s", wp->mode->mode->name);
format_add(ft, "pane_synchronized", "%d", format_add(ft, "pane_synchronized", "%d",
!!options_get_number(w->options, "synchronize-panes")); !!options_get_number(w->options, "synchronize-panes"));
@ -1552,8 +1552,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper); format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower); format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
if (wp->mode != NULL && wp->mode->formats != NULL) if (wp->mode != NULL && wp->mode->mode->formats != NULL)
wp->mode->formats(wp, ft); wp->mode->mode->formats(wp->mode, ft);
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
format_add(ft, "alternate_saved_x", "%u", wp->saved_cx); format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);

View File

@ -928,6 +928,7 @@ server_client_handle_key(struct client *c, key_code key)
struct window_pane *wp; struct window_pane *wp;
struct timeval tv; struct timeval tv;
struct key_table *table, *first; struct key_table *table, *first;
const char *tablename;
struct key_binding *bd; struct key_binding *bd;
int xtimeout, flags; int xtimeout, flags;
struct cmd_find_state fs; struct cmd_find_state fs;
@ -1009,8 +1010,10 @@ server_client_handle_key(struct client *c, key_code key)
if (server_client_is_default_key_table(c, c->keytable) && if (server_client_is_default_key_table(c, c->keytable) &&
wp != NULL && wp != NULL &&
wp->mode != NULL && wp->mode != NULL &&
wp->mode->key_table != NULL) wp->mode->mode->key_table != NULL) {
table = key_bindings_get_table(wp->mode->key_table(wp), 1); tablename = wp->mode->mode->key_table(wp->mode);
table = key_bindings_get_table(tablename, 1);
}
else else
table = c->keytable; table = c->keytable;
first = table; first = table;

32
tmux.h
View File

@ -693,25 +693,37 @@ struct screen_write_ctx {
* Window mode. Windows can be in several modes and this is used to call the * Window mode. Windows can be in several modes and this is used to call the
* right function to handle input and output. * right function to handle input and output.
*/ */
struct window_mode_entry;
struct window_mode { struct window_mode {
const char *name; const char *name;
struct screen *(*init)(struct window_pane *, struct cmd_find_state *, struct screen *(*init)(struct window_mode_entry *,
struct args *); struct cmd_find_state *, struct args *);
void (*free)(struct window_pane *); void (*free)(struct window_mode_entry *);
void (*resize)(struct window_pane *, u_int, u_int); void (*resize)(struct window_mode_entry *, u_int, u_int);
void (*key)(struct window_pane *, struct client *, void (*key)(struct window_mode_entry *, struct client *,
struct session *, struct winlink *, key_code, struct session *, struct winlink *, key_code,
struct mouse_event *); struct mouse_event *);
const char *(*key_table)(struct window_pane *); const char *(*key_table)(struct window_mode_entry *);
void (*command)(struct window_pane *, struct client *, void (*command)(struct window_mode_entry *, struct client *,
struct session *, struct winlink *, struct args *, struct session *, struct winlink *, struct args *,
struct mouse_event *); struct mouse_event *);
void (*formats)(struct window_pane *, struct format_tree *); void (*formats)(struct window_mode_entry *,
struct format_tree *);
}; };
#define WINDOW_MODE_TIMEOUT 180 #define WINDOW_MODE_TIMEOUT 180
/* Active window mode. */
struct window_mode_entry {
struct window_pane *wp;
const struct window_mode *mode;
void *data;
u_int prefix;
};
/* Child window structure. */ /* Child window structure. */
struct window_pane { struct window_pane {
u_int id; u_int id;
@ -780,11 +792,9 @@ struct window_pane {
struct grid *saved_grid; struct grid *saved_grid;
struct grid_cell saved_cell; struct grid_cell saved_cell;
const struct window_mode *mode; struct window_mode_entry *mode;
void *modedata;
struct event modetimer; struct event modetimer;
time_t modelast; time_t modelast;
u_int modeprefix;
char *searchstr; char *searchstr;
TAILQ_ENTRY(window_pane) entry; TAILQ_ENTRY(window_pane) entry;

View File

@ -25,12 +25,12 @@
#include "tmux.h" #include "tmux.h"
static struct screen *window_buffer_init(struct window_pane *, static struct screen *window_buffer_init(struct window_mode_entry *,
struct cmd_find_state *, struct args *); struct cmd_find_state *, struct args *);
static void window_buffer_free(struct window_pane *); static void window_buffer_free(struct window_mode_entry *);
static void window_buffer_resize(struct window_pane *, u_int, static void window_buffer_resize(struct window_mode_entry *, u_int,
u_int); u_int);
static void window_buffer_key(struct window_pane *, static void window_buffer_key(struct window_mode_entry *,
struct client *, struct session *, struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *); struct winlink *, key_code, struct mouse_event *);
@ -253,13 +253,14 @@ window_buffer_search(__unused void *modedata, void *itemdata, const char *ss)
} }
static struct screen * static struct screen *
window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs, window_buffer_init(struct window_mode_entry *wme,
struct args *args) __unused struct cmd_find_state *fs, struct args *args)
{ {
struct window_pane *wp = wme->wp;
struct window_buffer_modedata *data; struct window_buffer_modedata *data;
struct screen *s; struct screen *s;
wp->modedata = data = xcalloc(1, sizeof *data); wme->data = data = xcalloc(1, sizeof *data);
if (args == NULL || !args_has(args, 'F')) if (args == NULL || !args_has(args, 'F'))
data->format = xstrdup(WINDOW_BUFFER_DEFAULT_FORMAT); data->format = xstrdup(WINDOW_BUFFER_DEFAULT_FORMAT);
@ -282,9 +283,9 @@ window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
} }
static void static void
window_buffer_free(struct window_pane *wp) window_buffer_free(struct window_mode_entry *wme)
{ {
struct window_buffer_modedata *data = wp->modedata; struct window_buffer_modedata *data = wme->data;
u_int i; u_int i;
if (data == NULL) if (data == NULL)
@ -303,9 +304,9 @@ window_buffer_free(struct window_pane *wp)
} }
static void static void
window_buffer_resize(struct window_pane *wp, u_int sx, u_int sy) window_buffer_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
{ {
struct window_buffer_modedata *data = wp->modedata; struct window_buffer_modedata *data = wme->data;
mode_tree_resize(data->data, sx, sy); mode_tree_resize(data->data, sx, sy);
} }
@ -337,11 +338,12 @@ window_buffer_do_paste(void* modedata, void *itemdata, struct client *c,
} }
static void static void
window_buffer_key(struct window_pane *wp, struct client *c, window_buffer_key(struct window_mode_entry *wme, struct client *c,
__unused struct session *s, __unused struct winlink *wl, key_code key, __unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m) struct mouse_event *m)
{ {
struct window_buffer_modedata *data = wp->modedata; struct window_pane *wp = wme->wp;
struct window_buffer_modedata *data = wme->data;
struct mode_tree_data *mtd = data->data; struct mode_tree_data *mtd = data->data;
struct window_buffer_itemdata *item; struct window_buffer_itemdata *item;
int finished; int finished;

View File

@ -25,12 +25,12 @@
#include "tmux.h" #include "tmux.h"
static struct screen *window_client_init(struct window_pane *, static struct screen *window_client_init(struct window_mode_entry *,
struct cmd_find_state *, struct args *); struct cmd_find_state *, struct args *);
static void window_client_free(struct window_pane *); static void window_client_free(struct window_mode_entry *);
static void window_client_resize(struct window_pane *, u_int, static void window_client_resize(struct window_mode_entry *, u_int,
u_int); u_int);
static void window_client_key(struct window_pane *, static void window_client_key(struct window_mode_entry *,
struct client *, struct session *, struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *); struct winlink *, key_code, struct mouse_event *);
@ -236,13 +236,14 @@ window_client_draw(__unused void *modedata, void *itemdata,
} }
static struct screen * static struct screen *
window_client_init(struct window_pane *wp, __unused struct cmd_find_state *fs, window_client_init(struct window_mode_entry *wme,
struct args *args) __unused struct cmd_find_state *fs, struct args *args)
{ {
struct window_pane *wp = wme->wp;
struct window_client_modedata *data; struct window_client_modedata *data;
struct screen *s; struct screen *s;
wp->modedata = data = xcalloc(1, sizeof *data); wme->data = data = xcalloc(1, sizeof *data);
if (args == NULL || !args_has(args, 'F')) if (args == NULL || !args_has(args, 'F'))
data->format = xstrdup(WINDOW_CLIENT_DEFAULT_FORMAT); data->format = xstrdup(WINDOW_CLIENT_DEFAULT_FORMAT);
@ -265,9 +266,9 @@ window_client_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
} }
static void static void
window_client_free(struct window_pane *wp) window_client_free(struct window_mode_entry *wme)
{ {
struct window_client_modedata *data = wp->modedata; struct window_client_modedata *data = wme->data;
u_int i; u_int i;
if (data == NULL) if (data == NULL)
@ -286,9 +287,9 @@ window_client_free(struct window_pane *wp)
} }
static void static void
window_client_resize(struct window_pane *wp, u_int sx, u_int sy) window_client_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
{ {
struct window_client_modedata *data = wp->modedata; struct window_client_modedata *data = wme->data;
mode_tree_resize(data->data, sx, sy); mode_tree_resize(data->data, sx, sy);
} }
@ -311,11 +312,12 @@ window_client_do_detach(void* modedata, void *itemdata,
} }
static void static void
window_client_key(struct window_pane *wp, struct client *c, window_client_key(struct window_mode_entry *wme, struct client *c,
__unused struct session *s, __unused struct winlink *wl, key_code key, __unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m) struct mouse_event *m)
{ {
struct window_client_modedata *data = wp->modedata; struct window_pane *wp = wme->wp;
struct window_client_modedata *data = wme->data;
struct mode_tree_data *mtd = data->data; struct mode_tree_data *mtd = data->data;
struct window_client_itemdata *item; struct window_client_itemdata *item;
int finished; int finished;

View File

@ -24,16 +24,16 @@
#include "tmux.h" #include "tmux.h"
static struct screen *window_clock_init(struct window_pane *, static struct screen *window_clock_init(struct window_mode_entry *,
struct cmd_find_state *, struct args *); struct cmd_find_state *, struct args *);
static void window_clock_free(struct window_pane *); static void window_clock_free(struct window_mode_entry *);
static void window_clock_resize(struct window_pane *, u_int, u_int); static void window_clock_resize(struct window_mode_entry *, u_int, u_int);
static void window_clock_key(struct window_pane *, struct client *, static void window_clock_key(struct window_mode_entry *, struct client *,
struct session *, struct winlink *, key_code, struct session *, struct winlink *, key_code,
struct mouse_event *); struct mouse_event *);
static void window_clock_timer_callback(int, short, void *); static void window_clock_timer_callback(int, short, void *);
static void window_clock_draw_screen(struct window_pane *); static void window_clock_draw_screen(struct window_mode_entry *);
const struct window_mode window_clock_mode = { const struct window_mode window_clock_mode = {
.name = "clock-mode", .name = "clock-mode",
@ -126,8 +126,9 @@ const char window_clock_table[14][5][5] = {
static void static void
window_clock_timer_callback(__unused int fd, __unused short events, void *arg) window_clock_timer_callback(__unused int fd, __unused short events, void *arg)
{ {
struct window_pane *wp = arg; struct window_mode_entry *wme = arg;
struct window_clock_mode_data *data = wp->modedata; struct window_pane *wp = wme->wp;
struct window_clock_mode_data *data = wme->data;
struct tm now, then; struct tm now, then;
time_t t; time_t t;
struct timeval tv = { .tv_sec = 1 }; struct timeval tv = { .tv_sec = 1 };
@ -142,37 +143,38 @@ window_clock_timer_callback(__unused int fd, __unused short events, void *arg)
return; return;
data->tim = t; data->tim = t;
window_clock_draw_screen(wp); window_clock_draw_screen(wme);
server_redraw_window(wp->window); server_redraw_window(wp->window);
} }
static struct screen * static struct screen *
window_clock_init(struct window_pane *wp, __unused struct cmd_find_state *fs, window_clock_init(struct window_mode_entry *wme,
__unused struct args *args) __unused struct cmd_find_state *fs, __unused struct args *args)
{ {
struct window_pane *wp = wme->wp;
struct window_clock_mode_data *data; struct window_clock_mode_data *data;
struct screen *s; struct screen *s;
struct timeval tv = { .tv_sec = 1 }; struct timeval tv = { .tv_sec = 1 };
wp->modedata = data = xmalloc(sizeof *data); wme->data = data = xmalloc(sizeof *data);
data->tim = time(NULL); data->tim = time(NULL);
evtimer_set(&data->timer, window_clock_timer_callback, wp); evtimer_set(&data->timer, window_clock_timer_callback, wme);
evtimer_add(&data->timer, &tv); evtimer_add(&data->timer, &tv);
s = &data->screen; s = &data->screen;
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0); screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
s->mode &= ~MODE_CURSOR; s->mode &= ~MODE_CURSOR;
window_clock_draw_screen(wp); window_clock_draw_screen(wme);
return (s); return (s);
} }
static void static void
window_clock_free(struct window_pane *wp) window_clock_free(struct window_mode_entry *wme)
{ {
struct window_clock_mode_data *data = wp->modedata; struct window_clock_mode_data *data = wme->data;
evtimer_del(&data->timer); evtimer_del(&data->timer);
screen_free(&data->screen); screen_free(&data->screen);
@ -180,27 +182,28 @@ window_clock_free(struct window_pane *wp)
} }
static void static void
window_clock_resize(struct window_pane *wp, u_int sx, u_int sy) window_clock_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
{ {
struct window_clock_mode_data *data = wp->modedata; struct window_clock_mode_data *data = wme->data;
struct screen *s = &data->screen; struct screen *s = &data->screen;
screen_resize(s, sx, sy, 0); screen_resize(s, sx, sy, 0);
window_clock_draw_screen(wp); window_clock_draw_screen(wme);
} }
static void static void
window_clock_key(struct window_pane *wp, __unused struct client *c, window_clock_key(struct window_mode_entry *wme, __unused struct client *c,
__unused struct session *s, __unused struct winlink *wl, __unused struct session *s, __unused struct winlink *wl,
__unused key_code key, __unused struct mouse_event *m) __unused key_code key, __unused struct mouse_event *m)
{ {
window_pane_reset_mode(wp); window_pane_reset_mode(wme->wp);
} }
static void static void
window_clock_draw_screen(struct window_pane *wp) window_clock_draw_screen(struct window_mode_entry *wme)
{ {
struct window_clock_mode_data *data = wp->modedata; struct window_pane *wp = wme->wp;
struct window_clock_mode_data *data = wme->data;
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
int colour, style; int colour, style;
struct screen *s = &data->screen; struct screen *s = &data->screen;

File diff suppressed because it is too large Load Diff

View File

@ -24,11 +24,12 @@
#include "tmux.h" #include "tmux.h"
static struct screen *window_tree_init(struct window_pane *, static struct screen *window_tree_init(struct window_mode_entry *,
struct cmd_find_state *, struct args *); struct cmd_find_state *, struct args *);
static void window_tree_free(struct window_pane *); static void window_tree_free(struct window_mode_entry *);
static void window_tree_resize(struct window_pane *, u_int, u_int); static void window_tree_resize(struct window_mode_entry *, u_int,
static void window_tree_key(struct window_pane *, u_int);
static void window_tree_key(struct window_mode_entry *,
struct client *, struct session *, struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *); struct winlink *, key_code, struct mouse_event *);
@ -810,13 +811,14 @@ window_tree_search(__unused void *modedata, void *itemdata, const char *ss)
} }
static struct screen * static struct screen *
window_tree_init(struct window_pane *wp, struct cmd_find_state *fs, window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs,
struct args *args) struct args *args)
{ {
struct window_pane *wp = wme->wp;
struct window_tree_modedata *data; struct window_tree_modedata *data;
struct screen *s; struct screen *s;
wp->modedata = data = xcalloc(1, sizeof *data); wme->data = data = xcalloc(1, sizeof *data);
if (args_has(args, 's')) if (args_has(args, 's'))
data->type = WINDOW_TREE_SESSION; data->type = WINDOW_TREE_SESSION;
@ -871,9 +873,9 @@ window_tree_destroy(struct window_tree_modedata *data)
} }
static void static void
window_tree_free(struct window_pane *wp) window_tree_free(struct window_mode_entry *wme)
{ {
struct window_tree_modedata *data = wp->modedata; struct window_tree_modedata *data = wme->data;
if (data == NULL) if (data == NULL)
return; return;
@ -884,9 +886,9 @@ window_tree_free(struct window_pane *wp)
} }
static void static void
window_tree_resize(struct window_pane *wp, u_int sx, u_int sy) window_tree_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
{ {
struct window_tree_modedata *data = wp->modedata; struct window_tree_modedata *data = wme->data;
mode_tree_resize(data->data, sx, sy); mode_tree_resize(data->data, sx, sy);
} }
@ -1119,11 +1121,12 @@ window_tree_mouse(struct window_tree_modedata *data, key_code key, u_int x,
} }
static void static void
window_tree_key(struct window_pane *wp, struct client *c, window_tree_key(struct window_mode_entry *wme, struct client *c,
__unused struct session *s, __unused struct winlink *wl, key_code key, __unused struct session *s, __unused struct winlink *wl, key_code key,
struct mouse_event *m) struct mouse_event *m)
{ {
struct window_tree_modedata *data = wp->modedata; struct window_pane *wp = wme->wp;
struct window_tree_modedata *data = wme->data;
struct window_tree_itemdata *item, *new_item; struct window_tree_itemdata *item, *new_item;
char *name, *prompt = NULL; char *name, *prompt = NULL;
struct cmd_find_state fs; struct cmd_find_state fs;

View File

@ -811,7 +811,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->event = NULL; wp->event = NULL;
wp->mode = NULL; wp->mode = NULL;
wp->modeprefix = 1;
wp->layout_cell = NULL; wp->layout_cell = NULL;
@ -1054,8 +1053,8 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
wp->sy = sy; wp->sy = sy;
screen_resize(&wp->base, sx, sy, wp->saved_grid == NULL); screen_resize(&wp->base, sx, sy, wp->saved_grid == NULL);
if (wp->mode != NULL) if (wp->mode != NULL && wp->mode->mode->resize != NULL)
wp->mode->resize(wp, sx, sy); wp->mode->mode->resize(wp->mode, sx, sy);
wp->flags |= PANE_RESIZE; wp->flags |= PANE_RESIZE;
} }
@ -1222,13 +1221,17 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode,
if (wp->mode != NULL) if (wp->mode != NULL)
return (1); return (1);
wp->mode = mode;
wp->mode = xcalloc(1, sizeof *wp->mode);
wp->mode->wp = wp;
wp->mode->mode = mode;
wp->mode->prefix = 1;
wp->modelast = time(NULL); wp->modelast = time(NULL);
evtimer_set(&wp->modetimer, window_pane_mode_timer, wp); evtimer_set(&wp->modetimer, window_pane_mode_timer, wp);
evtimer_add(&wp->modetimer, &tv); evtimer_add(&wp->modetimer, &tv);
if ((s = wp->mode->init(wp, fs, args)) != NULL) if ((s = wp->mode->mode->init(wp->mode, fs, args)) != NULL)
wp->screen = s; wp->screen = s;
wp->flags |= (PANE_REDRAW|PANE_CHANGED); wp->flags |= (PANE_REDRAW|PANE_CHANGED);
@ -1245,9 +1248,9 @@ window_pane_reset_mode(struct window_pane *wp)
evtimer_del(&wp->modetimer); evtimer_del(&wp->modetimer);
wp->mode->free(wp); wp->mode->mode->free(wp->mode);
free(wp->mode);
wp->mode = NULL; wp->mode = NULL;
wp->modeprefix = 1;
wp->screen = &wp->base; wp->screen = &wp->base;
wp->flags |= (PANE_REDRAW|PANE_CHANGED); wp->flags |= (PANE_REDRAW|PANE_CHANGED);
@ -1260,15 +1263,16 @@ void
window_pane_key(struct window_pane *wp, struct client *c, struct session *s, window_pane_key(struct window_pane *wp, struct client *c, struct session *s,
struct winlink *wl, key_code key, struct mouse_event *m) struct winlink *wl, key_code key, struct mouse_event *m)
{ {
struct window_pane *wp2; struct window_mode_entry *wme = wp->mode;
struct window_pane *wp2;
if (KEYC_IS_MOUSE(key) && m == NULL) if (KEYC_IS_MOUSE(key) && m == NULL)
return; return;
if (wp->mode != NULL) { if (wme != NULL) {
wp->modelast = time(NULL); wp->modelast = time(NULL);
if (wp->mode->key != NULL) if (wme->mode->key != NULL)
wp->mode->key(wp, c, s, wl, (key & ~KEYC_XTERM), m); wme->mode->key(wme, c, s, wl, (key & ~KEYC_XTERM), m);
return; return;
} }