diff --git a/include/modules/hyprland/submap.hpp b/include/modules/hyprland/submap.hpp index 0dcb5d5ae..97a20c7cc 100644 --- a/include/modules/hyprland/submap.hpp +++ b/include/modules/hyprland/submap.hpp @@ -26,9 +26,11 @@ class Submap : public waybar::ALabel, public EventHandler { const Bar& bar_; util::JsonParser parser_; std::string submap_; + std::string icon_; std::string prev_submap_; bool always_on_ = false; std::string default_submap_ = "Default"; + std::unordered_map icons_; IPC& m_ipc; }; diff --git a/man/waybar-hyprland-submap.5.scd b/man/waybar-hyprland-submap.5.scd index f6cdff94b..0e540a937 100644 --- a/man/waybar-hyprland-submap.5.scd +++ b/man/waybar-hyprland-submap.5.scd @@ -15,7 +15,7 @@ Addressed by *hyprland/submap* *format*: ++ typeof: string ++ default: {} ++ - The format, how information should be displayed. On {} the currently active submap is displayed. + The format, how information should be displayed. This format supports two placeholders: *{submap}* for the currently active submap name and *{icon}* for the icon associated with the submap. *rotate*: ++ typeof: integer ++ @@ -80,6 +80,10 @@ Addressed by *hyprland/submap* default: Default ++ Option to set the submap name to display when not in an active submap. +*icons*: ++ + typeof: object ++ + Based on the submap name, the corresponding icon will be selected from this map and made available as the *{icon}* placeholder in the format string. The keys are submap names, and the values are the icons or strings to display for those submaps. + *menu*: ++ typeof: string ++ Action that popups the menu. @@ -103,9 +107,13 @@ Addressed by *hyprland/submap* ``` "hyprland/submap": { - "format": "✌️ {}", + "format": "{icon} {submap}", "max-length": 8, - "tooltip": false + "tooltip": false, + "icons": { + "resize": "", + "pause": "", + } } ``` diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index 5d587d02f..7cc0a3c41 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -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() { @@ -58,7 +70,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_); } @@ -79,6 +92,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_; }