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;
|
||||
}
|
||||
|
||||
void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
|
||||
if (config_["current-only"].asBool()) {
|
||||
bool is_focused_recursive(const Json::Value& node) {
|
||||
// If a workspace has a focused container then get_tree will say
|
||||
// that the workspace itself isn't focused. Therefore we need to
|
||||
// check if any of its nodes are focused as well.
|
||||
bool focused = node["focused"].asBool() ||
|
||||
std::any_of(node["nodes"].begin(), node["nodes"].end(),
|
||||
[](const auto &child) { return child["focused"].asBool(); });
|
||||
// some layouts like tabbed have many nested nodes
|
||||
// all nested nodes must be checked for focused flag
|
||||
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();
|
||||
} else {
|
||||
button.hide();
|
||||
|
Reference in New Issue
Block a user