summaryrefslogtreecommitdiff
path: root/swaymsg/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaymsg/main.c')
-rw-r--r--swaymsg/main.c74
1 files changed, 60 insertions, 14 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 0d9dc5a0..02bb12c6 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -288,28 +288,74 @@ static void pretty_print_config(json_object *c) {
printf("%s\n", json_object_get_string(config));
}
-static void pretty_print(int type, json_object *resp) {
- if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
- type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
- type != IPC_GET_VERSION && type != IPC_GET_SEATS &&
- type != IPC_GET_CONFIG && type != IPC_SEND_TICK) {
- printf("%s\n", json_object_to_json_string_ext(resp,
- JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
- return;
+static void pretty_print_tree(json_object *obj, int indent) {
+ for (int i = 0; i < indent; i++) {
+ printf(" ");
}
- if (type == IPC_SEND_TICK) {
- return;
+ int id = json_object_get_int(json_object_object_get(obj, "id"));
+ const char *name = json_object_get_string(json_object_object_get(obj, "name"));
+ const char *type = json_object_get_string(json_object_object_get(obj, "type"));
+ const char *shell = json_object_get_string(json_object_object_get(obj, "shell"));
+
+ printf("#%d: %s \"%s\"", id, type, name);
+
+ if (shell != NULL) {
+ int pid = json_object_get_int(json_object_object_get(obj, "pid"));
+ const char *app_id = json_object_get_string(json_object_object_get(obj, "app_id"));
+ json_object *window_props_obj = json_object_object_get(obj, "window_properties");
+ const char *instance = json_object_get_string(json_object_object_get(window_props_obj, "instance"));
+ const char *class = json_object_get_string(json_object_object_get(window_props_obj, "class"));
+ int x11_id = json_object_get_int(json_object_object_get(obj, "window"));
+
+ printf(" (%s, pid: %d", shell, pid);
+ if (app_id != NULL) {
+ printf(", app_id: \"%s\"", app_id);
+ }
+ if (instance != NULL) {
+ printf(", instance: \"%s\"", instance);
+ }
+ if (class != NULL) {
+ printf(", class: \"%s\"", class);
+ }
+ if (x11_id != 0) {
+ printf(", X11 window: 0x%X", x11_id);
+ }
+ printf(")");
}
- if (type == IPC_GET_VERSION) {
- pretty_print_version(resp);
- return;
+ printf("\n");
+
+ json_object *nodes_obj = json_object_object_get(obj, "nodes");
+ size_t len = json_object_array_length(nodes_obj);
+ for (size_t i = 0; i < len; i++) {
+ pretty_print_tree(json_object_array_get_idx(nodes_obj, i), indent + 1);
}
+}
- if (type == IPC_GET_CONFIG) {
+static void pretty_print(int type, json_object *resp) {
+ switch (type) {
+ case IPC_SEND_TICK:
+ return;
+ case IPC_GET_VERSION:
+ pretty_print_version(resp);
+ return;
+ case IPC_GET_CONFIG:
pretty_print_config(resp);
return;
+ case IPC_GET_TREE:
+ pretty_print_tree(resp, 0);
+ return;
+ case IPC_COMMAND:
+ case IPC_GET_WORKSPACES:
+ case IPC_GET_INPUTS:
+ case IPC_GET_OUTPUTS:
+ case IPC_GET_SEATS:
+ break;
+ default:
+ printf("%s\n", json_object_to_json_string_ext(resp,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
+ return;
}
json_object *obj;