refactor(Workspaces, IPC): no more mutex in the workspaces modules, moved to the IPC client for a proper handling

This commit is contained in:
Alex
2019-04-19 16:48:02 +02:00
parent e77c155ede
commit cbb6f2a307
4 changed files with 131 additions and 174 deletions

View File

@ -6,6 +6,7 @@
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <mutex>
#include "ipc.hpp"
namespace waybar::modules::sway {
@ -24,9 +25,9 @@ class Ipc {
sigc::signal<void, const struct ipc_response> signal_event;
sigc::signal<void, const struct ipc_response> signal_cmd;
void sendCmd(uint32_t type, const std::string &payload = "") const;
void subscribe(const std::string &payload) const;
void handleEvent() const;
void sendCmd(uint32_t type, const std::string &payload = "");
void subscribe(const std::string &payload);
void handleEvent();
protected:
static inline const std::string ipc_magic_ = "i3-ipc";
@ -34,11 +35,13 @@ class Ipc {
const std::string getSocketPath() const;
int open(const std::string &) const;
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "") const;
struct ipc_response recv(int fd) const;
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "");
struct ipc_response recv(int fd);
int fd_;
int fd_event_;
int fd_;
int fd_event_;
std::mutex mutex_;
std::mutex mutex_event_;
};
} // namespace waybar::modules::sway

View File

@ -21,25 +21,24 @@ class Workspaces : public IModule {
private:
void onCmd(const struct Ipc::ipc_response);
void onEvent(const struct Ipc::ipc_response);
void worker();
void addWorkspace(const Json::Value&);
bool filterButtons();
Gtk::Button& addButton(const Json::Value&);
void onButtonReady(const Json::Value&, Gtk::Button&);
std::string getIcon(const std::string&, const Json::Value&);
bool handleScroll(GdkEventScroll*);
const std::string getCycleWorkspace(const Json::Value& workspaces, uint8_t current,
bool prev) const;
uint16_t getWorkspaceIndex(const Json::Value& workspaces, const std::string& name) const;
const std::string getCycleWorkspace(std::vector<Json::Value>::iterator, bool prev) const;
uint16_t getWorkspaceIndex(const std::string& name) const;
std::string trimWorkspaceName(std::string);
const Json::Value getWorkspaces();
const Bar& bar_;
const Json::Value& config_;
Json::Value workspaces_;
std::vector<Json::Value> workspaces_;
waybar::util::SleeperThread thread_;
Gtk::Box box_;
util::JsonParser parser_;
Ipc ipc_;
std::mutex mutex_;
bool scrolling_;
std::unordered_map<std::string, Gtk::Button> buttons_;
};