Introduced a new GET_BINDING_MODES message type and reply. (#2376)

This type dumps all currently configured binding modes.

fixes #2375
next
Ingo Bürk 2016-06-15 22:25:22 +02:00 committed by Michael Stapelberg
parent 63d0823016
commit b1d70f25b3
5 changed files with 47 additions and 18 deletions

View File

@ -80,6 +80,8 @@ GET_BAR_CONFIG (6)::
GET_VERSION (7)::
Gets the version of i3. The reply will be a JSON-encoded dictionary
with the major, minor, patch and human-readable version.
GET_BINDING_MODES (8)::
Gets a list of currently configured binding modes.
So, a typical message could look like this:
--------------------------------------------------
@ -137,6 +139,8 @@ BAR_CONFIG (6)::
Reply to the GET_BAR_CONFIG message.
VERSION (7)::
Reply to the GET_VERSION message.
BINDING_MODES (8)::
Reply to the GET_BINDING_MODES message.
=== COMMAND reply
@ -604,6 +608,15 @@ loaded_config_file_name (string)::
}
-------------------
=== BINDING_MODES reply
The reply consists of an array of all currently configured binding modes.
*Example:*
---------------------
["default", "resize"]
---------------------
== Events
[[events]]

View File

@ -161,11 +161,13 @@ int main(int argc, char *argv[]) {
message_type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
else if (strcasecmp(optarg, "get_bar_config") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG;
else if (strcasecmp(optarg, "get_binding_modes") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_BINDING_MODES;
else if (strcasecmp(optarg, "get_version") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_VERSION;
else {
printf("Unknown message type\n");
printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_version\n");
printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_binding_modes, get_version\n");
exit(EXIT_FAILURE);
}
} else if (o == 'q') {

View File

@ -51,34 +51,22 @@ typedef struct i3_ipc_header {
/** Request the i3 version */
#define I3_IPC_MESSAGE_TYPE_GET_VERSION 7
/** Request a list of configured binding modes. */
#define I3_IPC_MESSAGE_TYPE_GET_BINDING_MODES 8
/*
* Messages from i3 to clients
*
*/
/** Command reply type */
#define I3_IPC_REPLY_TYPE_COMMAND 0
/** Workspaces reply type */
#define I3_IPC_REPLY_TYPE_WORKSPACES 1
/** Subscription reply type */
#define I3_IPC_REPLY_TYPE_SUBSCRIBE 2
/** Outputs reply type */
#define I3_IPC_REPLY_TYPE_OUTPUTS 3
/** Tree reply type */
#define I3_IPC_REPLY_TYPE_TREE 4
/** Marks reply type */
#define I3_IPC_REPLY_TYPE_MARKS 5
/** Bar config reply type */
#define I3_IPC_REPLY_TYPE_BAR_CONFIG 6
/** i3 version reply type */
#define I3_IPC_REPLY_TYPE_VERSION 7
#define I3_IPC_REPLY_TYPE_BINDING_MODES 8
/*
* Events from i3 to clients. Events have the first bit set high.

View File

@ -62,6 +62,9 @@ get_bar_config::
Gets the configuration (as JSON map) of the workspace bar with the given ID. If
no ID is provided, an array with all configured bar IDs is returned instead.
get_binding_modes::
Gets a list of configured binding modes.
get_version::
Gets the version of i3. The reply will be a JSON-encoded dictionary with the
major, minor, patch and human-readable version.

View File

@ -958,6 +958,28 @@ IPC_HANDLER(get_bar_config) {
y(free);
}
/*
* Returns a list of configured binding modes
*
*/
IPC_HANDLER(get_binding_modes) {
yajl_gen gen = ygenalloc();
y(array_open);
struct Mode *mode;
SLIST_FOREACH(mode, &modes, modes) {
ystr(mode->name);
}
y(array_close);
const unsigned char *payload;
ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_BINDING_MODES, payload);
y(free);
}
/*
* Callback for the YAJL parser (will be called when a string is parsed).
*
@ -1034,7 +1056,7 @@ IPC_HANDLER(subscribe) {
/* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */
handler_t handlers[8] = {
handler_t handlers[9] = {
handle_command,
handle_get_workspaces,
handle_subscribe,
@ -1043,6 +1065,7 @@ handler_t handlers[8] = {
handle_get_marks,
handle_get_bar_config,
handle_get_version,
handle_get_binding_modes,
};
/*