feat(hyprland/submap): add config option to specify different icons for submaps
This commit is contained in:
@@ -26,8 +26,10 @@ class Submap : public waybar::ALabel, public EventHandler {
|
||||
const Bar& bar_;
|
||||
util::JsonParser parser_;
|
||||
std::string submap_;
|
||||
std::string icon_;
|
||||
bool always_on_ = false;
|
||||
std::string default_submap_ = "Default";
|
||||
std::unordered_map<std::string, std::string> icons_;
|
||||
|
||||
IPC& m_ipc;
|
||||
};
|
||||
|
||||
@@ -21,6 +21,18 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
// register for hyprland ipc
|
||||
m_ipc.registerForIPC("submap", this);
|
||||
dp.emit();
|
||||
|
||||
if (config["icons"].isObject()) {
|
||||
const Json::Value& icons = config["icons"];
|
||||
|
||||
for (const std::string& key : icons.getMemberNames()) {
|
||||
const Json::Value& value = icons[key];
|
||||
|
||||
if (value.isString()) {
|
||||
icons_[key] = value.asString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Submap::~Submap() {
|
||||
@@ -47,7 +59,8 @@ auto Submap::update() -> void {
|
||||
if (submap_.empty()) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
label_.set_markup(fmt::format(fmt::runtime(format_), submap_));
|
||||
label_.set_markup(
|
||||
fmt::format(fmt::runtime(format_), fmt::arg("submap", submap_), fmt::arg("icon", icon_)));
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(submap_);
|
||||
}
|
||||
@@ -72,6 +85,12 @@ void Submap::onEvent(const std::string& ev) {
|
||||
|
||||
submap_ = submapName;
|
||||
|
||||
if (!icons_[submap_].empty()) {
|
||||
icon_ = icons_[submap_];
|
||||
} else {
|
||||
icon_ = "";
|
||||
}
|
||||
|
||||
if (submap_.empty() && always_on_) {
|
||||
submap_ = default_submap_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user