From f4cc117e896e4e973bade3581abbe694081be813 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 21 Oct 2024 12:39:49 +0000 Subject: [PATCH] Add function to get current offset from copy mode, from Michael Grant. --- usr.bin/tmux/tmux.h | 4 +++- usr.bin/tmux/window-copy.c | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 1f6e4c4d9c2..3e20243c4e8 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1234 2024/10/07 08:50:47 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1235 2024/10/21 12:39:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3245,6 +3245,8 @@ void window_copy_pagedown(struct window_pane *, int, int); void window_copy_start_drag(struct client *, struct mouse_event *); char *window_copy_get_word(struct window_pane *, u_int, u_int); char *window_copy_get_line(struct window_pane *, u_int); +int window_copy_get_current_offset(struct window_pane *, u_int *, + u_int *); /* window-option.c */ extern const struct window_mode window_customize_mode; diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 6e290315c70..3129bf146ee 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.357 2024/10/05 00:35:35 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.358 2024/10/21 12:39:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -4188,6 +4188,23 @@ window_copy_write_one(struct window_mode_entry *wme, } } +int +window_copy_get_current_offset(struct window_pane *wp, u_int *offset, + u_int *size) +{ + struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); + struct window_copy_mode_data *data = wme->data; + u_int hsize; + + if (data == NULL) + return (0); + hsize = screen_hsize(data->backing); + + *offset = hsize - data->oy; + *size = hsize; + return (1); +} + static void window_copy_write_line(struct window_mode_entry *wme, struct screen_write_ctx *ctx, u_int py) -- 2.20.1