fix: add proper mutex
This commit is contained in:
parent
71a9a75aad
commit
ff9d598c16
|
@ -22,6 +22,7 @@ class Mode : public ALabel, public sigc::trackable {
|
|||
|
||||
std::string mode_;
|
||||
util::JsonParser parser_;
|
||||
std::mutex mutex_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
Ipc ipc_;
|
||||
|
|
|
@ -32,6 +32,7 @@ class Window : public ALabel, public sigc::trackable {
|
|||
std::string old_app_id_;
|
||||
std::size_t app_nb_;
|
||||
util::JsonParser parser_;
|
||||
std::mutex mutex_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
Ipc ipc_;
|
||||
|
|
|
@ -37,6 +37,7 @@ class Workspaces : public AModule, public sigc::trackable {
|
|||
Gtk::Box box_;
|
||||
util::JsonParser parser_;
|
||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||
std::mutex mutex_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
Ipc ipc_;
|
||||
|
|
|
@ -13,6 +13,7 @@ Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "m
|
|||
|
||||
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto payload = parser_.parse(res.payload);
|
||||
if (payload["change"] != "default") {
|
||||
mode_ = Glib::Markup::escape_text(payload["change"].asString());
|
||||
|
|
|
@ -21,6 +21,7 @@ void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
|||
|
||||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto payload = parser_.parse(res.payload);
|
||||
auto output = payload["ouput"].isString() ? payload["output"].asString() : "";
|
||||
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output);
|
||||
|
|
|
@ -36,8 +36,9 @@ void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
|
|||
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
if (res.type == IPC_GET_WORKSPACES) {
|
||||
try {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto payload = parser_.parse(res.payload);
|
||||
if (payload.isArray()) {
|
||||
workspaces_.clear();
|
||||
std::copy_if(payload.begin(),
|
||||
payload.end(),
|
||||
|
@ -90,9 +91,8 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
|||
return lhs["name"].asString() < rhs["name"].asString();
|
||||
});
|
||||
}
|
||||
|
||||
dp.emit();
|
||||
}
|
||||
dp.emit();
|
||||
} catch (const std::exception &e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
|
@ -127,6 +127,7 @@ bool Workspaces::filterButtons() {
|
|||
}
|
||||
|
||||
auto Workspaces::update() -> void {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
bool needReorder = filterButtons();
|
||||
for (auto it = workspaces_.begin(); it != workspaces_.end(); ++it) {
|
||||
auto bit = buttons_.find((*it)["name"].asString());
|
||||
|
@ -217,6 +218,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||
if (dir == SCROLL_DIR::NONE) {
|
||||
return true;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) {
|
||||
return workspace["focused"].asBool();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue