mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -04:00
ipc: add GET_BINDING_STATE request
This commit is contained in:
parent
f9361ae36c
commit
4a5f7d3721
4 changed files with 47 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ enum ipc_command_type {
|
||||||
IPC_GET_CONFIG = 9,
|
IPC_GET_CONFIG = 9,
|
||||||
IPC_SEND_TICK = 10,
|
IPC_SEND_TICK = 10,
|
||||||
IPC_SYNC = 11,
|
IPC_SYNC = 11,
|
||||||
|
IPC_GET_BINDING_STATE = 12,
|
||||||
|
|
||||||
// sway-specific command types
|
// sway-specific command types
|
||||||
IPC_GET_INPUTS = 100,
|
IPC_GET_INPUTS = 100,
|
||||||
|
|
|
||||||
|
|
@ -895,6 +895,18 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
|
||||||
goto exit_cleanup;
|
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:
|
default:
|
||||||
sway_log(SWAY_INFO, "Unknown IPC command type %x", payload_type);
|
sway_log(SWAY_INFO, "Unknown IPC command type %x", payload_type);
|
||||||
goto exit_cleanup;
|
goto exit_cleanup;
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ supported. *For all replies, any properties not listed are subject to removal.*
|
||||||
|- 11
|
|- 11
|
||||||
: SYNC
|
: SYNC
|
||||||
: Replies failure object for i3 compatibility
|
: Replies failure object for i3 compatibility
|
||||||
|
|- 12
|
||||||
|
: GET_BINDING_STATE
|
||||||
|
: Get the currently active binding mode name
|
||||||
|- 100
|
|- 100
|
||||||
: GET_INPUTS
|
: GET_INPUTS
|
||||||
: Get the list of input devices
|
: 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
|
## 100. GET_INPUTS
|
||||||
|
|
||||||
*MESSAGE*++
|
*MESSAGE*++
|
||||||
|
|
|
||||||
|
|
@ -286,11 +286,18 @@ static void pretty_print_config(json_object *c) {
|
||||||
printf("%s\n", json_object_get_string(config));
|
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) {
|
static void pretty_print(int type, json_object *resp) {
|
||||||
if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
|
if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
|
||||||
type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
|
type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
|
||||||
type != IPC_GET_VERSION && type != IPC_GET_SEATS &&
|
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,
|
printf("%s\n", json_object_to_json_string_ext(resp,
|
||||||
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
|
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
|
||||||
return;
|
return;
|
||||||
|
|
@ -310,6 +317,11 @@ static void pretty_print(int type, json_object *resp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == IPC_GET_BINDING_STATE) {
|
||||||
|
pretty_print_binding_state(resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
json_object *obj;
|
json_object *obj;
|
||||||
size_t len = json_object_array_length(resp);
|
size_t len = json_object_array_length(resp);
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
|
@ -440,6 +452,8 @@ int main(int argc, char **argv) {
|
||||||
type = IPC_GET_VERSION;
|
type = IPC_GET_VERSION;
|
||||||
} else if (strcasecmp(cmdtype, "get_binding_modes") == 0) {
|
} else if (strcasecmp(cmdtype, "get_binding_modes") == 0) {
|
||||||
type = IPC_GET_BINDING_MODES;
|
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) {
|
} else if (strcasecmp(cmdtype, "get_config") == 0) {
|
||||||
type = IPC_GET_CONFIG;
|
type = IPC_GET_CONFIG;
|
||||||
} else if (strcasecmp(cmdtype, "send_tick") == 0) {
|
} else if (strcasecmp(cmdtype, "send_tick") == 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue