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... --- input.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 4ac45bbe..a7aba971 100644 --- a/input.c +++ b/input.c @@ -17,6 +17,7 @@ #include "terminal.h" #include "render.h" #include "keymap.h" +#include "commands.h" static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, @@ -140,6 +141,18 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, keymap_mods |= term->kbd.alt ? MOD_ALT : MOD_NONE; keymap_mods |= term->kbd.ctrl ? MOD_CTRL : MOD_NONE; + if (effective_mods == shift) { + if (sym == XKB_KEY_Page_Up) { + cmd_scrollback_up(term); + found_map = true; + } + + else if (sym == XKB_KEY_Page_Down) { + cmd_scrollback_down(term); + found_map = true; + } + } + for (size_t i = 0; i < sizeof(key_map) / sizeof(key_map[0]) && !found_map; i++) { const struct key_map *k = &key_map[i]; if (k->sym != sym) @@ -160,6 +173,13 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, write(term->ptmx, info->seq, strlen(info->seq)); found_map = true; + + if (term->grid->view != term->grid->offset) { + term->grid->view = term->grid->offset; + /* TODO: damage view */ + term_damage_all(term); + } + break; } } @@ -182,6 +202,13 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, write(term->ptmx, "\x1b", 1); write(term->ptmx, buf, count); + + if (term->grid->view != term->grid->offset) { + term->grid->view = term->grid->offset; + /* TODO: damage view */ + term_damage_all(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 'input.c') 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 From 7594edb89bef777b02177b7c82f7231fac4e2528 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 10 Jul 2019 14:17:44 +0200 Subject: input: generate BTN_BACK/BTN_FORWARD mouse down events when scrolling --- input.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f9e7f92b..33547fcd 100644 --- a/input.c +++ b/input.c @@ -7,6 +7,8 @@ #include #include +#include + #include #include #include @@ -350,10 +352,20 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, return; int amount = wl_fixed_to_int(value); - if (amount < 0) + + if (amount < 0) { + for (int i = 0; i < -amount; i++) { + term_mouse_down(term, BTN_BACK, term->mouse.row, term->mouse.col, + term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + } cmd_scrollback_up(term, -amount); - else + } else { + for (int i = 0; i < amount; i++) { + term_mouse_down(term, BTN_FORWARD, term->mouse.row, term->mouse.col, + term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + } cmd_scrollback_down(term, amount); + } } static void -- cgit v1.3