diff options
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/swaybar/config.h | 1 | ||||
-rw-r--r-- | sway/commands/bar.c | 1 | ||||
-rw-r--r-- | sway/commands/bar/workspace_min_width.c | 33 | ||||
-rw-r--r-- | sway/config/bar.c | 1 | ||||
-rw-r--r-- | sway/ipc-json.c | 2 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-bar.5.scd | 5 | ||||
-rw-r--r-- | sway/sway-ipc.7.scd | 4 | ||||
-rw-r--r-- | swaybar/config.c | 1 | ||||
-rw-r--r-- | swaybar/ipc.c | 6 | ||||
-rw-r--r-- | swaybar/render.c | 20 |
13 files changed, 74 insertions, 3 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 07730f98..f549626b 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -228,6 +228,7 @@ sway_cmd bar_cmd_unbindcode; | |||
228 | sway_cmd bar_cmd_unbindsym; | 228 | sway_cmd bar_cmd_unbindsym; |
229 | sway_cmd bar_cmd_wrap_scroll; | 229 | sway_cmd bar_cmd_wrap_scroll; |
230 | sway_cmd bar_cmd_workspace_buttons; | 230 | sway_cmd bar_cmd_workspace_buttons; |
231 | sway_cmd bar_cmd_workspace_min_width; | ||
231 | 232 | ||
232 | sway_cmd bar_colors_cmd_active_workspace; | 233 | sway_cmd bar_colors_cmd_active_workspace; |
233 | sway_cmd bar_colors_cmd_background; | 234 | sway_cmd bar_colors_cmd_background; |
diff --git a/include/sway/config.h b/include/sway/config.h index 5ad240d3..ee1852d4 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -320,6 +320,7 @@ struct bar_config { | |||
320 | struct side_gaps gaps; | 320 | struct side_gaps gaps; |
321 | int status_padding; | 321 | int status_padding; |
322 | int status_edge_padding; | 322 | int status_edge_padding; |
323 | uint32_t workspace_min_width; | ||
323 | struct { | 324 | struct { |
324 | char *background; | 325 | char *background; |
325 | char *statusline; | 326 | char *statusline; |
diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 688fa2d7..4cacd21a 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h | |||
@@ -38,6 +38,7 @@ struct swaybar_config { | |||
38 | bool binding_mode_indicator; | 38 | bool binding_mode_indicator; |
39 | bool wrap_scroll; | 39 | bool wrap_scroll; |
40 | bool workspace_buttons; | 40 | bool workspace_buttons; |
41 | uint32_t workspace_min_width; | ||
41 | list_t *bindings; | 42 | list_t *bindings; |
42 | struct wl_list outputs; // config_output::link | 43 | struct wl_list outputs; // config_output::link |
43 | int height; | 44 | int height; |
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 7370910d..d42b7fc2 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -36,6 +36,7 @@ static struct cmd_handler bar_handlers[] = { | |||
36 | { "unbindcode", bar_cmd_unbindcode }, | 36 | { "unbindcode", bar_cmd_unbindcode }, |
37 | { "unbindsym", bar_cmd_unbindsym }, | 37 | { "unbindsym", bar_cmd_unbindsym }, |
38 | { "workspace_buttons", bar_cmd_workspace_buttons }, | 38 | { "workspace_buttons", bar_cmd_workspace_buttons }, |
39 | { "workspace_min_width", bar_cmd_workspace_min_width }, | ||
39 | { "wrap_scroll", bar_cmd_wrap_scroll }, | 40 | { "wrap_scroll", bar_cmd_wrap_scroll }, |
40 | }; | 41 | }; |
41 | 42 | ||
diff --git a/sway/commands/bar/workspace_min_width.c b/sway/commands/bar/workspace_min_width.c new file mode 100644 index 00000000..8d65592c --- /dev/null +++ b/sway/commands/bar/workspace_min_width.c | |||
@@ -0,0 +1,33 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <strings.h> | ||
3 | #include "config.h" | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct cmd_results *bar_cmd_workspace_min_width(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "workspace_min_width", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | |||
14 | struct bar_config *bar = config->current_bar; | ||
15 | |||
16 | char *end; | ||
17 | int min_width = strtol(argv[0], &end, 10); | ||
18 | if (min_width < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) { | ||
19 | return cmd_results_new(CMD_INVALID, | ||
20 | "[Bar %s] Invalid minimum workspace button width value: %s", | ||
21 | bar->id, argv[0]); | ||
22 | } | ||
23 | |||
24 | if (argc == 2 && strcasecmp(argv[1], "px") != 0) { | ||
25 | return cmd_results_new(CMD_INVALID, | ||
26 | "Expected 'workspace_min_width <px> [px]'"); | ||
27 | } | ||
28 | |||
29 | sway_log(SWAY_DEBUG, "[Bar %s] Setting minimum workspace button width to %d", | ||
30 | bar->id, min_width); | ||
31 | config->current_bar->workspace_min_width = min_width; | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
33 | } | ||
diff --git a/sway/config/bar.c b/sway/config/bar.c index 1c7c13b2..767534a6 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -105,6 +105,7 @@ struct bar_config *default_bar_config(void) { | |||
105 | bar->modifier = get_modifier_mask_by_name("Mod4"); | 105 | bar->modifier = get_modifier_mask_by_name("Mod4"); |
106 | bar->status_padding = 1; | 106 | bar->status_padding = 1; |
107 | bar->status_edge_padding = 3; | 107 | bar->status_edge_padding = 3; |
108 | bar->workspace_min_width = 0; | ||
108 | if (!(bar->mode = strdup("dock"))) { | 109 | if (!(bar->mode = strdup("dock"))) { |
109 | goto cleanup; | 110 | goto cleanup; |
110 | } | 111 | } |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 9330de09..fceee84d 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -1102,6 +1102,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
1102 | json_object_new_boolean(bar->strip_workspace_numbers)); | 1102 | json_object_new_boolean(bar->strip_workspace_numbers)); |
1103 | json_object_object_add(json, "strip_workspace_name", | 1103 | json_object_object_add(json, "strip_workspace_name", |
1104 | json_object_new_boolean(bar->strip_workspace_name)); | 1104 | json_object_new_boolean(bar->strip_workspace_name)); |
1105 | json_object_object_add(json, "workspace_min_width", | ||
1106 | json_object_new_int(bar->workspace_min_width)); | ||
1105 | json_object_object_add(json, "binding_mode_indicator", | 1107 | json_object_object_add(json, "binding_mode_indicator", |
1106 | json_object_new_boolean(bar->binding_mode_indicator)); | 1108 | json_object_new_boolean(bar->binding_mode_indicator)); |
1107 | json_object_object_add(json, "verbose", | 1109 | json_object_object_add(json, "verbose", |
diff --git a/sway/meson.build b/sway/meson.build index 0db45836..b65a5211 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -144,6 +144,7 @@ sway_sources = files( | |||
144 | 'commands/bar/tray_output.c', | 144 | 'commands/bar/tray_output.c', |
145 | 'commands/bar/tray_padding.c', | 145 | 'commands/bar/tray_padding.c', |
146 | 'commands/bar/workspace_buttons.c', | 146 | 'commands/bar/workspace_buttons.c', |
147 | 'commands/bar/workspace_min_width.c', | ||
147 | 'commands/bar/wrap_scroll.c', | 148 | 'commands/bar/wrap_scroll.c', |
148 | 149 | ||
149 | 'commands/input/accel_profile.c', | 150 | 'commands/input/accel_profile.c', |
diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index 78124c92..80d08449 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd | |||
@@ -138,6 +138,11 @@ runtime. | |||
138 | *workspace_buttons* yes|no | 138 | *workspace_buttons* yes|no |
139 | Enables or disables workspace buttons on the bar. Default is _yes_. | 139 | Enables or disables workspace buttons on the bar. Default is _yes_. |
140 | 140 | ||
141 | *workspace_min_width* <px> [px] | ||
142 | Specifies the minimum width for the workspace buttons on the bar. Default is _0_. | ||
143 | |||
144 | This setting also applies to the current binding mode indicator. | ||
145 | |||
141 | ## TRAY | 146 | ## TRAY |
142 | 147 | ||
143 | Swaybar provides a system tray where third-party applications may place icons. | 148 | Swaybar provides a system tray where third-party applications may place icons. |
diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd index 495e2e7d..018080fe 100644 --- a/sway/sway-ipc.7.scd +++ b/sway/sway-ipc.7.scd | |||
@@ -829,6 +829,9 @@ their value mean can be found in *sway-bar*(5): | |||
829 | |- workspace_buttons | 829 | |- workspace_buttons |
830 | : boolean | 830 | : boolean |
831 | : Whether to display the workspace buttons on the bar | 831 | : Whether to display the workspace buttons on the bar |
832 | |- workspace_min_width | ||
833 | : integer | ||
834 | : Minimum width in px for the workspace buttons on the bar | ||
832 | |- binding_mode_indicator | 835 | |- binding_mode_indicator |
833 | : boolean | 836 | : boolean |
834 | : Whether to display the current binding mode on the bar | 837 | : Whether to display the current binding mode on the bar |
@@ -931,6 +934,7 @@ containing the _#RRGGBBAA_ representation of the color: | |||
931 | "status_padding": 1, | 934 | "status_padding": 1, |
932 | "status_edge_padding": 3, | 935 | "status_edge_padding": 3, |
933 | "workspace_buttons": true, | 936 | "workspace_buttons": true, |
937 | "workspace_min_width": 0, | ||
934 | "binding_mode_indicator": true, | 938 | "binding_mode_indicator": true, |
935 | "verbose": false, | 939 | "verbose": false, |
936 | "pango_markup": false, | 940 | "pango_markup": false, |
diff --git a/swaybar/config.c b/swaybar/config.c index 52297310..abedaec0 100644 --- a/swaybar/config.c +++ b/swaybar/config.c | |||
@@ -35,6 +35,7 @@ struct swaybar_config *init_config(void) { | |||
35 | config->binding_mode_indicator = true; | 35 | config->binding_mode_indicator = true; |
36 | config->wrap_scroll = false; | 36 | config->wrap_scroll = false; |
37 | config->workspace_buttons = true; | 37 | config->workspace_buttons = true; |
38 | config->workspace_min_width = 0; | ||
38 | config->bindings = create_list(); | 39 | config->bindings = create_list(); |
39 | wl_list_init(&config->outputs); | 40 | wl_list_init(&config->outputs); |
40 | config->status_padding = 1; | 41 | config->status_padding = 1; |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 6aa604eb..6bbe9408 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -270,6 +270,12 @@ static bool ipc_parse_config( | |||
270 | config->workspace_buttons = json_object_get_boolean(workspace_buttons); | 270 | config->workspace_buttons = json_object_get_boolean(workspace_buttons); |
271 | } | 271 | } |
272 | 272 | ||
273 | json_object *workspace_min_width = | ||
274 | json_object_object_get(bar_config, "workspace_min_width"); | ||
275 | if (workspace_min_width) { | ||
276 | config->workspace_min_width = json_object_get_int(workspace_min_width); | ||
277 | } | ||
278 | |||
273 | json_object *wrap_scroll = json_object_object_get(bar_config, "wrap_scroll"); | 279 | json_object *wrap_scroll = json_object_object_get(bar_config, "wrap_scroll"); |
274 | if (wrap_scroll) { | 280 | if (wrap_scroll) { |
275 | config->wrap_scroll = json_object_get_boolean(wrap_scroll); | 281 | config->wrap_scroll = json_object_get_boolean(wrap_scroll); |
diff --git a/swaybar/render.c b/swaybar/render.c index 3a626e1c..8f38174f 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -402,7 +402,11 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo, | |||
402 | return 0; | 402 | return 0; |
403 | } | 403 | } |
404 | 404 | ||
405 | return ws_horizontal_padding * 2 + text_width + border_width * 2; | 405 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
406 | if (width < config->workspace_min_width * output->scale) { | ||
407 | width = config->workspace_min_width * output->scale; | ||
408 | } | ||
409 | return width; | ||
406 | } | 410 | } |
407 | 411 | ||
408 | static uint32_t predict_workspace_buttons_length(cairo_t *cairo, | 412 | static uint32_t predict_workspace_buttons_length(cairo_t *cairo, |
@@ -446,7 +450,11 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo, | |||
446 | output->height < ideal_surface_height) { | 450 | output->height < ideal_surface_height) { |
447 | return 0; | 451 | return 0; |
448 | } | 452 | } |
449 | return text_width + ws_horizontal_padding * 2 + border_width * 2; | 453 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
454 | if (width < config->workspace_min_width * output->scale) { | ||
455 | width = config->workspace_min_width * output->scale; | ||
456 | } | ||
457 | return width; | ||
450 | } | 458 | } |
451 | 459 | ||
452 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 460 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
@@ -518,6 +526,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
518 | return ideal_surface_height; | 526 | return ideal_surface_height; |
519 | } | 527 | } |
520 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; | 528 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
529 | if (width < config->workspace_min_width * output->scale) { | ||
530 | width = config->workspace_min_width * output->scale; | ||
531 | } | ||
521 | 532 | ||
522 | uint32_t height = output->height * output->scale; | 533 | uint32_t height = output->height * output->scale; |
523 | cairo_set_source_u32(cairo, config->colors.binding_mode.background); | 534 | cairo_set_source_u32(cairo, config->colors.binding_mode.background); |
@@ -585,7 +596,10 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
585 | return ideal_surface_height; | 596 | return ideal_surface_height; |
586 | } | 597 | } |
587 | 598 | ||
588 | uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; | 599 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
600 | if (width < config->workspace_min_width * output->scale) { | ||
601 | width = config->workspace_min_width * output->scale; | ||
602 | } | ||
589 | 603 | ||
590 | cairo_set_source_u32(cairo, box_colors.background); | 604 | cairo_set_source_u32(cairo, box_colors.background); |
591 | cairo_rectangle(cairo, *x, 0, width, height); | 605 | cairo_rectangle(cairo, *x, 0, width, height); |