feat(workspace): catch ipc errors
This commit is contained in:
parent
424ebb3c9b
commit
14053d61fc
|
@ -6,7 +6,7 @@ project(
|
||||||
)
|
)
|
||||||
|
|
||||||
cpp_args = []
|
cpp_args = []
|
||||||
cpp_link_args = ['-g']
|
cpp_link_args = []
|
||||||
|
|
||||||
if false # libc++
|
if false # libc++
|
||||||
cpp_args += ['-stdlib=libc++']
|
cpp_args += ['-stdlib=libc++']
|
||||||
|
|
|
@ -95,7 +95,6 @@ std::string ipc_single_command(int socketfd, uint32_t type, const char *payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ipc_response resp = ipc_recv_response(socketfd);
|
struct ipc_response resp = ipc_recv_response(socketfd);
|
||||||
std::string response = resp.payload;
|
|
||||||
*len = resp.size;
|
*len = resp.size;
|
||||||
return response;
|
return resp.payload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,17 @@ waybar::modules::Workspaces::Workspaces(Bar &bar)
|
||||||
: _bar(bar)
|
: _bar(bar)
|
||||||
{
|
{
|
||||||
_box.get_style_context()->add_class("workspaces");
|
_box.get_style_context()->add_class("workspaces");
|
||||||
|
try {
|
||||||
std::string socketPath = get_socketpath();
|
std::string socketPath = get_socketpath();
|
||||||
_ipcSocketfd = ipc_open_socket(socketPath);
|
_ipcSocketfd = ipc_open_socket(socketPath);
|
||||||
_ipcEventSocketfd = ipc_open_socket(socketPath);
|
_ipcEventSocketfd = ipc_open_socket(socketPath);
|
||||||
const char *subscribe = "[ \"workspace\", \"mode\" ]";
|
const char *subscribe = "[ \"workspace\", \"mode\" ]";
|
||||||
uint32_t len = strlen(subscribe);
|
uint32_t len = strlen(subscribe);
|
||||||
ipc_single_command(_ipcEventSocketfd, IPC_SUBSCRIBE, subscribe, &len);
|
ipc_single_command(_ipcEventSocketfd, IPC_SUBSCRIBE, subscribe, &len);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
Glib::signal_idle().connect_once([this] {
|
Glib::signal_idle().connect_once([this] {
|
||||||
update();
|
update();
|
||||||
|
@ -60,9 +65,13 @@ void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
|
||||||
_box.pack_start(button, false, false, 0);
|
_box.pack_start(button, false, false, 0);
|
||||||
button.set_relief(Gtk::RELIEF_NONE);
|
button.set_relief(Gtk::RELIEF_NONE);
|
||||||
button.signal_clicked().connect([this, pair] {
|
button.signal_clicked().connect([this, pair] {
|
||||||
|
try {
|
||||||
auto value = fmt::format("workspace \"{}\"", pair.first->first);
|
auto value = fmt::format("workspace \"{}\"", pair.first->first);
|
||||||
uint32_t size = value.size();
|
uint32_t size = value.size();
|
||||||
ipc_single_command(_ipcSocketfd, IPC_COMMAND, value.c_str(), &size);
|
ipc_single_command(_ipcSocketfd, IPC_COMMAND, value.c_str(), &size);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
_box.reorder_child(button, node["num"].asInt() - 1);
|
_box.reorder_child(button, node["num"].asInt() - 1);
|
||||||
if (node["focused"].asBool()) {
|
if (node["focused"].asBool()) {
|
||||||
|
@ -77,15 +86,20 @@ Json::Value waybar::modules::Workspaces::_getWorkspaces()
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::CharReaderBuilder builder;
|
Json::CharReaderBuilder builder;
|
||||||
Json::CharReader* reader = builder.newCharReader();
|
Json::CharReader* reader = builder.newCharReader();
|
||||||
std::string err;
|
try {
|
||||||
std::string str = ipc_single_command(_ipcSocketfd, IPC_GET_WORKSPACES,
|
std::string str = ipc_single_command(_ipcSocketfd, IPC_GET_WORKSPACES,
|
||||||
nullptr, &len);
|
nullptr, &len);
|
||||||
bool res = reader->parse(str.c_str(), str.c_str() + str.size(), &root, &err);
|
std::string err;
|
||||||
|
bool res =
|
||||||
|
reader->parse(str.c_str(), str.c_str() + str.size(), &root, &err);
|
||||||
delete reader;
|
delete reader;
|
||||||
if (!res) {
|
if (!res) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue