ipc: add GET_BINDING_STATE request

This commit is contained in:
Ronan Pigott 2020-06-13 20:39:57 -07:00
parent f9361ae36c
commit 4a5f7d3721
4 changed files with 47 additions and 1 deletions

View file

@ -17,6 +17,7 @@ enum ipc_command_type {
IPC_GET_CONFIG = 9,
IPC_SEND_TICK = 10,
IPC_SYNC = 11,
IPC_GET_BINDING_STATE = 12,
// sway-specific command types
IPC_GET_INPUTS = 100,

View file

@ -895,6 +895,18 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
goto exit_cleanup;
}
case IPC_GET_BINDING_STATE:
{
json_object *json = json_object_new_object();
json_object_object_add(json, "name",
json_object_new_string(config->current_mode->name));
const char *json_string = json_object_to_json_string(json);
ipc_send_reply(client, payload_type, json_string,
(uint32_t)strlen(json_string));
json_object_put(json); //free
goto exit_cleanup;
}
default:
sway_log(SWAY_INFO, "Unknown IPC command type %x", payload_type);
goto exit_cleanup;

View file

@ -75,6 +75,9 @@ supported. *For all replies, any properties not listed are subject to removal.*
|- 11
: SYNC
: Replies failure object for i3 compatibility
|- 12
: GET_BINDING_STATE
: Get the currently active binding mode name
|- 100
: GET_INPUTS
: Get the list of input devices
@ -1067,6 +1070,22 @@ boolean value _false_.
}
```
## 12. GET_BINDING_STATE
*MESSAGE*++
Retrieve the name of the current binding mode
*REPLY*++
An object with a single string property _name_ with the name of the current
binding mode.
*Example Reply:*
```
{
"name": "default"
}
```
## 100. GET_INPUTS
*MESSAGE*++

View file

@ -286,11 +286,18 @@ static void pretty_print_config(json_object *c) {
printf("%s\n", json_object_get_string(config));
}
static void pretty_print_binding_state(json_object *m) {
json_object *name;
json_object_object_get_ex(m, "name", &name);
printf("%s\n", json_object_get_string(name));
}
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_SEND_TICK) {
type != IPC_GET_CONFIG && type != IPC_SEND_TICK &&
type != IPC_GET_BINDING_STATE) {
printf("%s\n", json_object_to_json_string_ext(resp,
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
return;
@ -310,6 +317,11 @@ static void pretty_print(int type, json_object *resp) {
return;
}
if (type == IPC_GET_BINDING_STATE) {
pretty_print_binding_state(resp);
return;
}
json_object *obj;
size_t len = json_object_array_length(resp);
for (size_t i = 0; i < len; ++i) {
@ -440,6 +452,8 @@ int main(int argc, char **argv) {
type = IPC_GET_VERSION;
} else if (strcasecmp(cmdtype, "get_binding_modes") == 0) {
type = IPC_GET_BINDING_MODES;
} else if (strcasecmp(cmdtype, "get_binding_state") == 0) {
type = IPC_GET_BINDING_STATE;
} else if (strcasecmp(cmdtype, "get_config") == 0) {
type = IPC_GET_CONFIG;
} else if (strcasecmp(cmdtype, "send_tick") == 0) {