ipc: add tick event
This commit is contained in:
parent
33433c6434
commit
3edaf2ce2a
|
@ -16,6 +16,7 @@ _swaymsg()
|
|||
'get_version'
|
||||
'get_binding_modes'
|
||||
'get_config'
|
||||
'send_tick'
|
||||
)
|
||||
|
||||
short=(
|
||||
|
|
|
@ -24,6 +24,7 @@ types=(
|
|||
'get_version'
|
||||
'get_binding_modes'
|
||||
'get_config'
|
||||
'send_tick'
|
||||
)
|
||||
|
||||
_arguments -s \
|
||||
|
|
|
@ -15,6 +15,7 @@ enum ipc_command_type {
|
|||
IPC_GET_VERSION = 7,
|
||||
IPC_GET_BINDING_MODES = 8,
|
||||
IPC_GET_CONFIG = 9,
|
||||
IPC_SEND_TICK = 10,
|
||||
|
||||
// sway-specific command types
|
||||
IPC_GET_INPUTS = 100,
|
||||
|
@ -28,6 +29,7 @@ enum ipc_command_type {
|
|||
IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4),
|
||||
IPC_EVENT_BINDING = ((1<<31) | 5),
|
||||
IPC_EVENT_SHUTDOWN = ((1<<31) | 6),
|
||||
IPC_EVENT_TICK = ((1<<31) | 7),
|
||||
IPC_EVENT_MODIFIER = ((1<<31) | 16),
|
||||
IPC_EVENT_INPUT = ((1<<31) | 17),
|
||||
};
|
||||
|
|
|
@ -441,6 +441,21 @@ void ipc_event_binding(struct sway_binding *binding) {
|
|||
json_object_put(json);
|
||||
}
|
||||
|
||||
static void ipc_event_tick(const char *payload) {
|
||||
if (!ipc_has_event_listeners(IPC_EVENT_TICK)) {
|
||||
return;
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "Sending tick event");
|
||||
|
||||
json_object *json = json_object_new_object();
|
||||
json_object_object_add(json, "first", json_object_new_boolean(false));
|
||||
json_object_object_add(json, "payload", json_object_new_string(payload));
|
||||
|
||||
const char *json_string = json_object_to_json_string(json);
|
||||
ipc_send_event(json_string, IPC_EVENT_TICK);
|
||||
json_object_put(json);
|
||||
}
|
||||
|
||||
int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
|
||||
struct ipc_client *client = data;
|
||||
|
||||
|
@ -582,6 +597,13 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
case IPC_SEND_TICK:
|
||||
{
|
||||
ipc_event_tick(buf);
|
||||
ipc_send_reply(client, "{\"success\": true}", 17);
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
case IPC_GET_OUTPUTS:
|
||||
{
|
||||
json_object *outputs = json_object_new_array();
|
||||
|
@ -628,6 +650,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
bool is_tick = false;
|
||||
// parse requested event types
|
||||
for (size_t i = 0; i < json_object_array_length(request); i++) {
|
||||
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
|
||||
|
@ -645,6 +668,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER);
|
||||
} else if (strcmp(event_type, "binding") == 0) {
|
||||
client->subscribed_events |= event_mask(IPC_EVENT_BINDING);
|
||||
} else if (strcmp(event_type, "tick") == 0) {
|
||||
client->subscribed_events |= event_mask(IPC_EVENT_TICK);
|
||||
is_tick = true;
|
||||
} else {
|
||||
client_valid =
|
||||
ipc_send_reply(client, "{\"success\": false}", 18);
|
||||
|
@ -656,6 +682,10 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
|||
|
||||
json_object_put(request);
|
||||
client_valid = ipc_send_reply(client, "{\"success\": true}", 17);
|
||||
if (is_tick) {
|
||||
client->current_command = IPC_EVENT_TICK;
|
||||
ipc_send_reply(client, "{\"first\": true, \"payload\": \"\"}", 30);
|
||||
}
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
|
|
|
@ -250,12 +250,16 @@ static void pretty_print(int type, json_object *resp) {
|
|||
if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
|
||||
type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
|
||||
type != IPC_GET_VERSION && type != IPC_GET_SEATS &&
|
||||
type != IPC_GET_CONFIG) {
|
||||
type != IPC_GET_CONFIG && type != IPC_SEND_TICK) {
|
||||
printf("%s\n", json_object_to_json_string_ext(resp,
|
||||
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == IPC_SEND_TICK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == IPC_GET_VERSION) {
|
||||
pretty_print_version(resp);
|
||||
return;
|
||||
|
@ -384,6 +388,8 @@ int main(int argc, char **argv) {
|
|||
type = IPC_GET_BINDING_MODES;
|
||||
} else if (strcasecmp(cmdtype, "get_config") == 0) {
|
||||
type = IPC_GET_CONFIG;
|
||||
} else if (strcasecmp(cmdtype, "send_tick") == 0) {
|
||||
type = IPC_SEND_TICK;
|
||||
} else {
|
||||
sway_abort("Unknown message type %s", cmdtype);
|
||||
}
|
||||
|
|
|
@ -64,3 +64,6 @@ _swaymsg_ [options...] [message]
|
|||
|
||||
*get\_config*
|
||||
Gets a JSON-encoded copy of the current configuration.
|
||||
|
||||
*send\_tick*
|
||||
Sends a tick event to all subscribed clients.
|
||||
|
|
Loading…
Reference in a new issue