From 76c2f3166ef6003fe5f206925ff5dd7eb0dde6a4 Mon Sep 17 00:00:00 2001 From: Nicolas Lenz Date: Wed, 5 Jun 2024 19:58:27 +0200 Subject: [PATCH 1/2] format RegexCollection output using match results --- include/util/regex_collection.hpp | 4 ++-- src/util/regex_collection.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/util/regex_collection.hpp b/include/util/regex_collection.hpp index 5ea2882e0..fe958461d 100644 --- a/include/util/regex_collection.hpp +++ b/include/util/regex_collection.hpp @@ -36,7 +36,7 @@ class RegexCollection { std::map regex_cache; std::string default_repr; - std::string& find_match(std::string& value, bool& matched_any); + std::string find_match(std::string& value, bool& matched_any); public: RegexCollection() = default; @@ -48,4 +48,4 @@ class RegexCollection { std::string& get(std::string& value); }; -} // namespace waybar::util \ No newline at end of file +} // namespace waybar::util diff --git a/src/util/regex_collection.cpp b/src/util/regex_collection.cpp index 704d65455..db2f30ea1 100644 --- a/src/util/regex_collection.cpp +++ b/src/util/regex_collection.cpp @@ -31,11 +31,12 @@ RegexCollection::RegexCollection(const Json::Value& map, std::string default_rep std::sort(rules.begin(), rules.end(), [](Rule& a, Rule& b) { return a.priority > b.priority; }); } -std::string& RegexCollection::find_match(std::string& value, bool& matched_any) { +std::string RegexCollection::find_match(std::string& value, bool& matched_any) { for (auto& rule : rules) { - if (std::regex_search(value, rule.rule)) { + std::smatch match; + if (std::regex_search(value, match, rule.rule)) { matched_any = true; - return rule.repr; + return match.format(rule.repr.data()); } } From d0a8c1d90dace8cccdb23e0da6d1e288770cc151 Mon Sep 17 00:00:00 2001 From: Nicolas Lenz Date: Wed, 5 Jun 2024 20:16:30 +0200 Subject: [PATCH 2/2] document capturing in window-rewrite --- man/waybar-hyprland-workspaces.5.scd | 1 + man/waybar-sway-workspaces.5.scd | 1 + 2 files changed, 2 insertions(+) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 406ada7a2..686f8aa75 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -147,6 +147,7 @@ Additional to workspace name matching, the following *format-icons* can be set. "class title<.*github.*>": "", // Windows whose class is "firefox" and title contains "github". Note that "class" always comes first. "foot": "", // Windows that contain "foot" in either class or title. For optimization reasons, it will only match against a title if at least one other window explicitly matches against a title. "code": "󰨞", + "title<.* - (.*) - VSCodium>": "codium $1" // captures part of the window title and formats it into output } } ``` diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index 8f0ac8580..a65a999ba 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -171,6 +171,7 @@ n.b.: the list of outputs can be obtained from command line using *swaymsg -t ge "window-rewrite": { "class": "", "class": "k", + "title<.* - (.*) - VSCodium>": "codium $1" // captures part of the window title and formats it into output } } ```