Skip to content

Commit d999b5f

Browse files
Issue 1399: fix potential problem with filterWorkspace String conversion
This also adds some additional trace information which exception was triggered.
1 parent 664f9e1 commit d999b5f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/modules/sway/window.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
2626
ipc_.handleEvent();
2727
} catch (const std::exception& e) {
2828
spdlog::error("Window: {}", e.what());
29+
spdlog::trace("Window::Window exception");
2930
}
3031
});
3132
}
@@ -42,6 +43,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
4243
dp.emit();
4344
} catch (const std::exception& e) {
4445
spdlog::error("Window: {}", e.what());
46+
spdlog::trace("Window::onCmd exception");
4547
}
4648
}
4749

@@ -161,9 +163,9 @@ std::pair<int, int> leafNodesInWorkspace(const Json::Value& node) {
161163
auto const& nodes = node["nodes"];
162164
auto const& floating_nodes = node["floating_nodes"];
163165
if(nodes.empty() && floating_nodes.empty()) {
164-
if(node["type"] == "workspace")
166+
if(node["type"].asString() == "workspace")
165167
return {0,0};
166-
else if (node["type"] == "floating_con") {
168+
else if (node["type"].asString() == "floating_con") {
167169
return {0,1};
168170
} else {
169171
return {1,0};
@@ -189,21 +191,24 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
189191
const Bar& bar_, Json::Value& parentWorkspace, Json::Value& filterWorkspace, const Json::Value& immediateParent) {
190192
bool found_visible = false;
191193
for(auto const& node : nodes) {
192-
if (node["type"] == "output") {
194+
if (node["type"].asString() == "output") {
193195
if (!config_["all-outputs"].asBool() && node["name"].asString() != bar_.output->name) {
194196
continue;
195197
}
196198
filterWorkspace = node["current_workspace"];
197199
output = node["name"].asString();
198200
}
199-
else if(node["type"] == "workspace") {
201+
else if(node["type"].asString() == "workspace") {
202+
if (!filterWorkspace.isString()) {
203+
continue;
204+
}
200205
// needs to be a string comparison, because filterWorkspace is the current_workspace
201206
if (node["name"].asString() != filterWorkspace.asString()) {
202207
continue;
203208
}
204209
parentWorkspace = node;
205210
}
206-
else if (node["type"] == "con" || node["type"] == "floating_con") {
211+
else if (node["type"].asString() == "con" || node["type"].asString() == "floating_con") {
207212
// found node
208213
if (node["focused"].asBool()) {
209214
spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name, output, node["name"].asString());
@@ -216,16 +221,15 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
216221
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
217222
nb = all_leaf_nodes.first;
218223
floating_count = all_leaf_nodes.second;
219-
if (parentWorkspace["layout"].isString()) {
220-
workspace_layout = parentWorkspace["layout"].asString();
221-
}
224+
workspace_layout = parentWorkspace["layout"].asString();
222225
}
223226
return {nb,
224227
floating_count,
225228
node["id"].asInt(),
226229
Glib::Markup::escape_text(node["name"].asString()),
227230
app_id,
228231
workspace_layout};
232+
229233
}
230234
//record visible nodes, but since we don't know if a focused node is yet found, we can't return anything yet
231235
else if (!config_["all-outputs"].asBool() && node["visible"].asBool()) {
@@ -245,6 +249,7 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
245249
return {nb2, f2, id2, name2, app_id2,workspace_layout2};
246250
}
247251
}
252+
248253
// This is needed so the recursion isn't finished early before finding a focused node when using offscreen-text
249254
if (found_visible && immediateParent["type"].asString() == "workspace") {
250255
int tiled_count = 0;
@@ -254,13 +259,12 @@ std::tuple<std::size_t, int, int, std::string, std::string, std::string> gfnWith
254259
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
255260
tiled_count = all_leaf_nodes.first;
256261
floating_count = all_leaf_nodes.second;
257-
if (parentWorkspace["layout"].isString()) {
258-
workspace_layout = parentWorkspace["layout"].asString();
259-
}
262+
workspace_layout = parentWorkspace["layout"].asString();
260263
}
261264
//using an empty string as default ensures that no window depending styles are set due to the checks above for !name.empty()
262-
return {tiled_count, floating_count, 0, config_["offscreen-text"].isString() ? config_["offscreen-text"].asString() : "", "", workspace_layout};
265+
return {tiled_count, floating_count, 0, config_["offscreen-text"].asString(), "", workspace_layout};
263266
}
267+
264268
return {0, 0, -1, "", "", ""};
265269
}
266270

@@ -275,6 +279,7 @@ void Window::getTree() {
275279
ipc_.sendCmd(IPC_GET_TREE);
276280
} catch (const std::exception& e) {
277281
spdlog::error("Window: {}", e.what());
282+
spdlog::trace("Window::getTree exception");
278283
}
279284
}
280285

0 commit comments

Comments
 (0)