summaryrefslogtreecommitdiffstats
path: root/swaymsg
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2016-07-31 14:45:53 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2016-07-31 14:47:32 -0400
commit6535da7bdeb8e4bf36de89bf861d20d22ffe5efa (patch)
treed9c7dbc2236cc6e39fb70229f9bb95e808a0ce3c /swaymsg
parentMerge pull request #808 from zandrmartin/document-kill-command (diff)
downloadsway-6535da7bdeb8e4bf36de89bf861d20d22ffe5efa.tar.gz
sway-6535da7bdeb8e4bf36de89bf861d20d22ffe5efa.tar.zst
sway-6535da7bdeb8e4bf36de89bf861d20d22ffe5efa.zip
swaymsg: pretty print ipc response
fixes #809
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/CMakeLists.txt3
-rw-r--r--swaymsg/main.c16
2 files changed, 16 insertions, 3 deletions
diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt
index 06939991..a4989b9c 100644
--- a/swaymsg/CMakeLists.txt
+++ b/swaymsg/CMakeLists.txt
@@ -4,7 +4,8 @@ add_executable(swaymsg
4 4
5target_link_libraries(swaymsg 5target_link_libraries(swaymsg
6 sway-common 6 sway-common
7 ) 7 ${JSONC_LIBRARIES}
8)
8 9
9install( 10install(
10 TARGETS swaymsg 11 TARGETS swaymsg
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 88a8fab0..29e80f02 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -6,6 +6,7 @@
6#include <sys/un.h> 6#include <sys/un.h>
7#include <sys/socket.h> 7#include <sys/socket.h>
8#include <unistd.h> 8#include <unistd.h>
9#include <json-c/json.h>
9#include "stringop.h" 10#include "stringop.h"
10#include "ipc-client.h" 11#include "ipc-client.h"
11#include "readline.h" 12#include "readline.h"
@@ -109,16 +110,27 @@ int main(int argc, char **argv) {
109 command = join_args(argv + optind, argc - optind); 110 command = join_args(argv + optind, argc - optind);
110 } 111 }
111 112
113 int ret = 0;
112 int socketfd = ipc_open_socket(socket_path); 114 int socketfd = ipc_open_socket(socket_path);
113 uint32_t len = strlen(command); 115 uint32_t len = strlen(command);
114 char *resp = ipc_single_command(socketfd, type, command, &len); 116 char *resp = ipc_single_command(socketfd, type, command, &len);
115 if (!quiet) { 117 if (!quiet) {
116 printf("%s\n", resp); 118 // pretty print the json
119 json_object *obj = json_tokener_parse(resp);
120
121 if (obj == NULL) {
122 fprintf(stderr, "ERROR: Could not parse json response from ipc. This is a bug in sway.");
123 printf("%s\n", resp);
124 ret = 1;
125 } else {
126 printf("%s\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
127 free(obj);
128 }
117 } 129 }
118 close(socketfd); 130 close(socketfd);
119 131
120 free(command); 132 free(command);
121 free(resp); 133 free(resp);
122 free(socket_path); 134 free(socket_path);
123 return 0; 135 return ret;
124} 136}