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) {
|
2018-12-09 09:49:28 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|