aboutsummaryrefslogtreecommitdiff
path: root/grid.h
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-04-25 17:57:18 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-04-25 17:57:18 +0000
commitb4f666118febfc95bf97e31aa1e39e3df9522dfa (patch)
treebd74ce90720d1e57b9fb9f115f6758bf500fe818 /grid.h
parentinput: assert serial received from compositor is non-zero (diff)
grid: add abs-to-sb and sb-to-abs utility function
These functions convert row numbers between absolute coordinates and “scrollback relative” coordinates. Absolute row numbers can be used to index into the grid->rows[] array. Scrollback relative numbers are ordered with the *oldest* row first, and the *newest* row last. That is, in these coordinates, row 0 is the *first* (oldest) row in the scrollback history, and row N is the *last* (newest) row. Scrollback relative numbers are used when we need to sort things after their age, when determining if something has scrolled out, or when limiting an operation to ensure we don’t go past the scrollback wrap-around.
Diffstat (limited to 'grid.h')
-rw-r--r--grid.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/grid.h b/grid.h
index 7819db4d..22bd76bb 100644
--- a/grid.h
+++ b/grid.h
@@ -21,6 +21,10 @@ void grid_resize_and_reflow(
size_t tracking_points_count,
struct coord *const _tracking_points[static tracking_points_count]);
+/* Convert row numbers between scrollback-relative and absolute coordinates */
+int grid_row_abs_to_sb(const struct grid *grid, int screen_rows, int abs_row);
+int grid_row_sb_to_abs(const struct grid *grid, int screen_rows, int sb_rel_row);
+
static inline int
grid_row_absolute(const struct grid *grid, int row_no)
{
@@ -33,6 +37,7 @@ grid_row_absolute_in_view(const struct grid *grid, int row_no)
return (grid->view + row_no) & (grid->num_rows - 1);
}
+
static inline struct row *
_grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null)
{