sway workspace: fix workspace button not shown in nested layouts

This commit is contained in:
Almarhoon Ibraheem
2025-04-12 18:31:34 +03:00
parent 056295cbc6
commit 7e845f506e

View File

@ -494,16 +494,34 @@ std::string Workspaces::trimWorkspaceName(std::string name) {
return name; return name;
} }
void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) { bool is_focused_recursive(const Json::Value& node) {
if (config_["current-only"].asBool()) {
// If a workspace has a focused container then get_tree will say // If a workspace has a focused container then get_tree will say
// that the workspace itself isn't focused. Therefore we need to // that the workspace itself isn't focused. Therefore we need to
// check if any of its nodes are focused as well. // check if any of its nodes are focused as well.
bool focused = node["focused"].asBool() || // some layouts like tabbed have many nested nodes
std::any_of(node["nodes"].begin(), node["nodes"].end(), // all nested nodes must be checked for focused flag
[](const auto &child) { return child["focused"].asBool(); }); if (node["focused"].asBool()) {
return true;
}
if (focused) { for (const auto& child : node["nodes"]) {
if (is_focused_recursive(child)) {
return true;
}
}
for (const auto& child : node["floating_nodes"]) {
if (is_focused_recursive(child)) {
return true;
}
}
return false;
}
void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
if (config_["current-only"].asBool()) {
if (is_focused_recursive(node)) {
button.show(); button.show();
} else { } else {
button.hide(); button.hide();