mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-25 15:12:29 +02:00 
			
		
		
		
	fix: add proper mutex
This commit is contained in:
		| @@ -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 { | ||||
|       auto payload = parser_.parse(res.payload); | ||||
|       if (payload.isArray()) { | ||||
|       { | ||||
|         std::lock_guard<std::mutex> lock(mutex_); | ||||
|         auto                        payload = parser_.parse(res.payload); | ||||
|         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,7 +127,8 @@ bool Workspaces::filterButtons() { | ||||
| } | ||||
|  | ||||
| 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) { | ||||
|     auto bit = buttons_.find((*it)["name"].asString()); | ||||
|     if (bit == buttons_.end()) { | ||||
| @@ -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(); | ||||
|   }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Alex
					Alex