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 | 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/ipc-server.c | 13 | ||||
-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 | ||||
-rw-r--r-- | swaymsg/main.c | 70 | ||||
-rw-r--r-- | swaymsg/swaymsg.1.scd | 11 |
14 files changed, 217 insertions, 19 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/ipc-server.c b/sway/ipc-server.c index 95433d97..e3d73522 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -668,7 +668,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
668 | // TODO: Check if they're permitted to use these events | 668 | // TODO: Check if they're permitted to use these events |
669 | struct json_object *request = json_tokener_parse(buf); | 669 | struct json_object *request = json_tokener_parse(buf); |
670 | if (request == NULL) { | 670 | if (request == NULL) { |
671 | client_valid = ipc_send_reply(client, "{\"success\": false}", 18); | 671 | const char msg[] = "[{\"success\": false}]"; |
672 | client_valid = ipc_send_reply(client, msg, strlen(msg)); | ||
672 | wlr_log(WLR_INFO, "Failed to parse subscribe request"); | 673 | wlr_log(WLR_INFO, "Failed to parse subscribe request"); |
673 | goto exit_cleanup; | 674 | goto exit_cleanup; |
674 | } | 675 | } |
@@ -695,8 +696,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
695 | client->subscribed_events |= event_mask(IPC_EVENT_TICK); | 696 | client->subscribed_events |= event_mask(IPC_EVENT_TICK); |
696 | is_tick = true; | 697 | is_tick = true; |
697 | } else { | 698 | } else { |
698 | client_valid = | 699 | const char msg[] = "[{\"success\": false}]"; |
699 | ipc_send_reply(client, "{\"success\": false}", 18); | 700 | client_valid = ipc_send_reply(client, msg, strlen(msg)); |
700 | json_object_put(request); | 701 | json_object_put(request); |
701 | wlr_log(WLR_INFO, "Unsupported event type in subscribe request"); | 702 | wlr_log(WLR_INFO, "Unsupported event type in subscribe request"); |
702 | goto exit_cleanup; | 703 | goto exit_cleanup; |
@@ -704,10 +705,12 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
704 | } | 705 | } |
705 | 706 | ||
706 | json_object_put(request); | 707 | json_object_put(request); |
707 | client_valid = ipc_send_reply(client, "{\"success\": true}", 17); | 708 | const char msg[] = "[{\"success\": true}]"; |
709 | client_valid = ipc_send_reply(client, msg, strlen(msg)); | ||
708 | if (is_tick) { | 710 | if (is_tick) { |
709 | client->current_command = IPC_EVENT_TICK; | 711 | client->current_command = IPC_EVENT_TICK; |
710 | ipc_send_reply(client, "{\"first\": true, \"payload\": \"\"}", 30); | 712 | const char tickmsg[] = "{\"first\": true, \"payload\": \"\"}"; |
713 | ipc_send_reply(client, tickmsg, strlen(tickmsg)); | ||
711 | } | 714 | } |
712 | goto exit_cleanup; | 715 | goto exit_cleanup; |
713 | } | 716 | } |
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 | } |
diff --git a/swaymsg/main.c b/swaymsg/main.c index e640cadf..3e61b94a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -305,8 +305,9 @@ static void pretty_print(int type, json_object *resp) { | |||
305 | } | 305 | } |
306 | 306 | ||
307 | int main(int argc, char **argv) { | 307 | int main(int argc, char **argv) { |
308 | static int quiet = 0; | 308 | static bool quiet = false; |
309 | static int raw = 0; | 309 | static bool raw = false; |
310 | static bool monitor = false; | ||
310 | char *socket_path = NULL; | 311 | char *socket_path = NULL; |
311 | char *cmdtype = NULL; | 312 | char *cmdtype = NULL; |
312 | 313 | ||
@@ -314,6 +315,7 @@ int main(int argc, char **argv) { | |||
314 | 315 | ||
315 | static struct option long_options[] = { | 316 | static struct option long_options[] = { |
316 | {"help", no_argument, NULL, 'h'}, | 317 | {"help", no_argument, NULL, 'h'}, |
318 | {"monitor", no_argument, NULL, 'm'}, | ||
317 | {"quiet", no_argument, NULL, 'q'}, | 319 | {"quiet", no_argument, NULL, 'q'}, |
318 | {"raw", no_argument, NULL, 'r'}, | 320 | {"raw", no_argument, NULL, 'r'}, |
319 | {"socket", required_argument, NULL, 's'}, | 321 | {"socket", required_argument, NULL, 's'}, |
@@ -326,6 +328,7 @@ int main(int argc, char **argv) { | |||
326 | "Usage: swaymsg [options] [message]\n" | 328 | "Usage: swaymsg [options] [message]\n" |
327 | "\n" | 329 | "\n" |
328 | " -h, --help Show help message and quit.\n" | 330 | " -h, --help Show help message and quit.\n" |
331 | " -m, --monitor Monitor until killed (-t SUBSCRIBE only)\n" | ||
329 | " -q, --quiet Be quiet.\n" | 332 | " -q, --quiet Be quiet.\n" |
330 | " -r, --raw Use raw output even if using a tty\n" | 333 | " -r, --raw Use raw output even if using a tty\n" |
331 | " -s, --socket <socket> Use the specified socket.\n" | 334 | " -s, --socket <socket> Use the specified socket.\n" |
@@ -337,16 +340,19 @@ int main(int argc, char **argv) { | |||
337 | int c; | 340 | int c; |
338 | while (1) { | 341 | while (1) { |
339 | int option_index = 0; | 342 | int option_index = 0; |
340 | c = getopt_long(argc, argv, "hqrs:t:v", long_options, &option_index); | 343 | c = getopt_long(argc, argv, "hmqrs:t:v", long_options, &option_index); |
341 | if (c == -1) { | 344 | if (c == -1) { |
342 | break; | 345 | break; |
343 | } | 346 | } |
344 | switch (c) { | 347 | switch (c) { |
348 | case 'm': // Monitor | ||
349 | monitor = true; | ||
350 | break; | ||
345 | case 'q': // Quiet | 351 | case 'q': // Quiet |
346 | quiet = 1; | 352 | quiet = true; |
347 | break; | 353 | break; |
348 | case 'r': // Raw | 354 | case 'r': // Raw |
349 | raw = 1; | 355 | raw = true; |
350 | break; | 356 | break; |
351 | case 's': // Socket | 357 | case 's': // Socket |
352 | socket_path = strdup(optarg); | 358 | socket_path = strdup(optarg); |
@@ -400,12 +406,20 @@ int main(int argc, char **argv) { | |||
400 | type = IPC_GET_CONFIG; | 406 | type = IPC_GET_CONFIG; |
401 | } else if (strcasecmp(cmdtype, "send_tick") == 0) { | 407 | } else if (strcasecmp(cmdtype, "send_tick") == 0) { |
402 | type = IPC_SEND_TICK; | 408 | type = IPC_SEND_TICK; |
409 | } else if (strcasecmp(cmdtype, "subscribe") == 0) { | ||
410 | type = IPC_SUBSCRIBE; | ||
403 | } else { | 411 | } else { |
404 | sway_abort("Unknown message type %s", cmdtype); | 412 | sway_abort("Unknown message type %s", cmdtype); |
405 | } | 413 | } |
406 | 414 | ||
407 | free(cmdtype); | 415 | free(cmdtype); |
408 | 416 | ||
417 | if (monitor && type != IPC_SUBSCRIBE) { | ||
418 | wlr_log(WLR_ERROR, "Monitor can only be used with -t SUBSCRIBE"); | ||
419 | free(socket_path); | ||
420 | return 1; | ||
421 | } | ||
422 | |||
409 | char *command = NULL; | 423 | char *command = NULL; |
410 | if (optind < argc) { | 424 | if (optind < argc) { |
411 | command = join_args(argv + optind, argc - optind); | 425 | command = join_args(argv + optind, argc - optind); |
@@ -422,26 +436,56 @@ int main(int argc, char **argv) { | |||
422 | json_object *obj = json_tokener_parse(resp); | 436 | json_object *obj = json_tokener_parse(resp); |
423 | 437 | ||
424 | if (obj == NULL) { | 438 | if (obj == NULL) { |
425 | fprintf(stderr, "ERROR: Could not parse json response from ipc. This is a bug in sway."); | 439 | fprintf(stderr, "ERROR: Could not parse json response from ipc. " |
440 | "This is a bug in sway."); | ||
426 | printf("%s\n", resp); | 441 | printf("%s\n", resp); |
427 | ret = 1; | 442 | ret = 1; |
428 | } else { | 443 | } else { |
429 | if (!success(obj, true)) { | 444 | if (!success(obj, true)) { |
430 | ret = 1; | 445 | ret = 1; |
431 | } | 446 | } |
432 | if (raw) { | 447 | if (type != IPC_SUBSCRIBE || ret != 0) { |
433 | printf("%s\n", json_object_to_json_string_ext(obj, | 448 | if (raw) { |
434 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | 449 | printf("%s\n", json_object_to_json_string_ext(obj, |
435 | } else { | 450 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); |
436 | pretty_print(type, obj); | 451 | } else { |
452 | pretty_print(type, obj); | ||
453 | } | ||
437 | } | 454 | } |
438 | json_object_put(obj); | 455 | json_object_put(obj); |
439 | } | 456 | } |
440 | } | 457 | } |
441 | close(socketfd); | ||
442 | |||
443 | free(command); | 458 | free(command); |
444 | free(resp); | 459 | free(resp); |
460 | |||
461 | if (type == IPC_SUBSCRIBE && ret == 0) { | ||
462 | do { | ||
463 | struct ipc_response *reply = ipc_recv_response(socketfd); | ||
464 | if (!reply) { | ||
465 | break; | ||
466 | } | ||
467 | |||
468 | json_object *obj = json_tokener_parse(reply->payload); | ||
469 | if (obj == NULL) { | ||
470 | fprintf(stderr, "ERROR: Could not parse json response from ipc" | ||
471 | ". This is a bug in sway."); | ||
472 | ret = 1; | ||
473 | break; | ||
474 | } else { | ||
475 | if (raw) { | ||
476 | printf("%s\n", json_object_to_json_string(obj)); | ||
477 | } else { | ||
478 | printf("%s\n", json_object_to_json_string_ext(obj, | ||
479 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | ||
480 | } | ||
481 | json_object_put(obj); | ||
482 | } | ||
483 | |||
484 | free_ipc_response(reply); | ||
485 | } while (monitor); | ||
486 | } | ||
487 | |||
488 | close(socketfd); | ||
445 | free(socket_path); | 489 | free(socket_path); |
446 | return ret; | 490 | return ret; |
447 | } | 491 | } |
diff --git a/swaymsg/swaymsg.1.scd b/swaymsg/swaymsg.1.scd index eaac8105..f55f86a9 100644 --- a/swaymsg/swaymsg.1.scd +++ b/swaymsg/swaymsg.1.scd | |||
@@ -13,6 +13,12 @@ _swaymsg_ [options...] [message] | |||
13 | *-h, --help* | 13 | *-h, --help* |
14 | Show help message and quit. | 14 | Show help message and quit. |
15 | 15 | ||
16 | *-m, --monitor* | ||
17 | Monitor for responses until killed instead of exiting after the first | ||
18 | response. This can only be used with the IPC message type _subscribe_. If | ||
19 | there is a malformed response or an invalid event type was requested, | ||
20 | swaymsg will stop monitoring and exit. | ||
21 | |||
16 | *-q, --quiet* | 22 | *-q, --quiet* |
17 | Sends the IPC message but does not print the response from sway. | 23 | Sends the IPC message but does not print the response from sway. |
18 | 24 | ||
@@ -71,3 +77,8 @@ _swaymsg_ [options...] [message] | |||
71 | 77 | ||
72 | *send\_tick* | 78 | *send\_tick* |
73 | Sends a tick event to all subscribed clients. | 79 | Sends a tick event to all subscribed clients. |
80 | |||
81 | *subscribe* | ||
82 | Subscribe to a list of event types. The argument for this type should be | ||
83 | provided in the form of a valid JSON array. If any of the types are invalid | ||
84 | or if an valid JSON array is not provided, this will result in an failure. | ||