Waybar/src/modules/sway/mode.cpp

43 lines
995 B
C++
Raw Normal View History

2018-10-30 12:39:30 +00:00
#include "modules/sway/mode.hpp"
2018-11-30 23:10:41 +00:00
waybar::modules::sway::Mode::Mode(const Bar& bar, const Json::Value& config)
2018-10-30 12:39:30 +00:00
: ALabel(config, "{}"), bar_(bar)
{
ipc_.connect();
ipc_.subscribe("[ \"mode\" ]");
// Launch worker
worker();
}
void waybar::modules::sway::Mode::worker()
{
thread_ = [this] {
try {
auto res = ipc_.handleEvent();
auto parsed = parser_.parse(res.payload);
if ((parsed["change"]) != "default" ) {
mode_ = parsed["change"].asString();
dp.emit();
}
else if ((parsed["change"]) == "default" ) {
mode_.clear();
dp.emit();
}
} catch (const std::exception& e) {
std::cerr << "Mode: " << e.what() << std::endl;
2018-10-30 12:39:30 +00:00
}
};
}
auto waybar::modules::sway::Mode::update() -> void
{
if (mode_.empty()) {
label_.set_name("");
label_.hide();
} else {
label_.set_name("mode");
2018-11-21 19:49:09 +00:00
label_.set_markup(fmt::format(format_, mode_));
2018-10-30 12:39:30 +00:00
label_.set_tooltip_text(mode_);
label_.show();
}
}