Merge pull request #814 from danieldg/markup-fixes

Allow enabing pango markup in the taskbar string
This commit is contained in:
Alex 2020-08-28 09:01:32 +02:00 committed by GitHub
commit 4a22057138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 19 deletions

View File

@ -32,6 +32,11 @@ Addressed by *wlr/taskbar*
default: 16 ++ default: 16 ++
The size of the icon. The size of the icon.
*markup*: ++
typeof: bool ++
default: false ++
If set to true, pango markup will be accepted in format and tooltip-format.
*tooltip*: ++ *tooltip*: ++
typeof: bool ++ typeof: bool ++
default: true ++ default: true ++

View File

@ -306,7 +306,7 @@ std::string Task::state_string(bool shortened) const
void Task::handle_title(const char *title) void Task::handle_title(const char *title)
{ {
title_ = Glib::Markup::escape_text(title); title_ = title;
} }
void Task::handle_app_id(const char *app_id) void Task::handle_app_id(const char *app_id)
@ -460,38 +460,51 @@ bool Task::operator!=(const Task &o) const
void Task::update() void Task::update()
{ {
bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false;
std::string title = title_;
std::string app_id = app_id_;
if (markup) {
title = Glib::Markup::escape_text(title);
app_id = Glib::Markup::escape_text(app_id);
}
if (!format_before_.empty()) { if (!format_before_.empty()) {
text_before_.set_label( auto txt = fmt::format(format_before_,
fmt::format(format_before_, fmt::arg("title", title),
fmt::arg("title", title_), fmt::arg("app_id", app_id),
fmt::arg("app_id", app_id_),
fmt::arg("state", state_string()), fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true)) fmt::arg("short_state", state_string(true))
) );
); if (markup)
text_before_.set_markup(txt);
else
text_before_.set_label(txt);
text_before_.show(); text_before_.show();
} }
if (!format_after_.empty()) { if (!format_after_.empty()) {
text_after_.set_label( auto txt = fmt::format(format_after_,
fmt::format(format_after_, fmt::arg("title", title),
fmt::arg("title", title_), fmt::arg("app_id", app_id),
fmt::arg("app_id", app_id_),
fmt::arg("state", state_string()), fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true)) fmt::arg("short_state", state_string(true))
) );
); if (markup)
text_after_.set_markup(txt);
else
text_after_.set_label(txt);
text_after_.show(); text_after_.show();
} }
if (!format_tooltip_.empty()) { if (!format_tooltip_.empty()) {
button_.set_tooltip_markup( auto txt = fmt::format(format_tooltip_,
fmt::format(format_tooltip_, fmt::arg("title", title),
fmt::arg("title", title_), fmt::arg("app_id", app_id),
fmt::arg("app_id", app_id_),
fmt::arg("state", state_string()), fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true)) fmt::arg("short_state", state_string(true))
) );
); if (markup)
button_.set_tooltip_markup(txt);
else
button_.set_tooltip_text(txt);
} }
} }