Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/modules/hyprland/submap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> icons_;

IPC& m_ipc;
};
Expand Down
14 changes: 11 additions & 3 deletions man/waybar-hyprland-submap.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++
Expand Down Expand Up @@ -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.
Expand All @@ -103,9 +107,13 @@ Addressed by *hyprland/submap*

```
"hyprland/submap": {
"format": "✌️ {}",
"format": "{icon} {submap}",
"max-length": 8,
"tooltip": false
"tooltip": false,
"icons": {
"resize": "",
"pause": "",
}
}
```

Expand Down
21 changes: 20 additions & 1 deletion src/modules/hyprland/submap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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_);
}
Expand All @@ -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_;
}
Expand Down