aboutsummaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-26 16:47:56 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-26 16:48:59 +0000
commite88cf4c8c88c63eef66fcc8bc00e27903562a49d (patch)
treee1e4c404e08241aeb46516c48b542eee80127b33 /input.c
parentrender: add render_row() (diff)
mouse: use discrete axis event if available
This improves the scroll experience with certain devices
Diffstat (limited to 'input.c')
-rw-r--r--input.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/input.c b/input.c
index 6112be86..93bdc9fd 100644
--- a/input.c
+++ b/input.c
@@ -411,36 +411,53 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
}
static void
+mouse_scroll(struct terminal *term, int amount)
+{
+ int button = amount < 0 ? BTN_BACK : BTN_FORWARD;
+
+ void (*scrollback)(struct terminal *term, int rows)
+ = amount < 0 ? &cmd_scrollback_up : &cmd_scrollback_down;
+
+ amount = abs(amount);
+
+ for (int i = 0; i < amount; i++)
+ term_mouse_down(term, button, term->mouse.row, term->mouse.col,
+ term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
+
+ scrollback(term, amount);
+}
+
+static void
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
+ if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
+ return;
+
struct terminal *term = data;
+ if (term->mouse.have_discrete)
+ return;
- /* TODO: generate button event for BTN_FORWARD/BTN_BACK? */
+ mouse_scroll(term, wl_fixed_to_int(value));
+}
+static void
+wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
+ uint32_t axis, int32_t discrete)
+{
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
return;
- int amount = wl_fixed_to_int(value);
-
- 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 {
- 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);
- }
+ struct terminal *term = data;
+ term->mouse.have_discrete = true;
+ mouse_scroll(term, discrete);
}
static void
wl_pointer_frame(void *data, struct wl_pointer *wl_pointer)
{
+ struct terminal *term = data;
+ term->mouse.have_discrete = false;
}
static void
@@ -455,12 +472,6 @@ wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
{
}
-static void
-wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
- uint32_t axis, int32_t discrete)
-{
-}
-
const struct wl_pointer_listener pointer_listener = {
.enter = wl_pointer_enter,
.leave = wl_pointer_leave,