From 259fe1e76f752a842dc495bcc9862119a1e0b378 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Sat, 27 Oct 2018 18:29:56 +0100 Subject: [PATCH 1/2] ipc: remove class key from view json It turns out that i3 does not have a `class` key in the json description of a view, but provides it through `window_properties.class`. Since `window_properties` has been added by 8fc9328, we can remove `class` altogether. Signed-off-by: Franklin "Snaipe" Mathieu --- sway/ipc-json.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 2cd0cb2d..5d1393bc 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -229,10 +229,6 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_object_add(object, "app_id", app_id ? json_object_new_string(app_id) : NULL); - const char *class = view_get_class(c->view); - json_object_object_add(object, "class", - class ? json_object_new_string(class) : NULL); - json_object *marks = json_object_new_array(); list_t *view_marks = c->view->marks; for (int i = 0; i < view_marks->length; ++i) { @@ -269,6 +265,7 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object *window_props = json_object_new_object(); + const char *class = view_get_class(c->view); json_object_object_add(window_props, "class", class ? json_object_new_string(class) : NULL); const char *instance = view_get_instance(c->view); From 03ca8596d6bcec0a83567d9b51a71ccc7db197e5 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Sat, 27 Oct 2018 18:35:31 +0100 Subject: [PATCH 2/2] ipc: make class, instance, and title window properties optional i3 seems to make all window properties, with the exception of transient_for, optional[1]. [1]: https://github.com/i3/i3/blob/315ff17563fd703b2f5117b2ec4d46e89389d323/src/ipc.c#L435-L450 Signed-off-by: Franklin "Snaipe" Mathieu --- sway/ipc-json.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 5d1393bc..5c9b3e5a 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -266,13 +266,16 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object *window_props = json_object_new_object(); const char *class = view_get_class(c->view); - json_object_object_add(window_props, "class", - class ? json_object_new_string(class) : NULL); + if (class) { + json_object_object_add(window_props, "class", json_object_new_string(class)); + } const char *instance = view_get_instance(c->view); - json_object_object_add(window_props, "instance", - instance ? json_object_new_string(instance) : NULL); - json_object_object_add(window_props, "title", - c->title ? json_object_new_string(c->title) : NULL); + if (instance) { + json_object_object_add(window_props, "instance", json_object_new_string(instance)); + } + if (c->title) { + json_object_object_add(window_props, "title", json_object_new_string(c->title)); + } // the transient_for key is always present in i3's output uint32_t parent_id = view_get_x11_parent_id(c->view); @@ -281,8 +284,7 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object const char *role = view_get_window_role(c->view); if (role) { - json_object_object_add(window_props, "window_role", - json_object_new_string(role)); + json_object_object_add(window_props, "window_role", json_object_new_string(role)); } json_object_object_add(object, "window_properties", window_props);