mpris: update docs

pull/2011/head
chayleaf 2023-02-17 15:50:07 +07:00
parent 5383f7bd56
commit a301b8c4cd
2 changed files with 21 additions and 17 deletions

View File

@ -45,8 +45,7 @@ The *mpris* module displays currently playing media via libplayerctl.
*tooltip-format-[status]*: ++ *tooltip-format-[status]*: ++
typeof: string ++ typeof: string ++
default: "MPD (disconnected)" ++ The status-specific tooltip format.
The status-specif tooltip format.
*artist-len*: ++ *artist-len*: ++
typeof: integer ++ typeof: integer ++
@ -66,34 +65,34 @@ The *mpris* module displays currently playing media via libplayerctl.
*dynamic-len*: ++ *dynamic-len*: ++
typeof: integer ++ typeof: integer ++
Maximum length of the Dynamic tag (Wide/Fullwidth Unicode characters Maximum length of the Dynamic tag (Wide/Fullwidth Unicode characters
count as two). count as two). The dynamic tag will not truncate any tags beyond their
set length limits, instead, it will attempt to fit as much of the
available tags as possible. It is recommended you set title-len to
something less than or equal to this value, so the title will always be
displayed.
*dynamic-priority* ++ *dynamic-priority* ++
typeof: []string ++ typeof: []string ++
default: ["title", "length", "artist", "album"] default: ["title", "length", "position", "artist", "album"]
Priority of the tags when truncating the Dynamic tag (absence in this Priority of the tags when truncating the Dynamic tag (absence in this
list means force inclusion). list means force inclusion).
*truncate-hours*: ++ *truncate-hours*: ++
typeof: bool ++ typeof: bool ++
default: true ++ default: true ++
Whether to truncate hours when media duration is less than an hour long Whether to hide hours when media duration is less than an hour long.
*enable-tooltip-len-limits*: ++ *enable-tooltip-len-limits*: ++
typeof: bool ++ typeof: bool ++
default: false ++ default: false ++
Option to enable the length limits for the tooltip as well Option to enable the length limits for the tooltip as well. By default
the tooltip ignores all length limits.
*ellipsis*: ++ *ellipsis*: ++
typeof: string ++ typeof: string ++
default: "…" ++ default: "…" ++
Override the default ellipsis (set to empty string to simply truncate This character will be used when any of the tags exceed their maximum
the tags when needed instead). length. If you don't want to use an ellipsis, set this to empty string.
*on-click*: ++
typeof: string ++
default: play-pause ++
Overwrite default action toggles.
*on-click*: ++ *on-click*: ++
typeof: string ++ typeof: string ++

View File

@ -206,7 +206,7 @@ size_t utf8_truncate(std::string& str, size_t width = std::string::npos) {
return str.length(); return str.length();
} else if (g_unichar_iswide(c)) { } else if (g_unichar_iswide(c)) {
total_width += 2; total_width += 2;
} else if (!g_unichar_iszerowidth(c)) { } else if (!g_unichar_iszerowidth(c) && c != 0xAD) { // neither zero-width nor soft hyphen
total_width += 1; total_width += 1;
} }
@ -339,6 +339,11 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) ->
} }
std::stringstream dynamic; std::stringstream dynamic;
if (html) {
artist = Glib::Markup::escape_text(artist);
album = Glib::Markup::escape_text(album);
title = Glib::Markup::escape_text(title);
}
if (showArtist) dynamic << artist << " - "; if (showArtist) dynamic << artist << " - ";
if (showAlbum) dynamic << album << " - "; if (showAlbum) dynamic << album << " - ";
if (showTitle) dynamic << title; if (showTitle) dynamic << title;
@ -472,21 +477,21 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
if (auto artist_ = playerctl_player_get_artist(player, &error)) { if (auto artist_ = playerctl_player_get_artist(player, &error)) {
spdlog::debug("mpris[{}]: artist = {}", info.name, artist_); spdlog::debug("mpris[{}]: artist = {}", info.name, artist_);
info.artist = Glib::Markup::escape_text(artist_); info.artist = artist_;
g_free(artist_); g_free(artist_);
} }
if (error) goto errorexit; if (error) goto errorexit;
if (auto album_ = playerctl_player_get_album(player, &error)) { if (auto album_ = playerctl_player_get_album(player, &error)) {
spdlog::debug("mpris[{}]: album = {}", info.name, album_); spdlog::debug("mpris[{}]: album = {}", info.name, album_);
info.album = Glib::Markup::escape_text(album_); info.album = album_;
g_free(album_); g_free(album_);
} }
if (error) goto errorexit; if (error) goto errorexit;
if (auto title_ = playerctl_player_get_title(player, &error)) { if (auto title_ = playerctl_player_get_title(player, &error)) {
spdlog::debug("mpris[{}]: title = {}", info.name, title_); spdlog::debug("mpris[{}]: title = {}", info.name, title_);
info.title = Glib::Markup::escape_text(title_); info.title = title_;
g_free(title_); g_free(title_);
} }
if (error) goto errorexit; if (error) goto errorexit;