From bcd111d203f9e421b43e4e31fc750b0515b10d61 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 9 Jul 2019 16:26:36 +0200 Subject: wip: initial scroll back support Can scroll up and down, and stops when the beginning/end of history is reached. However, it probably breaks when the entire scrollback buffer has been filled - we need to detect when the view has wrapped around to the current terminal offset. The detection of when we've reached the bottom of the history is also flawed, and only works when we overshoot the bottom with at least a page. Resizing the windows while in a view most likely doesn't work. The view will not detect a wrapped around scrollback buffer. I.e. if the user has scrolled back, and is stationary at a view, but there is still output being produced. Then eventually the scrollback buffer will wrap around. In this case, the correct thing to do is make the view start following the beginning of the history. Right now it doesn't, meaning once the scrollback buffer wraps around, you'll start seeing command output... --- commands.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 commands.h (limited to 'commands.h') diff --git a/commands.h b/commands.h new file mode 100644 index 00000000..865cd83f --- /dev/null +++ b/commands.h @@ -0,0 +1,6 @@ +#pragma once + +#include "terminal.h" + +void cmd_scrollback_up(struct terminal *term); +void cmd_scrollback_down(struct terminal *term); -- cgit v1.3 From b058e6384ab5349cbf78bf471d581a83f531e30a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 10 Jul 2019 09:15:37 +0200 Subject: scrollback: initial support for mouse scrolling --- commands.c | 34 +++++++++++++++++++++++++--------- commands.h | 4 ++-- input.c | 16 ++++++++++++++-- 3 files changed, 41 insertions(+), 13 deletions(-) (limited to 'commands.h') diff --git a/commands.c b/commands.c index dea9b36e..47bbb4a8 100644 --- a/commands.c +++ b/commands.c @@ -10,15 +10,19 @@ #define max(x, y) ((x) > (y) ? (x) : (y)) void -cmd_scrollback_up(struct terminal *term) +cmd_scrollback_up(struct terminal *term, int rows) { + if (term->grid == &term->alt) + return; + assert(term->grid->offset >= 0); - int new_view = (term->grid->view + term->grid->num_rows - term->rows) % term->grid->num_rows; + int new_view = (term->grid->view + term->grid->num_rows - rows) % term->grid->num_rows; LOG_WARN("%d" ,new_view); assert(new_view >= 0); assert(new_view < term->grid->num_rows); + /* Avoid scrolling in uninitialized rows */ while (!term->grid->rows[new_view]->initialized) new_view = (new_view + 1) % term->grid->num_rows; @@ -34,20 +38,32 @@ cmd_scrollback_up(struct terminal *term) } void -cmd_scrollback_down(struct terminal *term) +cmd_scrollback_down(struct terminal *term, int rows) { + if (term->grid == &term->alt) + return; + assert(term->grid->offset >= 0); - int new_view = (term->grid->view + term->rows) % term->grid->num_rows; + int new_view = (term->grid->view + rows) % term->grid->num_rows; LOG_WARN("%d" ,new_view); assert(new_view >= 0); assert(new_view < term->grid->num_rows); - if (!term->grid->rows[new_view]->initialized) { - while (!term->grid->rows[new_view]->initialized) - new_view = (new_view + term->grid->num_rows - 1) % term->grid->num_rows; - new_view = (new_view + term->grid->num_rows - term->rows + 1) % term->grid->num_rows; - } + /* Prevent scrolling in uninitialized rows */ + bool all_initialized = false; + do { + all_initialized = true; + + for (int i = 0; i < term->rows; i++) { + int row_no = (new_view + i) % term->grid->num_rows; + if (!term->grid->rows[row_no]->initialized) { + all_initialized = false; + new_view--; + break; + } + } + } while (!all_initialized); LOG_DBG("scrollback DOWN: %d -> %d (offset = %d, rows = %d)", term->grid->view, new_view, term->grid->offset, term->grid->num_rows); diff --git a/commands.h b/commands.h index 865cd83f..644523b0 100644 --- a/commands.h +++ b/commands.h @@ -2,5 +2,5 @@ #include "terminal.h" -void cmd_scrollback_up(struct terminal *term); -void cmd_scrollback_down(struct terminal *term); +void cmd_scrollback_up(struct terminal *term, int rows); +void cmd_scrollback_down(struct terminal *term, int rows); diff --git a/input.c b/input.c index a7aba971..f9e7f92b 100644 --- a/input.c +++ b/input.c @@ -143,12 +143,12 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, if (effective_mods == shift) { if (sym == XKB_KEY_Page_Up) { - cmd_scrollback_up(term); + cmd_scrollback_up(term, term->rows); found_map = true; } else if (sym == XKB_KEY_Page_Down) { - cmd_scrollback_down(term); + cmd_scrollback_down(term, term->rows); found_map = true; } } @@ -342,6 +342,18 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { + struct terminal *term = data; + + /* TODO: generate button event for BTN_FORWARD/BTN_BACK? */ + + if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) + return; + + int amount = wl_fixed_to_int(value); + if (amount < 0) + cmd_scrollback_up(term, -amount); + else + cmd_scrollback_down(term, amount); } static void -- cgit v1.3