diff options
-rw-r--r-- | include/client/window.h | 11 | ||||
-rw-r--r-- | swaybar/bar.c | 12 | ||||
-rw-r--r-- | wayland/window.c | 25 |
3 files changed, 42 insertions, 6 deletions
diff --git a/include/client/window.h b/include/client/window.h index 55a12225..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)(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/swaybar/bar.c b/swaybar/bar.c index 4f8063ac..82e136e4 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -89,6 +89,13 @@ static void mouse_button_notify(struct window *window, int x, int y, uint32_t bu | |||
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { | ||
93 | sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); | ||
94 | |||
95 | const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output"; | ||
96 | ipc_send_workspace_command(workspace_name); | ||
97 | } | ||
98 | |||
92 | void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | 99 | void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { |
93 | /* initialize bar with default values */ | 100 | /* initialize bar with default values */ |
94 | bar_init(bar); | 101 | bar_init(bar); |
@@ -123,8 +130,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
123 | /* set font */ | 130 | /* set font */ |
124 | bar_output->window->font = bar->config->font; | 131 | bar_output->window->font = bar->config->font; |
125 | 132 | ||
126 | /* set font */ | 133 | /* set mouse event callbacks */ |
127 | bar_output->window->pointer_input.notify = mouse_button_notify; | 134 | bar_output->window->pointer_input.notify_button = mouse_button_notify; |
135 | bar_output->window->pointer_input.notify_scroll = mouse_scroll_notify; | ||
128 | 136 | ||
129 | /* set window height */ | 137 | /* set window height */ |
130 | set_window_height(bar_output->window, bar->config->height); | 138 | set_window_height(bar_output->window, bar->config->height); |
diff --git a/wayland/window.c b/wayland/window.c index 9b6e5b00..dfa6a997 100644 --- a/wayland/window.c +++ b/wayland/window.c | |||
@@ -41,13 +41,32 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32 | |||
41 | struct window *window = data; | 41 | struct window *window = data; |
42 | struct pointer_input *input = &window->pointer_input; | 42 | struct pointer_input *input = &window->pointer_input; |
43 | 43 | ||
44 | if (window->pointer_input.notify) { | 44 | if (window->pointer_input.notify_button) { |
45 | window->pointer_input.notify(window, input->last_x, input->last_y, button); | 45 | window->pointer_input.notify_button(window, input->last_x, input->last_y, button); |
46 | } | 46 | } |
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 = { |