From 3bb880bf207b40bc0cddcb9c449a738861e6791b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 17 Jul 2016 11:26:38 -0400 Subject: Implement configurable wrapping on bar ws scroll --- swaybar/bar.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'swaybar/bar.c') diff --git a/swaybar/bar.c b/swaybar/bar.c index 9009e1ff..41538052 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -96,6 +96,37 @@ static void mouse_button_notify(struct window *window, int x, int y, 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"); + if (!swaybar.config->wrap_scroll) { + // Find output this window lives on + int i; + struct output *output; + for (i = 0; i < swaybar.outputs->length; ++i) { + output = swaybar.outputs->items[i]; + if (output->window == window) { + break; + } + } + if (!sway_assert(i != swaybar.outputs->length, "Unknown window in scroll event")) { + return; + } + int focused = -1; + for (i = 0; i < output->workspaces->length; ++i) { + struct workspace *ws = output->workspaces->items[i]; + if (ws->focused) { + focused = i; + break; + } + } + if (!sway_assert(focused != -1, "Scroll wheel event received on inactive output")) { + return; + } + if ((focused == 0 && direction == SCROLL_UP) || + (focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) { + // Do not wrap + return; + } + } + const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output"; ipc_send_workspace_command(workspace_name); } -- cgit v1.2.3-54-g00ecf