From 63525ec95628a0720af457f38f6e266a723db9ac Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sat, 25 Mar 2023 17:33:01 +0100 Subject: [PATCH 1/3] Rename function name --- include/util/{rewrite_title.hpp => rewrite_string.hpp} | 2 +- meson.build | 2 +- src/modules/hyprland/window.cpp | 4 ++-- src/modules/sway/window.cpp | 4 ++-- src/util/{rewrite_title.cpp => rewrite_string.cpp} | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) rename include/util/{rewrite_title.hpp => rewrite_string.hpp} (55%) rename src/util/{rewrite_title.cpp => rewrite_string.cpp} (75%) diff --git a/include/util/rewrite_title.hpp b/include/util/rewrite_string.hpp similarity index 55% rename from include/util/rewrite_title.hpp rename to include/util/rewrite_string.hpp index c477339..2ab39ad 100644 --- a/include/util/rewrite_title.hpp +++ b/include/util/rewrite_string.hpp @@ -4,5 +4,5 @@ #include namespace waybar::util { -std::string rewriteTitle(const std::string&, const Json::Value&); +std::string rewriteString(const std::string&, const Json::Value&); } diff --git a/meson.build b/meson.build index ad6541e..58e1c67 100644 --- a/meson.build +++ b/meson.build @@ -172,7 +172,7 @@ src_files = files( 'src/group.cpp', 'src/util/ustring_clen.cpp', 'src/util/sanitize_str.cpp', - 'src/util/rewrite_title.cpp' + 'src/util/rewrite_string.cpp' ) if is_linux diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index 47daae9..40b6620 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -8,7 +8,7 @@ #include "modules/hyprland/backend.hpp" #include "util/command.hpp" #include "util/json.hpp" -#include "util/rewrite_title.hpp" +#include "util/rewrite_string.hpp" namespace waybar::modules::hyprland { @@ -41,7 +41,7 @@ auto Window::update() -> void { if (!format_.empty()) { label_.show(); label_.set_markup(fmt::format(fmt::runtime(format_), - waybar::util::rewriteTitle(lastView, config_["rewrite"]))); + waybar::util::rewriteString(lastView, config_["rewrite"]))); } else { label_.hide(); } diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 7d60d29..c3c19f5 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -12,7 +12,7 @@ #include #include -#include "util/rewrite_title.hpp" +#include "util/rewrite_string.hpp" namespace waybar::modules::sway { @@ -206,7 +206,7 @@ auto Window::update() -> void { label_.set_markup( fmt::format(fmt::runtime(format_), - fmt::arg("title", waybar::util::rewriteTitle(window_, config_["rewrite"])), + fmt::arg("title", waybar::util::rewriteString(window_, config_["rewrite"])), fmt::arg("app_id", app_id_), fmt::arg("shell", shell_))); if (tooltipEnabled()) { label_.set_tooltip_text(window_); diff --git a/src/util/rewrite_title.cpp b/src/util/rewrite_string.cpp similarity index 75% rename from src/util/rewrite_title.cpp rename to src/util/rewrite_string.cpp index fae59bb..40c71e9 100644 --- a/src/util/rewrite_title.cpp +++ b/src/util/rewrite_string.cpp @@ -1,16 +1,16 @@ -#include "util/rewrite_title.hpp" +#include "util/rewrite_string.hpp" #include #include namespace waybar::util { -std::string rewriteTitle(const std::string& title, const Json::Value& rules) { +std::string rewriteString(const std::string& value, const Json::Value& rules) { if (!rules.isObject()) { - return title; + return value; } - std::string res = title; + std::string res = value; for (auto it = rules.begin(); it != rules.end(); ++it) { if (it.key().isString() && it->isString()) { @@ -18,7 +18,7 @@ std::string rewriteTitle(const std::string& title, const Json::Value& rules) { // malformated regexes will cause an exception. // in this case, log error and try the next rule. const std::regex rule{it.key().asString()}; - if (std::regex_match(title, rule)) { + if (std::regex_match(value, rule)) { res = std::regex_replace(res, rule, it->asString()); } } catch (const std::regex_error& e) { From f557697e92b4fb07386ffe8fbc0450903019882c Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sat, 25 Mar 2023 17:36:00 +0100 Subject: [PATCH 2/3] Rewrite entire label in sway/window module Closes #1742 --- src/modules/sway/window.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index c3c19f5..3c528e0 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -204,10 +204,10 @@ auto Window::update() -> void { old_app_id_ = app_id_; } - label_.set_markup( - fmt::format(fmt::runtime(format_), - fmt::arg("title", waybar::util::rewriteString(window_, config_["rewrite"])), - fmt::arg("app_id", app_id_), fmt::arg("shell", shell_))); + label_.set_markup(waybar::util::rewriteString( + fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_), + fmt::arg("shell", shell_)), + config_["rewrite"])); if (tooltipEnabled()) { label_.set_tooltip_text(window_); } From 4b27385da2838f69c72eb8a921b6aeeca7c4b266 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sat, 25 Mar 2023 17:41:09 +0100 Subject: [PATCH 3/3] Update manpage for sway/window module --- man/waybar-sway-window.5.scd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 19e0cd2..0dd1629 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -87,7 +87,7 @@ Addressed by *sway/window* *rewrite*: ++ typeof: object ++ - Rules to rewrite window title. See *rewrite rules*. + Rules to rewrite the module format output. See *rewrite rules*. *icon*: ++ typeof: bool ++ @@ -116,7 +116,7 @@ captures of the expression. Regular expression and replacement follow ECMA-script rules. -If no expression matches, the title is left unchanged. +If no expression matches, the format output is left unchanged. Invalid expressions (e.g., mismatched parentheses) are skipped.