mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 22:52:30 +02:00
Add always on option for hyprland/submap
This commit is contained in:
@ -10,6 +10,8 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar) {
|
||||
modulesReady = true;
|
||||
|
||||
parseConfig(config);
|
||||
|
||||
if (!gIPC.get()) {
|
||||
gIPC = std::make_unique<IPC>();
|
||||
}
|
||||
@ -17,6 +19,13 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
label_.hide();
|
||||
ALabel::update();
|
||||
|
||||
// Displays widget immediately if always_on_ assuming default submap
|
||||
// Needs an actual way to retrive current submap on startup
|
||||
if (always_on_) {
|
||||
submap_ = default_submap_;
|
||||
label_.get_style_context()->add_class(submap_);
|
||||
}
|
||||
|
||||
// register for hyprland ipc
|
||||
gIPC->registerForIPC("submap", this);
|
||||
dp.emit();
|
||||
@ -28,6 +37,18 @@ Submap::~Submap() {
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
}
|
||||
|
||||
auto Submap::parseConfig(const Json::Value& config) -> void {
|
||||
auto const alwaysOn = config["always-on"];
|
||||
if (alwaysOn.isBool()) {
|
||||
always_on_ = alwaysOn.asBool();
|
||||
}
|
||||
|
||||
auto const defaultSubmap = config["default-submap"];
|
||||
if (defaultSubmap.isString()) {
|
||||
default_submap_ = defaultSubmap.asString();
|
||||
}
|
||||
}
|
||||
|
||||
auto Submap::update() -> void {
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
|
||||
@ -54,16 +75,18 @@ void Submap::onEvent(const std::string& ev) {
|
||||
auto submapName = ev.substr(ev.find_last_of('>') + 1);
|
||||
submapName = waybar::util::sanitize_string(submapName);
|
||||
|
||||
if (!submap_.empty()){
|
||||
if (!submap_.empty()) {
|
||||
label_.get_style_context()->remove_class(submap_);
|
||||
}
|
||||
|
||||
submap_ = submapName;
|
||||
|
||||
if (submap_.empty() && always_on_) {
|
||||
submap_ = default_submap_;
|
||||
}
|
||||
|
||||
label_.get_style_context()->add_class(submap_);
|
||||
|
||||
|
||||
|
||||
spdlog::debug("hyprland submap onevent with {}", submap_);
|
||||
|
||||
dp.emit();
|
||||
|
Reference in New Issue
Block a user