Skip to content

Commit

Permalink
Issue 1399: fix potential problem with filterWorkspace String conversion
Browse files Browse the repository at this point in the history
This also adds some additional trace information which exception was
triggered.
  • Loading branch information
RobertMueller2 committed Mar 25, 2022
1 parent 664f9e1 commit d999b5f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/modules/sway/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
ipc_.handleEvent();
} catch (const std::exception& e) {
spdlog::error("Window: {}", e.what());
spdlog::trace("Window::Window exception");
}
});
}
Expand All @@ -42,6 +43,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
dp.emit();
} catch (const std::exception& e) {
spdlog::error("Window: {}", e.what());
spdlog::trace("Window::onCmd exception");
}
}

Expand Down Expand Up @@ -161,9 +163,9 @@ std::pair<int, int> leafNodesInWorkspace(const Json::Value& node) {
auto const& nodes = node["nodes"];
auto const& floating_nodes = node["floating_nodes"];
if(nodes.empty() && floating_nodes.empty()) {
if(node["type"] == "workspace")
if(node["type"].asString() == "workspace")
return {0,0};
else if (node["type"] == "floating_con") {
else if (node["type"].asString() == "floating_con") {
return {0,1};
} else {
return {1,0};
Expand All @@ -189,21 +191,24 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
const Bar& bar_, Json::Value& parentWorkspace, Json::Value& filterWorkspace, const Json::Value& immediateParent) {
bool found_visible = false;
for(auto const& node : nodes) {
if (node["type"] == "output") {
if (node["type"].asString() == "output") {
if (!config_["all-outputs"].asBool() && node["name"].asString() != bar_.output->name) {
continue;
}
filterWorkspace = node["current_workspace"];
output = node["name"].asString();
}
else if(node["type"] == "workspace") {
else if(node["type"].asString() == "workspace") {
if (!filterWorkspace.isString()) {
continue;
}
// needs to be a string comparison, because filterWorkspace is the current_workspace
if (node["name"].asString() != filterWorkspace.asString()) {
continue;
}
parentWorkspace = node;
}
else if (node["type"] == "con" || node["type"] == "floating_con") {
else if (node["type"].asString() == "con" || node["type"].asString() == "floating_con") {
// found node
if (node["focused"].asBool()) {
spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name, output, node["name"].asString());
Expand All @@ -216,16 +221,15 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
nb = all_leaf_nodes.first;
floating_count = all_leaf_nodes.second;
if (parentWorkspace["layout"].isString()) {
workspace_layout = parentWorkspace["layout"].asString();
}
workspace_layout = parentWorkspace["layout"].asString();
}
return {nb,
floating_count,
node["id"].asInt(),
Glib::Markup::escape_text(node["name"].asString()),
app_id,
workspace_layout};

}
//record visible nodes, but since we don't know if a focused node is yet found, we can't return anything yet
else if (!config_["all-outputs"].asBool() && node["visible"].asBool()) {
Expand All @@ -245,6 +249,7 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
return {nb2, f2, id2, name2, app_id2,workspace_layout2};
}
}

// This is needed so the recursion isn't finished early before finding a focused node when using offscreen-text
if (found_visible && immediateParent["type"].asString() == "workspace") {
int tiled_count = 0;
Expand All @@ -254,13 +259,12 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
tiled_count = all_leaf_nodes.first;
floating_count = all_leaf_nodes.second;
if (parentWorkspace["layout"].isString()) {
workspace_layout = parentWorkspace["layout"].asString();
}
workspace_layout = parentWorkspace["layout"].asString();
}
//using an empty string as default ensures that no window depending styles are set due to the checks above for !name.empty()
return {tiled_count, floating_count, 0, config_["offscreen-text"].isString() ? config_["offscreen-text"].asString() : "", "", workspace_layout};
return {tiled_count, floating_count, 0, config_["offscreen-text"].asString(), "", workspace_layout};
}

return {0, 0, -1, "", "", ""};
}

Expand All @@ -275,6 +279,7 @@ void Window::getTree() {
ipc_.sendCmd(IPC_GET_TREE);
} catch (const std::exception& e) {
spdlog::error("Window: {}", e.what());
spdlog::trace("Window::getTree exception");
}
}

Expand Down

0 comments on commit d999b5f

Please sign in to comment.