Skip to content

Commit 85f177a

Browse files
committed
Adding sway/workspaces:persistant_workspaces in config file
c.f. Alexays#210
1 parent 6ffc7ee commit 85f177a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/modules/sway/workspaces.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
4747
? workspace["output"].asString() == bar_.output->name
4848
: true;
4949
});
50+
51+
// adding persistant workspaces (as per the config file)
52+
const Json::Value& p_workspaces = config_["persistant_workspaces"];
53+
const std::vector<std::string> p_workspaces_names = p_workspaces.getMemberNames();
54+
for (const std::string& p_w_name : p_workspaces_names) {
55+
const Json::Value& p_w = p_workspaces[p_w_name];
56+
auto it = std::find_if(payload.begin(), payload.end(), [&p_w_name](const Json::Value& node) {
57+
return node["name"].asString() == p_w_name;
58+
});
59+
if (it != payload.end()) {
60+
continue; // already displayed by some bar
61+
}
62+
63+
if (p_w.isArray() && !p_w.empty()) {
64+
for (const Json::Value& output : p_w) {
65+
if (output.asString() == bar_.output->name) {
66+
Json::Value v;
67+
v["name"] = p_w_name;
68+
workspaces_.emplace_back(std::move(v));
69+
break;
70+
}
71+
}
72+
} else {
73+
Json::Value v;
74+
v["name"] = p_w_name;
75+
workspaces_.emplace_back(std::move(v));
76+
}
77+
}
78+
std::sort(workspaces_.begin(), workspaces_.end(), [](const Json::Value& lhs, const Json::Value& rhs) {
79+
return lhs["name"].asString() < rhs["name"].asString();
80+
});
81+
5082
dp.emit();
5183
}
5284
} catch (const std::exception &e) {

0 commit comments

Comments
 (0)