Merge pull request #4046 from ebeem/sway-workspace-current-not-shown-fix
Sway Workspace: Fix workspace button not showing for tabbed/nested layouts
This commit is contained in:
@ -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();
|
||||||
|
Reference in New Issue
Block a user