aboutsummaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-10-12 18:20:26 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-10-12 18:20:26 +0000
commitd75e50230eb91b87bf6880177bd9fe32ab964140 (patch)
treec0ad7e70f744f80bb7023da957d1ba141ae859f5 /input.c
parentMerge branch 'releases/1.5' into master (diff)
parentselection: auto-scroll: call cmd_scrollback_{up,down}() with number of rows (diff)
Merge branch 'scroll-up-down-while-selecting' into master
Closes #149
Diffstat (limited to 'input.c')
-rw-r--r--input.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/input.c b/input.c
index 20c1381c..f3993978 100644
--- a/input.c
+++ b/input.c
@@ -1325,10 +1325,46 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
= old_col != seat->mouse.col || old_row != seat->mouse.row;
/* Cursor is inside the grid, i.e. *not* in the margins */
- bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0;
+ const bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0;
+
+ enum selection_scroll_direction auto_scroll_direction
+ = y < term->margins.top ? SELECTION_SCROLL_UP
+ : y > term->height - term->margins.bottom ? SELECTION_SCROLL_DOWN
+ : SELECTION_SCROLL_NOT;
+
+ if (auto_scroll_direction == SELECTION_SCROLL_NOT)
+ selection_stop_scroll_timer(term);
/* Update selection */
if (!term->is_searching) {
+ if (auto_scroll_direction != SELECTION_SCROLL_NOT) {
+ /*
+ * Start ‘selection auto-scrolling’
+ *
+ * The speed of the scrolling is proportional to the
+ * distance between the mouse and the grid; the
+ * further away the mouse is, the faster we scroll.
+ *
+ * Note that the speed is measured in ‘intervals (in
+ * ns) between each timed scroll of a single line’.
+ *
+ * Thus, the further away the mouse is, the smaller
+ * interval value we use.
+ */
+
+ int distance = auto_scroll_direction == SELECTION_SCROLL_UP
+ ? term->margins.top - y
+ : y - (term->height - term->margins.bottom);
+
+ assert(distance > 0);
+ int divisor
+ = distance * term->conf->scrollback.multiplier / term->scale;
+
+ selection_start_scroll_timer(
+ term, 400000000 / (divisor > 0 ? divisor : 1),
+ auto_scroll_direction, selection_col);
+ }
+
if (cursor_is_on_new_cell || term->selection.end.row < 0)
selection_update(term, selection_col, selection_row);
}