aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2021-12-12 20:19:22 +0100
committerLibravatar Simon Ser <contact@emersion.fr>2021-12-21 11:07:11 +0100
commit513fa00a5ecf91a59f96f0ce8dfad846aa81547e (patch)
tree5a457c1002ca7e67f8467262a145ea03c7944326
parentswaymsg: replace if with switch in pretty_print (diff)
downloadsway-513fa00a5ecf91a59f96f0ce8dfad846aa81547e.tar.gz
sway-513fa00a5ecf91a59f96f0ce8dfad846aa81547e.tar.zst
sway-513fa00a5ecf91a59f96f0ce8dfad846aa81547e.zip
swaymsg: add GET_TREE pretty-printing
-rw-r--r--swaymsg/main.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index b58c673c..02bb12c6 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -288,6 +288,51 @@ static void pretty_print_config(json_object *c) {
288 printf("%s\n", json_object_get_string(config)); 288 printf("%s\n", json_object_get_string(config));
289} 289}
290 290
291static void pretty_print_tree(json_object *obj, int indent) {
292 for (int i = 0; i < indent; i++) {
293 printf(" ");
294 }
295
296 int id = json_object_get_int(json_object_object_get(obj, "id"));
297 const char *name = json_object_get_string(json_object_object_get(obj, "name"));
298 const char *type = json_object_get_string(json_object_object_get(obj, "type"));
299 const char *shell = json_object_get_string(json_object_object_get(obj, "shell"));
300
301 printf("#%d: %s \"%s\"", id, type, name);
302
303 if (shell != NULL) {
304 int pid = json_object_get_int(json_object_object_get(obj, "pid"));
305 const char *app_id = json_object_get_string(json_object_object_get(obj, "app_id"));
306 json_object *window_props_obj = json_object_object_get(obj, "window_properties");
307 const char *instance = json_object_get_string(json_object_object_get(window_props_obj, "instance"));
308 const char *class = json_object_get_string(json_object_object_get(window_props_obj, "class"));
309 int x11_id = json_object_get_int(json_object_object_get(obj, "window"));
310
311 printf(" (%s, pid: %d", shell, pid);
312 if (app_id != NULL) {
313 printf(", app_id: \"%s\"", app_id);
314 }
315 if (instance != NULL) {
316 printf(", instance: \"%s\"", instance);
317 }
318 if (class != NULL) {
319 printf(", class: \"%s\"", class);
320 }
321 if (x11_id != 0) {
322 printf(", X11 window: 0x%X", x11_id);
323 }
324 printf(")");
325 }
326
327 printf("\n");
328
329 json_object *nodes_obj = json_object_object_get(obj, "nodes");
330 size_t len = json_object_array_length(nodes_obj);
331 for (size_t i = 0; i < len; i++) {
332 pretty_print_tree(json_object_array_get_idx(nodes_obj, i), indent + 1);
333 }
334}
335
291static void pretty_print(int type, json_object *resp) { 336static void pretty_print(int type, json_object *resp) {
292 switch (type) { 337 switch (type) {
293 case IPC_SEND_TICK: 338 case IPC_SEND_TICK:
@@ -298,6 +343,9 @@ static void pretty_print(int type, json_object *resp) {
298 case IPC_GET_CONFIG: 343 case IPC_GET_CONFIG:
299 pretty_print_config(resp); 344 pretty_print_config(resp);
300 return; 345 return;
346 case IPC_GET_TREE:
347 pretty_print_tree(resp, 0);
348 return;
301 case IPC_COMMAND: 349 case IPC_COMMAND:
302 case IPC_GET_WORKSPACES: 350 case IPC_GET_WORKSPACES:
303 case IPC_GET_INPUTS: 351 case IPC_GET_INPUTS: