From 250ddc66c672f62a3c7f44db73b5c4d0661093ba Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 11 Jul 2016 22:51:50 -0500 Subject: [PATCH 1/3] Rename pointer_input::notify to indicate that is called on button clicks --- include/client/window.h | 2 +- swaybar/bar.c | 2 +- wayland/window.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/client/window.h b/include/client/window.h index 55a122252..98d19a2b9 100644 --- a/include/client/window.h +++ b/include/client/window.h @@ -31,7 +31,7 @@ struct pointer_input { int last_x; int last_y; - void (*notify)(struct window *window, int x, int y, uint32_t button); + void (*notify_button)(struct window *window, int x, int y, uint32_t button); }; struct window { diff --git a/swaybar/bar.c b/swaybar/bar.c index 4f8063ac8..c0aa85c7b 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -124,7 +124,7 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { bar_output->window->font = bar->config->font; /* set font */ - bar_output->window->pointer_input.notify = mouse_button_notify; + bar_output->window->pointer_input.notify_button = mouse_button_notify; /* set window height */ set_window_height(bar_output->window, bar->config->height); diff --git a/wayland/window.c b/wayland/window.c index 9b6e5b00e..2a76654b7 100644 --- a/wayland/window.c +++ b/wayland/window.c @@ -41,8 +41,8 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32 struct window *window = data; struct pointer_input *input = &window->pointer_input; - if (window->pointer_input.notify) { - window->pointer_input.notify(window, input->last_x, input->last_y, button); + if (window->pointer_input.notify_button) { + window->pointer_input.notify_button(window, input->last_x, input->last_y, button); } } From c0b7610c264b36de46e12189cb622a597c5b000b Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 11 Jul 2016 23:15:23 -0500 Subject: [PATCH 2/3] Enable windows to register to get notified when the mouse wheel is scrolled --- include/client/window.h | 9 +++++++++ wayland/window.c | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/client/window.h b/include/client/window.h index 98d19a2b9..e07e3509e 100644 --- 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 index 2a76654b7..dfa6a9971 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 } 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 = { From e38d6b94b890b473141fb0d1cd3f4b3203ea7d81 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Tue, 12 Jul 2016 22:14:20 -0500 Subject: [PATCH 3/3] Change workspace when mouse wheel is scrolled while hovering over the bar --- swaybar/bar.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/swaybar/bar.c b/swaybar/bar.c index c0aa85c7b..82e136e4e 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 } } +static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { + sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); + + const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output"; + ipc_send_workspace_command(workspace_name); +} + void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { /* initialize bar with default values */ bar_init(bar); @@ -123,8 +130,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { /* set font */ bar_output->window->font = bar->config->font; - /* set font */ + /* set mouse event callbacks */ bar_output->window->pointer_input.notify_button = mouse_button_notify; + bar_output->window->pointer_input.notify_scroll = mouse_scroll_notify; /* set window height */ set_window_height(bar_output->window, bar->config->height);