aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-10 07:15:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-10 07:15:37 +0000
commitb058e6384ab5349cbf78bf471d581a83f531e30a (patch)
tree63432eb19230edb3ab83fe5677652d0800c59bb3
parentwip: initial scroll back support (diff)
scrollback: initial support for mouse scrolling
-rw-r--r--commands.c34
-rw-r--r--commands.h4
-rw-r--r--input.c16
3 files changed, 41 insertions, 13 deletions
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