mirror of
https://github.com/swaywm/sway.git
synced 2025-11-05 13:29:51 -05:00
Implement support for swaymsg -t SUBSCRIBE [-m]
In `i3 4.16`, `i3-msg` can be used with the message type `subscribe` and has the ability to monitor for responses until killed. This adds support for both to swaymsg. If the JSON array of event types is malformed or contains an invalid event, sway will send a response with `success` set to `false`. If swaymsg sees this, it will not display the failure and exit. If the `subscribe` event is successful, swaymsg will wait for the first response and display that instead of the success message. If `-m/--monitor` is given, swaymsg will continue monitor for responses until killed or a malformed response is received. For the `subscribe` event, the responses will always be printed as JSON. If `-r/--raw` is given, the JSON will not be pretty printed, which may be preferred when monitoring due to there being multiple responses. Example: `swaymsg -t SUBSCRIBE -m "['window']"`
This commit is contained in:
parent
a22d0c0ff6
commit
bf9a52bab0
3 changed files with 76 additions and 18 deletions
|
|
@ -668,7 +668,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
// TODO: Check if they're permitted to use these events
|
||||
struct json_object *request = json_tokener_parse(buf);
|
||||
if (request == NULL) {
|
||||
client_valid = ipc_send_reply(client, "{\"success\": false}", 18);
|
||||
const char msg[] = "[{\"success\": false}]";
|
||||
client_valid = ipc_send_reply(client, msg, strlen(msg));
|
||||
wlr_log(WLR_INFO, "Failed to parse subscribe request");
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
|
@ -695,8 +696,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
client->subscribed_events |= event_mask(IPC_EVENT_TICK);
|
||||
is_tick = true;
|
||||
} else {
|
||||
client_valid =
|
||||
ipc_send_reply(client, "{\"success\": false}", 18);
|
||||
const char msg[] = "[{\"success\": false}]";
|
||||
client_valid = ipc_send_reply(client, msg, strlen(msg));
|
||||
json_object_put(request);
|
||||
wlr_log(WLR_INFO, "Unsupported event type in subscribe request");
|
||||
goto exit_cleanup;
|
||||
|
|
@ -704,10 +705,12 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
}
|
||||
|
||||
json_object_put(request);
|
||||
client_valid = ipc_send_reply(client, "{\"success\": true}", 17);
|
||||
const char msg[] = "[{\"success\": true}]";
|
||||
client_valid = ipc_send_reply(client, msg, strlen(msg));
|
||||
if (is_tick) {
|
||||
client->current_command = IPC_EVENT_TICK;
|
||||
ipc_send_reply(client, "{\"first\": true, \"payload\": \"\"}", 30);
|
||||
const char tickmsg[] = "{\"first\": true, \"payload\": \"\"}";
|
||||
ipc_send_reply(client, tickmsg, strlen(tickmsg));
|
||||
}
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue