From 5090c131db4bf881e91a6e891418278451a5c71e Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Wed, 11 Jan 2017 09:06:21 -0500 Subject: [PATCH] add mouse_scroll_workspaces bar setting --- include/sway/commands.h | 11 ++++---- include/sway/config.h | 1 + include/swaybar/config.h | 1 + sway/commands/bar/mouse_scroll_workspaces.c | 29 +++++++++++++++++++++ sway/commands/bar/wrap_scroll.c | 1 + sway/config.c | 1 + sway/sway-bar.5.txt | 4 +++ swaybar/bar.c | 4 +++ swaybar/config.c | 1 + 9 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 sway/commands/bar/mouse_scroll_workspaces.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 3ab8d5af..8b79241f 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -152,22 +152,23 @@ sway_cmd bar_cmd_binding_mode_indicator; sway_cmd bar_cmd_bindsym; sway_cmd bar_cmd_colors; sway_cmd bar_cmd_font; -sway_cmd bar_cmd_mode; -sway_cmd bar_cmd_modifier; -sway_cmd bar_cmd_output; sway_cmd bar_cmd_height; sway_cmd bar_cmd_hidden_state; sway_cmd bar_cmd_id; +sway_cmd bar_cmd_mode; +sway_cmd bar_cmd_modifier; +sway_cmd bar_cmd_mouse_scroll_workspaces; +sway_cmd bar_cmd_output; +sway_cmd bar_cmd_pango_markup; sway_cmd bar_cmd_position; sway_cmd bar_cmd_separator_symbol; sway_cmd bar_cmd_status_command; -sway_cmd bar_cmd_pango_markup; sway_cmd bar_cmd_strip_workspace_numbers; sway_cmd bar_cmd_swaybar_command; sway_cmd bar_cmd_tray_output; sway_cmd bar_cmd_tray_padding; -sway_cmd bar_cmd_wrap_scroll; sway_cmd bar_cmd_workspace_buttons; +sway_cmd bar_cmd_wrap_scroll; sway_cmd bar_colors_cmd_active_workspace; sway_cmd bar_colors_cmd_background; diff --git a/include/sway/config.h b/include/sway/config.h index 4a14cd36..7bbdbe6f 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -135,6 +135,7 @@ struct bar_config { int height; // -1 not defined int tray_padding; bool workspace_buttons; + bool mouse_scroll_workspaces; bool wrap_scroll; char *separator_symbol; bool strip_workspace_numbers; diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 04b12cd4..b27562f5 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -28,6 +28,7 @@ struct config { char *mode; bool strip_workspace_numbers; bool binding_mode_indicator; + bool mouse_scroll_workspaces; bool wrap_scroll; bool workspace_buttons; bool all_outputs; diff --git a/sway/commands/bar/mouse_scroll_workspaces.c b/sway/commands/bar/mouse_scroll_workspaces.c new file mode 100644 index 00000000..9e1681f5 --- /dev/null +++ b/sway/commands/bar/mouse_scroll_workspaces.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "sway/commands.h" +#include "log.h" + +struct cmd_results *bar_cmd_mouse_scroll_workspaces(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "mouse_scroll_workspaces", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (!config->current_bar) { + return cmd_results_new(CMD_FAILURE, "mouse_scroll_workspaces", "No bar defined."); + } + + if (strcasecmp("yes", argv[0]) == 0) { + config->current_bar->mouse_scroll_workspaces = true; + sway_log(L_DEBUG, "Enabling workspace changing by mouse scroll wheel on bar: %s", config->current_bar->id); + } else if (strcasecmp("no", argv[0]) == 0) { + config->current_bar->mouse_scroll_workspaces = false; + sway_log(L_DEBUG, "Disabling workspace changing by mouse scroll wheel on bar: %s", config->current_bar->id); + } else { + error = cmd_results_new(CMD_INVALID, "mouse_scroll_workspaces", "Invalid value %s", argv[0]); + return error; + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c index caa85660..c1aa324c 100644 --- a/sway/commands/bar/wrap_scroll.c +++ b/sway/commands/bar/wrap_scroll.c @@ -1,4 +1,5 @@ #include +#include #include "sway/commands.h" #include "log.h" diff --git a/sway/config.c b/sway/config.c index 9e758c90..6f370db1 100644 --- a/sway/config.c +++ b/sway/config.c @@ -1291,6 +1291,7 @@ struct bar_config *default_bar_config(void) { bar->font = NULL; bar->height = -1; bar->workspace_buttons = true; + bar->mouse_scroll_workspaces = true; bar->wrap_scroll = false; bar->separator_symbol = NULL; bar->strip_workspace_numbers = false; diff --git a/sway/sway-bar.5.txt b/sway/sway-bar.5.txt index a404acd0..9bf65570 100644 --- a/sway/sway-bar.5.txt +++ b/sway/sway-bar.5.txt @@ -48,6 +48,10 @@ Commands **separator_symbol** :: Specifies the separator symbol to separate blocks on the bar. +**mouse_scroll_workspaces** :: + Enables or disables workspace switching using the mouse scroll wheel. + Default is yes. + **wrap_scroll** :: Enables or disables wrapping when scrolling through workspaces with the scroll wheel. Default is no. diff --git a/swaybar/bar.c b/swaybar/bar.c index 7ec3e0ea..c3e5dc72 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -95,6 +95,10 @@ 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->mouse_scroll_workspaces) { + return; + } + if (!swaybar.config->wrap_scroll) { // Find output this window lives on int i; diff --git a/swaybar/config.c b/swaybar/config.c index 7959b1ca..23e1f526 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -40,6 +40,7 @@ struct config *init_config() { config->sep_symbol = NULL; config->strip_workspace_numbers = false; config->binding_mode_indicator = true; + config->mouse_scroll_workspaces = true; config->wrap_scroll = false; config->workspace_buttons = true; config->all_outputs = false;