diff options
author | emersion <contact@emersion.fr> | 2018-11-28 17:57:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 17:57:35 +0100 |
commit | 2c31e826755c74e530cfc9b70e3e028cfaa85918 (patch) | |
tree | dcfac10d1996db167aba5e79059c41d1fff3f14f | |
parent | Merge pull request #3212 from martinetd/move_floating (diff) | |
parent | Implement bar gaps (diff) | |
download | sway-2c31e826755c74e530cfc9b70e3e028cfaa85918.tar.gz sway-2c31e826755c74e530cfc9b70e3e028cfaa85918.tar.zst sway-2c31e826755c74e530cfc9b70e3e028cfaa85918.zip |
Merge pull request #3208 from RedSoxFan/bar-gaps
Implement bar gaps
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/swaybar/config.h | 6 | ||||
-rw-r--r-- | sway/commands/bar.c | 1 | ||||
-rw-r--r-- | sway/commands/bar/gaps.c | 60 | ||||
-rw-r--r-- | sway/ipc-json.c | 12 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-bar.5.scd | 7 | ||||
-rw-r--r-- | swaybar/config.c | 6 | ||||
-rw-r--r-- | swaybar/ipc.c | 42 | ||||
-rw-r--r-- | swaybar/render.c | 5 |
11 files changed, 141 insertions, 1 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index c3913c79..1f2376d0 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -188,6 +188,7 @@ sway_cmd bar_cmd_bindsym; | |||
188 | sway_cmd bar_cmd_colors; | 188 | sway_cmd bar_cmd_colors; |
189 | sway_cmd bar_cmd_context_button; | 189 | sway_cmd bar_cmd_context_button; |
190 | sway_cmd bar_cmd_font; | 190 | sway_cmd bar_cmd_font; |
191 | sway_cmd bar_cmd_gaps; | ||
191 | sway_cmd bar_cmd_mode; | 192 | sway_cmd bar_cmd_mode; |
192 | sway_cmd bar_cmd_modifier; | 193 | sway_cmd bar_cmd_modifier; |
193 | sway_cmd bar_cmd_output; | 194 | sway_cmd bar_cmd_output; |
diff --git a/include/sway/config.h b/include/sway/config.h index d02b0d63..58b7010e 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -227,6 +227,7 @@ struct bar_config { | |||
227 | bool strip_workspace_name; | 227 | bool strip_workspace_name; |
228 | bool binding_mode_indicator; | 228 | bool binding_mode_indicator; |
229 | bool verbose; | 229 | bool verbose; |
230 | struct side_gaps gaps; | ||
230 | pid_t pid; | 231 | pid_t pid; |
231 | struct { | 232 | struct { |
232 | char *background; | 233 | char *background; |
diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 700e6b60..fd7c6ec4 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h | |||
@@ -42,6 +42,12 @@ struct swaybar_config { | |||
42 | struct wl_list outputs; // config_output::link | 42 | struct wl_list outputs; // config_output::link |
43 | bool all_outputs; | 43 | bool all_outputs; |
44 | int height; | 44 | int height; |
45 | struct { | ||
46 | int top; | ||
47 | int right; | ||
48 | int bottom; | ||
49 | int left; | ||
50 | } gaps; | ||
45 | 51 | ||
46 | struct { | 52 | struct { |
47 | uint32_t background; | 53 | uint32_t background; |
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index f9ed530e..0cf94907 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -14,6 +14,7 @@ static struct cmd_handler bar_handlers[] = { | |||
14 | { "colors", bar_cmd_colors }, | 14 | { "colors", bar_cmd_colors }, |
15 | { "context_button", bar_cmd_context_button }, | 15 | { "context_button", bar_cmd_context_button }, |
16 | { "font", bar_cmd_font }, | 16 | { "font", bar_cmd_font }, |
17 | { "gaps", bar_cmd_gaps }, | ||
17 | { "height", bar_cmd_height }, | 18 | { "height", bar_cmd_height }, |
18 | { "hidden_state", bar_cmd_hidden_state }, | 19 | { "hidden_state", bar_cmd_hidden_state }, |
19 | { "icon_theme", bar_cmd_icon_theme }, | 20 | { "icon_theme", bar_cmd_icon_theme }, |
diff --git a/sway/commands/bar/gaps.c b/sway/commands/bar/gaps.c new file mode 100644 index 00000000..f78f3742 --- /dev/null +++ b/sway/commands/bar/gaps.c | |||
@@ -0,0 +1,60 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/ipc-server.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct cmd_results *bar_cmd_gaps(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_MOST, 4))) { | ||
14 | return error; | ||
15 | } | ||
16 | if (!config->current_bar) { | ||
17 | return cmd_results_new(CMD_FAILURE, "bar gaps", "No bar defined."); | ||
18 | } | ||
19 | |||
20 | int top = 0, right = 0, bottom = 0, left = 0; | ||
21 | |||
22 | for (int i = 0; i < argc; i++) { | ||
23 | char *end; | ||
24 | int amount = strtol(argv[i], &end, 10); | ||
25 | if (strlen(end) && strcasecmp(end, "px") != 0) { | ||
26 | return cmd_results_new(CMD_INVALID, "bar gaps", | ||
27 | "Expected 'bar [<bar-id>] gaps <all> | <horizonal> " | ||
28 | "<vertical> | <top> <right> <bottom> <left>'"); | ||
29 | } | ||
30 | |||
31 | if (i == 0) { | ||
32 | top = amount; | ||
33 | } | ||
34 | if (i == 0 || i == 1) { | ||
35 | right = amount; | ||
36 | } | ||
37 | if (i == 0 || i == 2) { | ||
38 | bottom = amount; | ||
39 | } | ||
40 | if (i == 0 || i == 1 || i == 3) { | ||
41 | left = amount; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | config->current_bar->gaps.top = top; | ||
46 | config->current_bar->gaps.right = right; | ||
47 | config->current_bar->gaps.bottom = bottom; | ||
48 | config->current_bar->gaps.left = left; | ||
49 | |||
50 | wlr_log(WLR_DEBUG, "Setting bar gaps to %d %d %d %d on bar: %s", | ||
51 | config->current_bar->gaps.top, config->current_bar->gaps.right, | ||
52 | config->current_bar->gaps.bottom, config->current_bar->gaps.left, | ||
53 | config->current_bar->id); | ||
54 | |||
55 | if (!config->reading) { | ||
56 | ipc_event_barconfig_update(config->current_bar); | ||
57 | } | ||
58 | |||
59 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
60 | } | ||
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 40fbd3e7..fc631373 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -638,6 +638,18 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
638 | json_object_new_string(bar->status_command) : NULL); | 638 | json_object_new_string(bar->status_command) : NULL); |
639 | json_object_object_add(json, "font", | 639 | json_object_object_add(json, "font", |
640 | json_object_new_string((bar->font) ? bar->font : config->font)); | 640 | json_object_new_string((bar->font) ? bar->font : config->font)); |
641 | |||
642 | json_object *gaps = json_object_new_object(); | ||
643 | json_object_object_add(gaps, "top", | ||
644 | json_object_new_int(bar->gaps.top)); | ||
645 | json_object_object_add(gaps, "right", | ||
646 | json_object_new_int(bar->gaps.right)); | ||
647 | json_object_object_add(gaps, "bottom", | ||
648 | json_object_new_int(bar->gaps.bottom)); | ||
649 | json_object_object_add(gaps, "left", | ||
650 | json_object_new_int(bar->gaps.left)); | ||
651 | json_object_object_add(json, "gaps", gaps); | ||
652 | |||
641 | if (bar->separator_symbol) { | 653 | if (bar->separator_symbol) { |
642 | json_object_object_add(json, "separator_symbol", | 654 | json_object_object_add(json, "separator_symbol", |
643 | json_object_new_string(bar->separator_symbol)); | 655 | json_object_new_string(bar->separator_symbol)); |
diff --git a/sway/meson.build b/sway/meson.build index 75131891..51b40020 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -104,6 +104,7 @@ sway_sources = files( | |||
104 | 'commands/bar/colors.c', | 104 | 'commands/bar/colors.c', |
105 | 'commands/bar/context_button.c', | 105 | 'commands/bar/context_button.c', |
106 | 'commands/bar/font.c', | 106 | 'commands/bar/font.c', |
107 | 'commands/bar/gaps.c', | ||
107 | 'commands/bar/height.c', | 108 | 'commands/bar/height.c', |
108 | 'commands/bar/hidden_state.c', | 109 | 'commands/bar/hidden_state.c', |
109 | 'commands/bar/icon_theme.c', | 110 | 'commands/bar/icon_theme.c', |
diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index 60ee9999..a3c6af2e 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd | |||
@@ -61,6 +61,13 @@ Sway allows configuring swaybar in the sway configuration file. | |||
61 | *binding\_mode\_indicator* yes|no | 61 | *binding\_mode\_indicator* yes|no |
62 | Enable or disable binding mode indicator. Default is _yes_. | 62 | Enable or disable binding mode indicator. Default is _yes_. |
63 | 63 | ||
64 | *gaps* <all> | <horizontal> <vertical> | <top> <right> <bottom> <left> | ||
65 | Sets the gaps from the edge of the screen for the bar. Gaps can either be | ||
66 | set all at once, per direction, or per side. Note that only sides that | ||
67 | touch an edge of the screen can have gaps. For the side that does not | ||
68 | touch an edge of the screen, per-side outer gaps for workspaces may be of | ||
69 | use. | ||
70 | |||
64 | *height* <height> | 71 | *height* <height> |
65 | Sets the height of the bar. Default height will match the font size. | 72 | Sets the height of the bar. Default height will match the font size. |
66 | 73 | ||
diff --git a/swaybar/config.c b/swaybar/config.c index 16febb2e..10c78c8a 100644 --- a/swaybar/config.c +++ b/swaybar/config.c | |||
@@ -40,6 +40,12 @@ struct swaybar_config *init_config(void) { | |||
40 | /* height */ | 40 | /* height */ |
41 | config->height = 0; | 41 | config->height = 0; |
42 | 42 | ||
43 | /* gaps */ | ||
44 | config->gaps.top = 0; | ||
45 | config->gaps.right = 0; | ||
46 | config->gaps.bottom = 0; | ||
47 | config->gaps.left = 0; | ||
48 | |||
43 | /* colors */ | 49 | /* colors */ |
44 | config->colors.background = 0x000000FF; | 50 | config->colors.background = 0x000000FF; |
45 | config->colors.focused_background = 0x000000FF; | 51 | config->colors.focused_background = 0x000000FF; |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index db4360c1..2b930786 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -153,7 +153,7 @@ static bool ipc_parse_config( | |||
153 | return false; | 153 | return false; |
154 | } | 154 | } |
155 | json_object *markup, *mode, *hidden_state, *position, *status_command; | 155 | json_object *markup, *mode, *hidden_state, *position, *status_command; |
156 | json_object *font, *bar_height, *wrap_scroll, *workspace_buttons; | 156 | json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; |
157 | json_object *strip_workspace_numbers, *strip_workspace_name; | 157 | json_object *strip_workspace_numbers, *strip_workspace_name; |
158 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; | 158 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; |
159 | json_object *outputs, *bindings; | 159 | json_object *outputs, *bindings; |
@@ -162,6 +162,7 @@ static bool ipc_parse_config( | |||
162 | json_object_object_get_ex(bar_config, "position", &position); | 162 | json_object_object_get_ex(bar_config, "position", &position); |
163 | json_object_object_get_ex(bar_config, "status_command", &status_command); | 163 | json_object_object_get_ex(bar_config, "status_command", &status_command); |
164 | json_object_object_get_ex(bar_config, "font", &font); | 164 | json_object_object_get_ex(bar_config, "font", &font); |
165 | json_object_object_get_ex(bar_config, "gaps", &gaps); | ||
165 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); | 166 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); |
166 | json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); | 167 | json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); |
167 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); | 168 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); |
@@ -207,6 +208,24 @@ static bool ipc_parse_config( | |||
207 | if (bar_height) { | 208 | if (bar_height) { |
208 | config->height = json_object_get_int(bar_height); | 209 | config->height = json_object_get_int(bar_height); |
209 | } | 210 | } |
211 | if (gaps) { | ||
212 | json_object *top = json_object_object_get(gaps, "top"); | ||
213 | if (top) { | ||
214 | config->gaps.top = json_object_get_int(top); | ||
215 | } | ||
216 | json_object *right = json_object_object_get(gaps, "right"); | ||
217 | if (right) { | ||
218 | config->gaps.right = json_object_get_int(right); | ||
219 | } | ||
220 | json_object *bottom = json_object_object_get(gaps, "bottom"); | ||
221 | if (bottom) { | ||
222 | config->gaps.bottom = json_object_get_int(bottom); | ||
223 | } | ||
224 | json_object *left = json_object_object_get(gaps, "left"); | ||
225 | if (left) { | ||
226 | config->gaps.left = json_object_get_int(left); | ||
227 | } | ||
228 | } | ||
210 | if (markup) { | 229 | if (markup) { |
211 | config->pango_markup = json_object_get_boolean(markup); | 230 | config->pango_markup = json_object_get_boolean(markup); |
212 | } | 231 | } |
@@ -446,6 +465,27 @@ static bool handle_barconfig_update(struct swaybar *bar, | |||
446 | config->mode = strdup(json_object_get_string(json_mode)); | 465 | config->mode = strdup(json_object_get_string(json_mode)); |
447 | wlr_log(WLR_DEBUG, "Changing bar mode to %s", config->mode); | 466 | wlr_log(WLR_DEBUG, "Changing bar mode to %s", config->mode); |
448 | 467 | ||
468 | json_object *gaps; | ||
469 | json_object_object_get_ex(json_config, "gaps", &gaps); | ||
470 | if (gaps) { | ||
471 | json_object *top = json_object_object_get(gaps, "top"); | ||
472 | if (top) { | ||
473 | config->gaps.top = json_object_get_int(top); | ||
474 | } | ||
475 | json_object *right = json_object_object_get(gaps, "right"); | ||
476 | if (right) { | ||
477 | config->gaps.right = json_object_get_int(right); | ||
478 | } | ||
479 | json_object *bottom = json_object_object_get(gaps, "bottom"); | ||
480 | if (bottom) { | ||
481 | config->gaps.bottom = json_object_get_int(bottom); | ||
482 | } | ||
483 | json_object *left = json_object_object_get(gaps, "left"); | ||
484 | if (left) { | ||
485 | config->gaps.left = json_object_get_int(left); | ||
486 | } | ||
487 | } | ||
488 | |||
449 | return determine_bar_visibility(bar, true); | 489 | return determine_bar_visibility(bar, true); |
450 | } | 490 | } |
451 | 491 | ||
diff --git a/swaybar/render.c b/swaybar/render.c index 8269a840..77cfecbf 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -506,6 +506,11 @@ void render_frame(struct swaybar_output *output) { | |||
506 | if (height != output->height || output->width == 0) { | 506 | if (height != output->height || output->width == 0) { |
507 | // Reconfigure surface | 507 | // Reconfigure surface |
508 | zwlr_layer_surface_v1_set_size(output->layer_surface, 0, height); | 508 | zwlr_layer_surface_v1_set_size(output->layer_surface, 0, height); |
509 | zwlr_layer_surface_v1_set_margin(output->layer_surface, | ||
510 | output->bar->config->gaps.top, | ||
511 | output->bar->config->gaps.right, | ||
512 | output->bar->config->gaps.bottom, | ||
513 | output->bar->config->gaps.left); | ||
509 | if (strcmp(output->bar->config->mode, "dock") == 0) { | 514 | if (strcmp(output->bar->config->mode, "dock") == 0) { |
510 | zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height); | 515 | zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height); |
511 | } | 516 | } |