diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-07-17 11:26:38 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-07-17 11:26:38 -0400 |
commit | 3bb880bf207b40bc0cddcb9c449a738861e6791b (patch) | |
tree | 66ed13164fef27ebf3c8a6106590f1b7ec432483 /swaybar | |
parent | a9767ad2f742dc37896b3cae07d3ced80df28682 (diff) |
Implement configurable wrapping on bar ws scroll
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 31 | ||||
-rw-r--r-- | swaybar/config.c | 1 | ||||
-rw-r--r-- | swaybar/ipc.c | 7 |
3 files changed, 38 insertions, 1 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); } diff --git a/swaybar/config.c b/swaybar/config.c index 7bd22c91..f3a3e716 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -53,6 +53,7 @@ struct config *init_config() { config->sep_symbol = NULL; config->strip_workspace_numbers = false; config->binding_mode_indicator = true; + config->wrap_scroll = false; config->workspace_buttons = true; config->all_outputs = false; config->outputs = create_list(); diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 15f40508..ad4f9ef8 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -19,7 +19,7 @@ void ipc_send_workspace_command(const char *workspace_name) { static void ipc_parse_config(struct config *config, const char *payload) { json_object *bar_config = json_tokener_parse(payload); json_object *tray_output, *mode, *hidden_bar, *position, *status_command; - json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; + json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; json_object *markup; json_object_object_get_ex(bar_config, "tray_output", &tray_output); @@ -29,6 +29,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { json_object_object_get_ex(bar_config, "status_command", &status_command); json_object_object_get_ex(bar_config, "font", &font); json_object_object_get_ex(bar_config, "bar_height", &bar_height); + json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); @@ -65,6 +66,10 @@ static void ipc_parse_config(struct config *config, const char *payload) { config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); } + if (wrap_scroll) { + config->wrap_scroll = json_object_get_boolean(wrap_scroll); + } + if (workspace_buttons) { config->workspace_buttons = json_object_get_boolean(workspace_buttons); } |