mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Add module to show sway binding mode
This commit is contained in:
@ -12,6 +12,9 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
||||
return new waybar::modules::Battery(config_[name]);
|
||||
}
|
||||
#ifdef HAVE_SWAY
|
||||
if (ref == "sway/mode") {
|
||||
return new waybar::modules::sway::Mode(bar_, config_[name]);
|
||||
}
|
||||
if (ref == "sway/workspaces") {
|
||||
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
|
||||
}
|
||||
|
43
src/modules/sway/mode.cpp
Normal file
43
src/modules/sway/mode.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "modules/sway/mode.hpp"
|
||||
|
||||
waybar::modules::sway::Mode::Mode(Bar& bar, const Json::Value& config)
|
||||
: 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 << e.what() << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
auto waybar::modules::sway::Mode::update() -> void
|
||||
{
|
||||
if (mode_.empty()) {
|
||||
label_.set_name("");
|
||||
label_.hide();
|
||||
} else {
|
||||
label_.set_name("mode");
|
||||
label_.set_text(fmt::format(format_, mode_));
|
||||
label_.set_tooltip_text(mode_);
|
||||
label_.show();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user