diff options
-rw-r--r-- | include/client/window.h | 9 | ||||
-rw-r--r-- | wayland/window.c | 21 |
2 files changed, 29 insertions, 1 deletions
diff --git a/include/client/window.h b/include/client/window.h index 98d19a2b..e07e3509 100644 --- a/include/client/window.h +++ b/include/client/window.h | |||
@@ -27,11 +27,20 @@ struct cursor { | |||
27 | struct wl_poitner *pointer; | 27 | struct wl_poitner *pointer; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | enum scroll_direction { | ||
31 | SCROLL_UP, | ||
32 | SCROLL_DOWN, | ||
33 | SCROLL_LEFT, | ||
34 | SCROLL_RIGHT, | ||
35 | }; | ||
36 | |||
30 | struct pointer_input { | 37 | struct pointer_input { |
31 | int last_x; | 38 | int last_x; |
32 | int last_y; | 39 | int last_y; |
33 | 40 | ||
34 | void (*notify_button)(struct window *window, int x, int y, uint32_t button); | 41 | void (*notify_button)(struct window *window, int x, int y, uint32_t button); |
42 | |||
43 | void (*notify_scroll)(struct window *window, enum scroll_direction direction); | ||
35 | }; | 44 | }; |
36 | 45 | ||
37 | struct window { | 46 | struct window { |
diff --git a/wayland/window.c b/wayland/window.c index 2a76654b..dfa6a997 100644 --- a/wayland/window.c +++ b/wayland/window.c | |||
@@ -47,7 +47,26 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32 | |||
47 | } | 47 | } |
48 | 48 | ||
49 | static void pointer_handle_axis(void *data, struct wl_pointer *pointer, | 49 | static void pointer_handle_axis(void *data, struct wl_pointer *pointer, |
50 | uint32_t time, uint32_t axis, wl_fixed_t value) { | 50 | uint32_t time, uint32_t axis, wl_fixed_t value) { |
51 | struct window *window = data; | ||
52 | enum scroll_direction direction; | ||
53 | |||
54 | switch (axis) { | ||
55 | case 0: | ||
56 | direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN; | ||
57 | break; | ||
58 | case 1: | ||
59 | direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT; | ||
60 | break; | ||
61 | default: | ||
62 | if (!sway_assert(false, "Unexpected axis value")) { | ||
63 | return; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | if (window->pointer_input.notify_scroll) { | ||
68 | window->pointer_input.notify_scroll(window, direction); | ||
69 | } | ||
51 | } | 70 | } |
52 | 71 | ||
53 | static const struct wl_pointer_listener pointer_listener = { | 72 | static const struct wl_pointer_listener pointer_listener = { |