mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: try/catch, sigc trackable
This commit is contained in:
parent
0c3c548bc0
commit
362c393b1d
@ -63,8 +63,8 @@ class Item : public sigc::trackable {
|
|||||||
bool makeMenu(GdkEventButton* const& ev);
|
bool makeMenu(GdkEventButton* const& ev);
|
||||||
bool handleClick(GdkEventButton* const& /*ev*/);
|
bool handleClick(GdkEventButton* const& /*ev*/);
|
||||||
|
|
||||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
|
||||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||||
|
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||||
bool update_pending_;
|
bool update_pending_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
class Mode : public ALabel {
|
class Mode : public ALabel, public sigc::trackable {
|
||||||
public:
|
public:
|
||||||
Mode(const std::string&, const Json::Value&);
|
Mode(const std::string&, const Json::Value&);
|
||||||
~Mode() = default;
|
~Mode() = default;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
class Window : public ALabel {
|
class Window : public ALabel, public sigc::trackable {
|
||||||
public:
|
public:
|
||||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||||
~Window() = default;
|
~Window() = default;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
class Workspaces : public IModule {
|
class Workspaces : public IModule, public sigc::trackable {
|
||||||
public:
|
public:
|
||||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||||
~Workspaces() = default;
|
~Workspaces() = default;
|
||||||
|
@ -5,15 +5,16 @@
|
|||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
|
|
||||||
struct JsonParser {
|
struct JsonParser {
|
||||||
JsonParser() : reader_(builder_.newCharReader()) {}
|
JsonParser() {}
|
||||||
|
|
||||||
const Json::Value parse(const std::string& data) const {
|
const Json::Value parse(const std::string& data) const {
|
||||||
Json::Value root(Json::objectValue);
|
Json::Value root(Json::objectValue);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
std::string err;
|
std::unique_ptr<Json::CharReader> const reader(builder_.newCharReader());
|
||||||
bool res = reader_->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
std::string err;
|
||||||
|
bool res = reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||||
if (!res) throw std::runtime_error(err);
|
if (!res) throw std::runtime_error(err);
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
@ -21,8 +22,7 @@ struct JsonParser {
|
|||||||
~JsonParser() = default;
|
~JsonParser() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Json::CharReaderBuilder builder_;
|
Json::CharReaderBuilder builder_;
|
||||||
std::unique_ptr<Json::CharReader> const reader_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::util
|
} // namespace waybar::util
|
||||||
|
@ -14,11 +14,6 @@ Watcher::Watcher()
|
|||||||
watcher_(sn_watcher_skeleton_new()) {}
|
watcher_(sn_watcher_skeleton_new()) {}
|
||||||
|
|
||||||
Watcher::~Watcher() {
|
Watcher::~Watcher() {
|
||||||
if (bus_name_id_ != 0) {
|
|
||||||
Gio::DBus::unown_name(bus_name_id_);
|
|
||||||
bus_name_id_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hosts_ != nullptr) {
|
if (hosts_ != nullptr) {
|
||||||
g_slist_free_full(hosts_, gfWatchFree);
|
g_slist_free_full(hosts_, gfWatchFree);
|
||||||
hosts_ = nullptr;
|
hosts_ = nullptr;
|
||||||
|
@ -19,7 +19,13 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
|||||||
worker();
|
worker();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Workspaces::onEvent(const struct Ipc::ipc_response &res) { ipc_.sendCmd(IPC_GET_WORKSPACES); }
|
void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
|
||||||
|
try {
|
||||||
|
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -194,7 +200,11 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
try {
|
||||||
|
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user