From 6ab8d2c7999aff99eebb0c5d1e01e3d4dbe86100 Mon Sep 17 00:00:00 2001 From: Artem Senichev Date: Sat, 10 Feb 2024 10:42:55 +0300 Subject: [PATCH] Handle floating sway windows Signed-off-by: Artem Senichev --- src/sway.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sway.c b/src/sway.c index a35c6fa..ad346a6 100644 --- a/src/sway.c +++ b/src/sway.c @@ -225,20 +225,24 @@ static struct json_object* current_workspace(json_object* node) */ static struct json_object* current_window(json_object* node) { + static const char* nnames[] = { "nodes", "floating_nodes" }; + struct json_object* focused; if (json_object_object_get_ex(node, "focused", &focused) && json_object_get_boolean(focused)) { return node; } - struct json_object* nodes; - if (json_object_object_get_ex(node, "nodes", &nodes)) { - int idx = json_object_array_length(nodes); - while (--idx >= 0) { - struct json_object* sub = json_object_array_get_idx(nodes, idx); - struct json_object* focus = current_window(sub); - if (focus) { - return focus; + for (size_t i = 0; i < sizeof(nnames) / sizeof(nnames[0]); ++i) { + struct json_object* nodes; + if (json_object_object_get_ex(node, nnames[i], &nodes)) { + int idx = json_object_array_length(nodes); + while (--idx >= 0) { + struct json_object* sub = json_object_array_get_idx(nodes, idx); + struct json_object* focus = current_window(sub); + if (focus) { + return focus; + } } } }