From dabe2bebbb9a66bf8be112ea56d5555c34e0c56a Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 14 Jun 2019 11:27:40 +0200 Subject: [PATCH] feat(sway/window): handle floating nodes --- include/modules/sway/ipc/client.hpp | 1 - include/modules/sway/window.hpp | 3 ++- src/modules/sway/window.cpp | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/modules/sway/ipc/client.hpp b/include/modules/sway/ipc/client.hpp index a3ef9456..629556f7 100644 --- a/include/modules/sway/ipc/client.hpp +++ b/include/modules/sway/ipc/client.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include "ipc.hpp" diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index 8568890c..c7a3ab2d 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -21,7 +21,8 @@ class Window : public ALabel, public sigc::trackable { void onEvent(const struct Ipc::ipc_response&); void onCmd(const struct Ipc::ipc_response&); void worker(); - std::tuple getFocusedNode(const Json::Value& nodes, std::string output); + std::tuple getFocusedNode(const Json::Value& nodes, + std::string& output); void getTree(); const Bar& bar_; diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 2d0747f1..25262b00 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -24,7 +24,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); auto output = payload["ouput"].isString() ? payload["output"].asString() : ""; - std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload, output); + std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output); dp.emit(); } catch (const std::exception& e) { spdlog::error("Window: {}", e.what()); @@ -70,23 +70,28 @@ auto Window::update() -> void { } std::tuple Window::getFocusedNode( - const Json::Value& nodes, std::string output) { - for (auto const& node : nodes["nodes"]) { + const Json::Value& nodes, std::string& output) { + for (auto const& node : nodes) { if (node["output"].isString()) { output = node["output"].asString(); } - if (node["focused"].asBool() && node["type"] == "con") { + if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) { if ((!config_["all-outputs"].asBool() && output == bar_.output->name) || config_["all-outputs"].asBool()) { auto app_id = node["app_id"].isString() ? node["app_id"].asString() : node["window_properties"]["instance"].asString(); - return {nodes["nodes"].size(), + return {nodes.size(), node["id"].asInt(), Glib::Markup::escape_text(node["name"].asString()), app_id}; } } - auto [nb, id, name, app_id] = getFocusedNode(node, output); + auto [nb, id, name, app_id] = getFocusedNode(node["nodes"], output); + if (id > -1 && !name.empty()) { + return {nb, id, name, app_id}; + } + // Search for floating node + std::tie(nb, id, name, app_id) = getFocusedNode(node["floating_nodes"], output); if (id > -1 && !name.empty()) { return {nb, id, name, app_id}; }