From dbf8e3514f924499bb1767cdeaddad6efe0c4f25 Mon Sep 17 00:00:00 2001 From: cebem1nt Date: Sun, 16 Aug 2026 22:07:53 -0300 Subject: [PATCH 1/3] feat: add num-tags for mango/workspaces --- src/modules/mango/workspaces.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/modules/mango/workspaces.cpp b/src/modules/mango/workspaces.cpp index 2c2b790c40..8c6e62e3ef 100644 --- a/src/modules/mango/workspaces.cpp +++ b/src/modules/mango/workspaces.cpp @@ -55,6 +55,7 @@ void Workspaces::doUpdate() { const auto& tags = monitor["tags"]; bool overview_mode = false; + if (monitor.isMember("active_tags") && monitor["active_tags"].isArray()) { const auto& active_tags = monitor["active_tags"]; if (active_tags.size() == 1 && active_tags[0].asInt() == 0) { @@ -90,9 +91,9 @@ void Workspaces::doUpdate() { for (auto btn_it = buttons_.begin(); btn_it != buttons_.end();) { uint64_t id = btn_it->first; - bool found = std::any_of(tags.begin(), tags.end(), [id](const Json::Value& tag) { - return tag["index"].asUInt64() == id; - }); + + bool found = std::ranges::any_of( + tags, [id](const Json::Value& tag) { return tag["index"].asUInt64() == id; }); if (!found) { box_.remove(btn_it->second); @@ -102,21 +103,18 @@ void Workspaces::doUpdate() { } } + uint64_t num_tags = + config_["num-tags"].isUInt64() ? config_["num-tags"].asUInt64() : tags.size(); + for (const auto& tag : tags) { uint64_t idx = tag["index"].asUInt64(); + + if (idx > num_tags) break; + auto btn_it = buttons_.find(idx); Gtk::Button& button = (btn_it == buttons_.end()) ? addButton(idx) : btn_it->second; updateButtonState(button, tag, monitor); } - - std::vector indices; - for (const auto& tag : tags) indices.push_back(tag["index"].asUInt64()); - std::sort(indices.begin(), indices.end()); - int pos = 0; - for (uint64_t idx : indices) { - box_.reorder_child(buttons_[idx], pos + 1); - pos++; - } } } From e83c178e466d2cb214b4cfa897271088fa86f383 Mon Sep 17 00:00:00 2001 From: cebem1nt Date: Sun, 16 Aug 2026 22:23:03 -0300 Subject: [PATCH 2/3] mango/workspaces: add num-tags to manpages --- man/waybar-mango-workspaces.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-mango-workspaces.5.scd b/man/waybar-mango-workspaces.5.scd index 985398e7f4..a847b248f5 100644 --- a/man/waybar-mango-workspaces.5.scd +++ b/man/waybar-mango-workspaces.5.scd @@ -53,6 +53,10 @@ Addressed by *mango/workspaces* default: "OVERVIEW" ++ Label shown on the overview button when the overview is active. +*num-tags*: ++ + typeof: uint ++ + The number of tags that should be displayed. + *expand*: ++ typeof: bool ++ default: false ++ From f017762dc7c683ce0d36c6786203f88e2285d9ad Mon Sep 17 00:00:00 2001 From: cebem1nt Date: Mon, 17 Aug 2026 13:58:11 -0300 Subject: [PATCH 3/3] mango/workspaces: bring tags sorting back just in case --- src/modules/mango/workspaces.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/modules/mango/workspaces.cpp b/src/modules/mango/workspaces.cpp index 8c6e62e3ef..e8f75d88ac 100644 --- a/src/modules/mango/workspaces.cpp +++ b/src/modules/mango/workspaces.cpp @@ -103,17 +103,27 @@ void Workspaces::doUpdate() { } } - uint64_t num_tags = - config_["num-tags"].isUInt64() ? config_["num-tags"].asUInt64() : tags.size(); + const auto num_tags = std::min( + config_["num-tags"].isUInt64() ? config_["num-tags"].asUInt64() : tags.size(), tags.size()); - for (const auto& tag : tags) { - uint64_t idx = tag["index"].asUInt64(); + std::vector ordered_tags; + ordered_tags.reserve(num_tags); - if (idx > num_tags) break; + for (Json::ArrayIndex i = 0; i < num_tags; ++i) { + const auto& tag = tags[i]; + ordered_tags.push_back(&tag); + } + + std::ranges::sort(ordered_tags, [](const Json::Value* a, const Json::Value* b) { + return (*a)["index"].asUInt64() < (*b)["index"].asUInt64(); + }); + + for (const auto* tag : ordered_tags) { + uint64_t idx = (*tag)["index"].asUInt64(); auto btn_it = buttons_.find(idx); Gtk::Button& button = (btn_it == buttons_.end()) ? addButton(idx) : btn_it->second; - updateButtonState(button, tag, monitor); + updateButtonState(button, *tag, monitor); } } }