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