From b1d70f25b3f22027959d60e24f57b8f965fdd757 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Wed, 15 Jun 2016 22:25:22 +0200 Subject: [PATCH] Introduced a new GET_BINDING_MODES message type and reply. (#2376) This type dumps all currently configured binding modes. fixes #2375 --- docs/ipc | 13 +++++++++++++ i3-msg/main.c | 4 +++- include/i3/ipc.h | 20 ++++---------------- man/i3-msg.man | 3 +++ src/ipc.c | 25 ++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/docs/ipc b/docs/ipc index 033d5018..ddadabc4 100644 --- a/docs/ipc +++ b/docs/ipc @@ -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]] diff --git a/i3-msg/main.c b/i3-msg/main.c index 36691cae..658c33b4 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -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') { diff --git a/include/i3/ipc.h b/include/i3/ipc.h index 8912bf13..98ac35b0 100644 --- a/include/i3/ipc.h +++ b/include/i3/ipc.h @@ -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. diff --git a/man/i3-msg.man b/man/i3-msg.man index 000d9bf2..e81a94ab 100644 --- a/man/i3-msg.man +++ b/man/i3-msg.man @@ -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. diff --git a/src/ipc.c b/src/ipc.c index 2bd5f59d..a6c45ed1 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -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, }; /* -- 2.39.5