mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #2068 from TheRealLorenz/master
This commit is contained in:
commit
a6084ea7e6
@ -4,5 +4,5 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
std::string rewriteTitle(const std::string&, const Json::Value&);
|
std::string rewriteString(const std::string&, const Json::Value&);
|
||||||
}
|
}
|
@ -87,7 +87,7 @@ Addressed by *sway/window*
|
|||||||
|
|
||||||
*rewrite*: ++
|
*rewrite*: ++
|
||||||
typeof: object ++
|
typeof: object ++
|
||||||
Rules to rewrite window title. See *rewrite rules*.
|
Rules to rewrite the module format output. See *rewrite rules*.
|
||||||
|
|
||||||
*icon*: ++
|
*icon*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
@ -116,7 +116,7 @@ captures of the expression.
|
|||||||
|
|
||||||
Regular expression and replacement follow ECMA-script rules.
|
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.
|
Invalid expressions (e.g., mismatched parentheses) are skipped.
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ src_files = files(
|
|||||||
'src/group.cpp',
|
'src/group.cpp',
|
||||||
'src/util/ustring_clen.cpp',
|
'src/util/ustring_clen.cpp',
|
||||||
'src/util/sanitize_str.cpp',
|
'src/util/sanitize_str.cpp',
|
||||||
'src/util/rewrite_title.cpp'
|
'src/util/rewrite_string.cpp'
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_linux
|
if is_linux
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "modules/hyprland/backend.hpp"
|
#include "modules/hyprland/backend.hpp"
|
||||||
#include "util/command.hpp"
|
#include "util/command.hpp"
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ auto Window::update() -> void {
|
|||||||
if (!format_.empty()) {
|
if (!format_.empty()) {
|
||||||
label_.show();
|
label_.show();
|
||||||
label_.set_markup(fmt::format(fmt::runtime(format_),
|
label_.set_markup(fmt::format(fmt::runtime(format_),
|
||||||
waybar::util::rewriteTitle(lastView, config_["rewrite"])));
|
waybar::util::rewriteString(lastView, config_["rewrite"])));
|
||||||
} else {
|
} else {
|
||||||
label_.hide();
|
label_.hide();
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
@ -204,10 +204,10 @@ auto Window::update() -> void {
|
|||||||
old_app_id_ = app_id_;
|
old_app_id_ = app_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
label_.set_markup(
|
label_.set_markup(waybar::util::rewriteString(
|
||||||
fmt::format(fmt::runtime(format_),
|
fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_),
|
||||||
fmt::arg("title", waybar::util::rewriteTitle(window_, config_["rewrite"])),
|
fmt::arg("shell", shell_)),
|
||||||
fmt::arg("app_id", app_id_), fmt::arg("shell", shell_)));
|
config_["rewrite"]));
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(window_);
|
label_.set_tooltip_text(window_);
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
namespace waybar::util {
|
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()) {
|
if (!rules.isObject()) {
|
||||||
return title;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string res = title;
|
std::string res = value;
|
||||||
|
|
||||||
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
||||||
if (it.key().isString() && it->isString()) {
|
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.
|
// malformated regexes will cause an exception.
|
||||||
// in this case, log error and try the next rule.
|
// in this case, log error and try the next rule.
|
||||||
const std::regex rule{it.key().asString()};
|
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());
|
res = std::regex_replace(res, rule, it->asString());
|
||||||
}
|
}
|
||||||
} catch (const std::regex_error& e) {
|
} catch (const std::regex_error& e) {
|
Loading…
Reference in New Issue
Block a user