From 486b5a5d3897faefbe778b776f0914365344efbe Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 14 Jun 2019 10:57:22 +0200 Subject: [PATCH] fix(sway/window): check output recursively --- include/modules/sway/window.hpp | 2 +- src/modules/sway/window.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index 0570c1f..8568890 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -21,7 +21,7 @@ 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::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 5df96ac..2d0747f 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -23,7 +23,8 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { try { std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); - std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload); + auto output = payload["ouput"].isString() ? payload["output"].asString() : ""; + std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload, output); dp.emit(); } catch (const std::exception& e) { spdlog::error("Window: {}", e.what()); @@ -69,10 +70,13 @@ auto Window::update() -> void { } std::tuple Window::getFocusedNode( - const Json::Value& nodes) { + const Json::Value& nodes, std::string output) { for (auto const& node : nodes["nodes"]) { + if (node["output"].isString()) { + output = node["output"].asString(); + } if (node["focused"].asBool() && node["type"] == "con") { - if ((!config_["all-outputs"].asBool() && nodes["output"] == bar_.output->name) || + 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(); @@ -82,7 +86,7 @@ std::tuple Window::getFocusedNode( app_id}; } } - auto [nb, id, name, app_id] = getFocusedNode(node); + auto [nb, id, name, app_id] = getFocusedNode(node, output); if (id > -1 && !name.empty()) { return {nb, id, name, app_id}; }