From 7f093fcddcf82c01b6c4d1446af2ebfac5d8a686 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 7 Mar 2019 19:01:21 +0000 Subject: [PATCH] Make adding mode formats a function pointer as well. --- format.c | 3 ++- tmux.h | 4 ++-- window-copy.c | 27 +++++++++++++-------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/format.c b/format.c index 77f5f59d..f60a4019 100644 --- a/format.c +++ b/format.c @@ -1552,7 +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_lower", "%u", wp->base.rlower); - window_copy_add_formats(wp, ft); + if (wp->mode != NULL && wp->mode->formats != NULL) + wp->mode->formats(wp, ft); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); format_add(ft, "alternate_saved_x", "%u", wp->saved_cx); diff --git a/tmux.h b/tmux.h index 44d5fbcc..f0ee838e 100644 --- a/tmux.h +++ b/tmux.h @@ -43,6 +43,7 @@ struct cmdq_item; struct cmdq_list; struct environ; struct format_job_tree; +struct format_tree; struct input_ctx; struct job; struct mode_tree_data; @@ -707,6 +708,7 @@ struct window_mode { void (*command)(struct window_pane *, struct client *, struct session *, struct winlink *, struct args *, struct mouse_event *); + void (*formats)(struct window_pane *, struct format_tree *); }; #define WINDOW_MODE_TIMEOUT 180 @@ -2304,8 +2306,6 @@ void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...); void window_copy_vadd(struct window_pane *, const char *, va_list); void window_copy_pageup(struct window_pane *, int); void window_copy_start_drag(struct client *, struct mouse_event *); -void window_copy_add_formats(struct window_pane *, - struct format_tree *); /* names.c */ void check_window_name(struct window *); diff --git a/window-copy.c b/window-copy.c index 65b29df0..ed36efc0 100644 --- a/window-copy.c +++ b/window-copy.c @@ -31,10 +31,11 @@ static void window_copy_command(struct window_pane *, struct client *, static struct screen *window_copy_init(struct window_pane *, struct cmd_find_state *, struct args *); static void window_copy_free(struct window_pane *); +static void window_copy_resize(struct window_pane *, u_int, u_int); +static void window_copy_formats(struct window_pane *, struct format_tree *); static int window_copy_pagedown(struct window_pane *, int, int); static void window_copy_next_paragraph(struct window_pane *); static void window_copy_previous_paragraph(struct window_pane *); -static void window_copy_resize(struct window_pane *, u_int, u_int); static void window_copy_redraw_selection(struct window_pane *, u_int); static void window_copy_redraw_lines(struct window_pane *, u_int, u_int); @@ -113,6 +114,7 @@ const struct window_mode window_copy_mode = { .resize = window_copy_resize, .key_table = window_copy_key_table, .command = window_copy_command, + .formats = window_copy_formats, }; enum { @@ -472,6 +474,16 @@ window_copy_next_paragraph(struct window_pane *wp) window_copy_scroll_to(wp, ox, oy); } +static void +window_copy_formats(struct window_pane *wp, struct format_tree *ft) +{ + struct window_copy_mode_data *data = wp->modedata; + + format_add(ft, "selection_present", "%d", data->screen.sel != NULL); + format_add(ft, "scroll_position", "%d", data->oy); + format_add(ft, "rectangle_toggle", "%d", data->rectflag); +} + static void window_copy_resize(struct window_pane *wp, u_int sx, u_int sy) { @@ -2447,19 +2459,6 @@ window_copy_scroll_down(struct window_pane *wp, u_int ny) screen_write_stop(&ctx); } -void -window_copy_add_formats(struct window_pane *wp, struct format_tree *ft) -{ - struct window_copy_mode_data *data = wp->modedata; - - if (wp->mode != &window_copy_mode) - return; - - format_add(ft, "selection_present", "%d", data->screen.sel != NULL); - format_add(ft, "scroll_position", "%d", data->oy); - format_add(ft, "rectangle_toggle", "%d", data->rectflag); -} - static void window_copy_rectangle_toggle(struct window_pane *wp) {