Fix Sway #waybar.solo CSS rule applying on split
This error occurs because of an incorrect assumption that the size of the list of nodes that contains the focused window is the number of windows in a workspace. The windows in a workspace are stored as a tree by Sway, rather than a list, so the number of windows has to be found by counting the leaves of a workspace tree.
This commit is contained in:
parent
f91dc7fb6e
commit
85ca5027f4
|
@ -64,29 +64,51 @@ auto Window::update() -> void {
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
int leafNodesInWorkspace(const Json::Value& node) {
|
||||||
const Json::Value& nodes, std::string& output) {
|
auto const& nodes = node["nodes"];
|
||||||
for (auto const& node : nodes) {
|
if(nodes.empty()) {
|
||||||
|
if(node["type"] == "workspace")
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for(auto const& node : nodes)
|
||||||
|
sum += leafNodesInWorkspace(node);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<std::size_t, int, std::string, std::string> gfnWithWorkspace(
|
||||||
|
const Json::Value& nodes, std::string& output, const Json::Value& config_,
|
||||||
|
const Bar& bar_, Json::Value& parentWorkspace) {
|
||||||
|
for(auto const& node : nodes) {
|
||||||
if (node["output"].isString()) {
|
if (node["output"].isString()) {
|
||||||
output = node["output"].asString();
|
output = node["output"].asString();
|
||||||
}
|
}
|
||||||
|
// found node
|
||||||
if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) {
|
if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) {
|
||||||
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
|
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
|
||||||
config_["all-outputs"].asBool()) {
|
config_["all-outputs"].asBool()) {
|
||||||
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
||||||
: node["window_properties"]["instance"].asString();
|
: node["window_properties"]["instance"].asString();
|
||||||
return {nodes.size(),
|
int nb = node.size();
|
||||||
|
if(parentWorkspace != 0)
|
||||||
|
nb = leafNodesInWorkspace(parentWorkspace);
|
||||||
|
return {nb,
|
||||||
node["id"].asInt(),
|
node["id"].asInt(),
|
||||||
Glib::Markup::escape_text(node["name"].asString()),
|
Glib::Markup::escape_text(node["name"].asString()),
|
||||||
app_id};
|
app_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto [nb, id, name, app_id] = getFocusedNode(node["nodes"], output);
|
// iterate
|
||||||
|
if(node["type"] == "workspace")
|
||||||
|
parentWorkspace = node;
|
||||||
|
auto [nb, id, name, app_id] = gfnWithWorkspace(node["nodes"], output, config_, bar_, parentWorkspace);
|
||||||
if (id > -1 && !name.empty()) {
|
if (id > -1 && !name.empty()) {
|
||||||
return {nb, id, name, app_id};
|
return {nb, id, name, app_id};
|
||||||
}
|
}
|
||||||
// Search for floating node
|
// Search for floating node
|
||||||
std::tie(nb, id, name, app_id) = getFocusedNode(node["floating_nodes"], output);
|
std::tie(nb, id, name, app_id) = gfnWithWorkspace(node["floating_nodes"], output, config_, bar_, parentWorkspace);
|
||||||
if (id > -1 && !name.empty()) {
|
if (id > -1 && !name.empty()) {
|
||||||
return {nb, id, name, app_id};
|
return {nb, id, name, app_id};
|
||||||
}
|
}
|
||||||
|
@ -94,6 +116,11 @@ std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
||||||
return {0, -1, "", ""};
|
return {0, -1, "", ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
||||||
|
const Json::Value& nodes, std::string& output) {
|
||||||
|
return gfnWithWorkspace(nodes, output, config_, bar_, placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::getTree() {
|
void Window::getTree() {
|
||||||
try {
|
try {
|
||||||
ipc_.sendCmd(IPC_GET_TREE);
|
ipc_.sendCmd(IPC_GET_TREE);
|
||||||
|
|
Loading…
Reference in New Issue