diff options
-rw-r--r-- | include/bar/config.h | 1 | ||||
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 25 | ||||
-rw-r--r-- | sway/ipc-json.c | 1 | ||||
-rw-r--r-- | sway/sway-bar.5.txt | 9 | ||||
-rw-r--r-- | swaybar/bar.c | 31 | ||||
-rw-r--r-- | swaybar/config.c | 1 | ||||
-rw-r--r-- | swaybar/ipc.c | 7 |
8 files changed, 72 insertions, 4 deletions
diff --git a/include/bar/config.h b/include/bar/config.h index c0e3d2a7..c957caa7 100644 --- a/include/bar/config.h +++ b/include/bar/config.h | |||
@@ -27,6 +27,7 @@ struct config { | |||
27 | char *mode; | 27 | char *mode; |
28 | bool strip_workspace_numbers; | 28 | bool strip_workspace_numbers; |
29 | bool binding_mode_indicator; | 29 | bool binding_mode_indicator; |
30 | bool wrap_scroll; | ||
30 | bool workspace_buttons; | 31 | bool workspace_buttons; |
31 | bool all_outputs; | 32 | bool all_outputs; |
32 | list_t *outputs; | 33 | list_t *outputs; |
diff --git a/include/config.h b/include/config.h index bf278ddb..87e23187 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -136,6 +136,7 @@ struct bar_config { | |||
136 | int height; // -1 not defined | 136 | int height; // -1 not defined |
137 | int tray_padding; | 137 | int tray_padding; |
138 | bool workspace_buttons; | 138 | bool workspace_buttons; |
139 | bool wrap_scroll; | ||
139 | char *separator_symbol; | 140 | char *separator_symbol; |
140 | bool strip_workspace_numbers; | 141 | bool strip_workspace_numbers; |
141 | bool binding_mode_indicator; | 142 | bool binding_mode_indicator; |
diff --git a/sway/commands.c b/sway/commands.c index b9399dec..73f245c1 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -114,6 +114,7 @@ static sway_cmd bar_cmd_strip_workspace_numbers; | |||
114 | static sway_cmd bar_cmd_swaybar_command; | 114 | static sway_cmd bar_cmd_swaybar_command; |
115 | static sway_cmd bar_cmd_tray_output; | 115 | static sway_cmd bar_cmd_tray_output; |
116 | static sway_cmd bar_cmd_tray_padding; | 116 | static sway_cmd bar_cmd_tray_padding; |
117 | static sway_cmd bar_cmd_wrap_scroll; | ||
117 | static sway_cmd bar_cmd_workspace_buttons; | 118 | static sway_cmd bar_cmd_workspace_buttons; |
118 | 119 | ||
119 | static sway_cmd bar_colors_cmd_active_workspace; | 120 | static sway_cmd bar_colors_cmd_active_workspace; |
@@ -3169,6 +3170,29 @@ static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { | |||
3169 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 3170 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
3170 | } | 3171 | } |
3171 | 3172 | ||
3173 | static struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { | ||
3174 | struct cmd_results *error = NULL; | ||
3175 | if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { | ||
3176 | return error; | ||
3177 | } | ||
3178 | |||
3179 | if (!config->current_bar) { | ||
3180 | return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined."); | ||
3181 | } | ||
3182 | |||
3183 | if (strcasecmp("yes", argv[0]) == 0) { | ||
3184 | config->current_bar->wrap_scroll = true; | ||
3185 | sway_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); | ||
3186 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
3187 | config->current_bar->wrap_scroll = false; | ||
3188 | sway_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); | ||
3189 | } else { | ||
3190 | error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]); | ||
3191 | return error; | ||
3192 | } | ||
3193 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3194 | } | ||
3195 | |||
3172 | static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | 3196 | static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { |
3173 | struct cmd_results *error = NULL; | 3197 | struct cmd_results *error = NULL; |
3174 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { | 3198 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { |
@@ -3211,6 +3235,7 @@ static struct cmd_handler bar_handlers[] = { | |||
3211 | { "swaybar_command", bar_cmd_swaybar_command }, | 3235 | { "swaybar_command", bar_cmd_swaybar_command }, |
3212 | { "tray_output", bar_cmd_tray_output }, | 3236 | { "tray_output", bar_cmd_tray_output }, |
3213 | { "tray_padding", bar_cmd_tray_padding }, | 3237 | { "tray_padding", bar_cmd_tray_padding }, |
3238 | { "wrap_scroll", bar_cmd_wrap_scroll }, | ||
3214 | { "workspace_buttons", bar_cmd_workspace_buttons }, | 3239 | { "workspace_buttons", bar_cmd_workspace_buttons }, |
3215 | }; | 3240 | }; |
3216 | 3241 | ||
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index e7ab988c..ca45557c 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -241,6 +241,7 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
241 | json_object_object_add(json, "separator_symbol", json_object_new_string(bar->separator_symbol)); | 241 | json_object_object_add(json, "separator_symbol", json_object_new_string(bar->separator_symbol)); |
242 | } | 242 | } |
243 | json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); | 243 | json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); |
244 | json_object_object_add(json, "wrap_scroll", json_object_new_boolean(bar->wrap_scroll)); | ||
244 | json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); | 245 | json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); |
245 | json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); | 246 | json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); |
246 | json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); | 247 | json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); |
diff --git a/sway/sway-bar.5.txt b/sway/sway-bar.5.txt index dc4a673c..a404acd0 100644 --- a/sway/sway-bar.5.txt +++ b/sway/sway-bar.5.txt | |||
@@ -21,7 +21,7 @@ Commands | |||
21 | **status_command** <status command>:: | 21 | **status_command** <status command>:: |
22 | Executes the bar _status command_ with _sh -c_. Each line of text printed to | 22 | Executes the bar _status command_ with _sh -c_. Each line of text printed to |
23 | stdout from this command will be displayed in the status area of the bar. You | 23 | stdout from this command will be displayed in the status area of the bar. You |
24 | can also use the i3bar JSON protocol: | 24 | may also use the i3bar JSON protocol: |
25 | + | 25 | + |
26 | https://i3wm.org/docs/i3bar-protocol.html | 26 | https://i3wm.org/docs/i3bar-protocol.html |
27 | 27 | ||
@@ -48,9 +48,12 @@ Commands | |||
48 | **separator_symbol** <symbol>:: | 48 | **separator_symbol** <symbol>:: |
49 | Specifies the separator symbol to separate blocks on the bar. | 49 | Specifies the separator symbol to separate blocks on the bar. |
50 | 50 | ||
51 | **wrap_scroll** <yes|no>:: | ||
52 | Enables or disables wrapping when scrolling through workspaces with the | ||
53 | scroll wheel. Default is no. | ||
54 | |||
51 | **workspace_buttons** <yes|no>:: | 55 | **workspace_buttons** <yes|no>:: |
52 | Enables or disables workspace buttons on the bar. Default is to enable | 56 | Enables or disables workspace buttons on the bar. Default is yes. |
53 | buttons. | ||
54 | 57 | ||
55 | **strip_workspace_numbers** <yes|no>:: | 58 | **strip_workspace_numbers** <yes|no>:: |
56 | If set to _yes_, then workspace numbers will be omitted from the workspace | 59 | If set to _yes_, then workspace numbers will be omitted from the workspace |
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, | |||
96 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { | 96 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { |
97 | sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); | 97 | sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); |
98 | 98 | ||
99 | if (!swaybar.config->wrap_scroll) { | ||
100 | // Find output this window lives on | ||
101 | int i; | ||
102 | struct output *output; | ||
103 | for (i = 0; i < swaybar.outputs->length; ++i) { | ||
104 | output = swaybar.outputs->items[i]; | ||
105 | if (output->window == window) { | ||
106 | break; | ||
107 | } | ||
108 | } | ||
109 | if (!sway_assert(i != swaybar.outputs->length, "Unknown window in scroll event")) { | ||
110 | return; | ||
111 | } | ||
112 | int focused = -1; | ||
113 | for (i = 0; i < output->workspaces->length; ++i) { | ||
114 | struct workspace *ws = output->workspaces->items[i]; | ||
115 | if (ws->focused) { | ||
116 | focused = i; | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | if (!sway_assert(focused != -1, "Scroll wheel event received on inactive output")) { | ||
121 | return; | ||
122 | } | ||
123 | if ((focused == 0 && direction == SCROLL_UP) || | ||
124 | (focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) { | ||
125 | // Do not wrap | ||
126 | return; | ||
127 | } | ||
128 | } | ||
129 | |||
99 | const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output"; | 130 | const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output"; |
100 | ipc_send_workspace_command(workspace_name); | 131 | ipc_send_workspace_command(workspace_name); |
101 | } | 132 | } |
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() { | |||
53 | config->sep_symbol = NULL; | 53 | config->sep_symbol = NULL; |
54 | config->strip_workspace_numbers = false; | 54 | config->strip_workspace_numbers = false; |
55 | config->binding_mode_indicator = true; | 55 | config->binding_mode_indicator = true; |
56 | config->wrap_scroll = false; | ||
56 | config->workspace_buttons = true; | 57 | config->workspace_buttons = true; |
57 | config->all_outputs = false; | 58 | config->all_outputs = false; |
58 | config->outputs = create_list(); | 59 | 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) { | |||
19 | static void ipc_parse_config(struct config *config, const char *payload) { | 19 | static void ipc_parse_config(struct config *config, const char *payload) { |
20 | json_object *bar_config = json_tokener_parse(payload); | 20 | json_object *bar_config = json_tokener_parse(payload); |
21 | json_object *tray_output, *mode, *hidden_bar, *position, *status_command; | 21 | json_object *tray_output, *mode, *hidden_bar, *position, *status_command; |
22 | json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; | 22 | json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; |
23 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; | 23 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; |
24 | json_object *markup; | 24 | json_object *markup; |
25 | json_object_object_get_ex(bar_config, "tray_output", &tray_output); | 25 | 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) { | |||
29 | json_object_object_get_ex(bar_config, "status_command", &status_command); | 29 | json_object_object_get_ex(bar_config, "status_command", &status_command); |
30 | json_object_object_get_ex(bar_config, "font", &font); | 30 | json_object_object_get_ex(bar_config, "font", &font); |
31 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); | 31 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); |
32 | json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); | ||
32 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); | 33 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); |
33 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); | 34 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); |
34 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); | 35 | 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) { | |||
65 | config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); | 66 | config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); |
66 | } | 67 | } |
67 | 68 | ||
69 | if (wrap_scroll) { | ||
70 | config->wrap_scroll = json_object_get_boolean(wrap_scroll); | ||
71 | } | ||
72 | |||
68 | if (workspace_buttons) { | 73 | if (workspace_buttons) { |
69 | config->workspace_buttons = json_object_get_boolean(workspace_buttons); | 74 | config->workspace_buttons = json_object_get_boolean(workspace_buttons); |
70 | } | 75 | } |