sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit c0b7610c264b36de46e12189cb622a597c5b000b
parent 250ddc66c672f62a3c7f44db73b5c4d0661093ba
Author: David Eklov <david.eklov@gmail.com>
Date:   Mon, 11 Jul 2016 23:15:23 -0500

Enable windows to register to get notified when the mouse wheel is scrolled

Diffstat:
Minclude/client/window.h | 9+++++++++
Mwayland/window.c | 21++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/client/window.h b/include/client/window.h @@ -27,11 +27,20 @@ struct cursor { struct wl_poitner *pointer; }; +enum scroll_direction { + SCROLL_UP, + SCROLL_DOWN, + SCROLL_LEFT, + SCROLL_RIGHT, +}; + struct pointer_input { int last_x; int last_y; void (*notify_button)(struct window *window, int x, int y, uint32_t button); + + void (*notify_scroll)(struct window *window, enum scroll_direction direction); }; struct window { diff --git a/wayland/window.c b/wayland/window.c @@ -47,7 +47,26 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32 } static void pointer_handle_axis(void *data, struct wl_pointer *pointer, - uint32_t time, uint32_t axis, wl_fixed_t value) { + uint32_t time, uint32_t axis, wl_fixed_t value) { + struct window *window = data; + enum scroll_direction direction; + + switch (axis) { + case 0: + direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN; + break; + case 1: + direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT; + break; + default: + if (!sway_assert(false, "Unexpected axis value")) { + return; + } + } + + if (window->pointer_input.notify_scroll) { + window->pointer_input.notify_scroll(window, direction); + } } static const struct wl_pointer_listener pointer_listener = {