aboutsummaryrefslogtreecommitdiff
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-07-17 11:26:38 -0400
committerDrew DeVault <sir@cmpwn.com>2016-07-17 11:26:38 -0400
commit3bb880bf207b40bc0cddcb9c449a738861e6791b (patch)
tree66ed13164fef27ebf3c8a6106590f1b7ec432483 /swaybar/bar.c
parenta9767ad2f742dc37896b3cae07d3ced80df28682 (diff)
Implement configurable wrapping on bar ws scroll
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c31
1 files changed, 31 insertions, 0 deletions
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);
}