diff options
author | Magnus Hoff <maghoff@gmail.com> | 2014-08-05 15:05:59 +0200 |
---|---|---|
committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2014-08-15 16:06:05 +0300 |
commit | 1046f121f774e9248260d2bdd244eca111773426 (patch) | |
tree | ec4d163009e6d2d0f8ddd59380f72bab5548569c | |
parent | 45ee1f9ef7fab76c3287ab6f6a695357107b5f87 (diff) | |
download | weston-1046f121f774e9248260d2bdd244eca111773426.tar.gz |
Implemented support for mouse scrolling in weston-terminal
[Pekka Paalanen: fixed some code style issues]
-rw-r--r-- | clients/terminal.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/clients/terminal.c b/clients/terminal.c index eb133cd9..0bacbe09 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -447,6 +447,7 @@ struct terminal { int width, height, row, column, max_width; uint32_t buffer_height; uint32_t start, end, saved_start, log_size; + wl_fixed_t smooth_scroll; int saved_row, saved_column; int scrolling; int send_cursor_position; @@ -2785,6 +2786,55 @@ motion_handler(struct widget *widget, return CURSOR_IBEAM; } +/* This magnitude is chosen rather arbitrarily. Really, the scrolling + * should happen on a (fractional) pixel basis, not a line basis. */ +#define AXIS_UNITS_PER_LINE 256 + +static void +axis_handler(struct widget *widget, + struct input *input, uint32_t time, + uint32_t axis, + wl_fixed_t value, + void *data) +{ + struct terminal *terminal = data; + int lines; + + if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) + return; + + terminal->smooth_scroll += value; + lines = terminal->smooth_scroll / AXIS_UNITS_PER_LINE; + terminal->smooth_scroll -= lines * AXIS_UNITS_PER_LINE; + + if (lines > 0) { + if (terminal->scrolling) { + if ((uint32_t)lines > terminal->saved_start - terminal->start) + lines = terminal->saved_start - terminal->start; + } else { + lines = 0; + } + } else if (lines < 0) { + uint32_t neg_lines = -lines; + + if (neg_lines > terminal->log_size + terminal->start - terminal->end) + lines = terminal->end - terminal->log_size - terminal->start; + } + + if (lines) { + if (!terminal->scrolling) + terminal->saved_start = terminal->start; + terminal->scrolling = 1; + + terminal->start += lines; + terminal->row -= lines; + terminal->selection_start_row -= lines; + terminal->selection_end_row -= lines; + + widget_schedule_redraw(widget); + } +} + static void output_handler(struct window *window, struct output *output, int enter, void *data) @@ -2880,6 +2930,7 @@ terminal_create(struct display *display) widget_set_button_handler(terminal->widget, button_handler); widget_set_enter_handler(terminal->widget, enter_handler); widget_set_motion_handler(terminal->widget, motion_handler); + widget_set_axis_handler(terminal->widget, axis_handler); widget_set_touch_up_handler(terminal->widget, touch_up_handler); widget_set_touch_down_handler(terminal->widget, touch_down_handler); widget_set_touch_motion_handler(terminal->widget, touch_motion_handler); |