From 5bfdbf116d8d184a168ebaed6003a2326d495947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20Marussy?= Date: Tue, 13 Jun 2023 01:37:45 +0200 Subject: [PATCH] sway/window: app_id on unfocused workspaces If the unfocused workspace has a single window, use window-specific styling when offscreen-css is enabled. --- src/modules/sway/window.cpp | 55 +++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 030f93b..be6bce0 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -251,6 +251,39 @@ std::pair leafNodesInWorkspace(const Json::Value& node) { return {sum, floating_sum}; } +std::optional> getSingleChildNode(const Json::Value& node) { + auto const& nodes = node["nodes"]; + if (nodes.empty()) { + if (node["type"].asString() == "workspace") + return {}; + else if (node["type"].asString() == "floating_con") { + return {}; + } else { + return {std::cref(node)}; + } + } + auto it = std::cbegin(nodes); + if (it == std::cend(nodes)) { + return {}; + } + auto const& child = *it; + ++it; + if (it != std::cend(nodes)) { + return {}; + } + return {getSingleChildNode(child)}; +} + +std::tuple getWindowInfo(const Json::Value& node) { + const auto app_id = node["app_id"].isString() ? node["app_id"].asString() + : node["window_properties"]["instance"].asString(); + const auto app_class = node["window_properties"]["class"].isString() + ? node["window_properties"]["class"].asString() + : ""; + const auto shell = node["shell"].isString() ? node["shell"].asString() : ""; + return {app_id, app_class, shell}; +} + std::tuple gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Value& config_, const Bar& bar_, Json::Value& parentWorkspace, @@ -287,12 +320,7 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu // found node spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name, output, node["name"].asString()); - auto app_id = node["app_id"].isString() ? node["app_id"].asString() - : node["window_properties"]["instance"].asString(); - const auto app_class = node["window_properties"]["class"].isString() - ? node["window_properties"]["class"].asString() - : ""; - const auto shell = node["shell"].isString() ? node["shell"].asString() : ""; + const auto [app_id, app_class, shell] = getWindowInfo(node); int nb = node.size(); int floating_count = 0; std::string workspace_layout = ""; @@ -332,15 +360,24 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu std::pair all_leaf_nodes = leafNodesInWorkspace(immediateParent); // using an empty string as default ensures that no window depending styles are set due to the // checks above for !name.empty() + std::string app_id = ""; + std::string app_class = ""; + std::string workspace_layout = ""; + if (all_leaf_nodes.first == 1) { + const auto single_child = getSingleChildNode(immediateParent); + if (single_child.has_value()) { + std::tie(app_id, app_class, workspace_layout) = getWindowInfo(single_child.value()); + } + } return {all_leaf_nodes.first, all_leaf_nodes.second, 0, (all_leaf_nodes.first > 0 || all_leaf_nodes.second > 0) ? config_["offscreen-css-text"].asString() : "", - "", - "", - "", + app_id, + app_class, + workspace_layout, immediateParent["layout"].asString()}; }