From a301b8c4cd561a77dc5b93eb1577a7879804da87 Mon Sep 17 00:00:00 2001 From: chayleaf Date: Fri, 17 Feb 2023 15:50:07 +0700 Subject: [PATCH] mpris: update docs --- man/waybar-mpris.5.scd | 25 ++++++++++++------------- src/modules/mpris/mpris.cpp | 13 +++++++++---- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/man/waybar-mpris.5.scd b/man/waybar-mpris.5.scd index bc735b93..0abe4cc2 100644 --- a/man/waybar-mpris.5.scd +++ b/man/waybar-mpris.5.scd @@ -45,8 +45,7 @@ The *mpris* module displays currently playing media via libplayerctl. *tooltip-format-[status]*: ++ typeof: string ++ - default: "MPD (disconnected)" ++ - The status-specif tooltip format. + The status-specific tooltip format. *artist-len*: ++ typeof: integer ++ @@ -66,34 +65,34 @@ The *mpris* module displays currently playing media via libplayerctl. *dynamic-len*: ++ typeof: integer ++ 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* ++ 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 list means force inclusion). *truncate-hours*: ++ typeof: bool ++ 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*: ++ typeof: bool ++ 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*: ++ typeof: string ++ default: "…" ++ - Override the default ellipsis (set to empty string to simply truncate - the tags when needed instead). - -*on-click*: ++ - typeof: string ++ - default: play-pause ++ - Overwrite default action toggles. + This character will be used when any of the tags exceed their maximum + length. If you don't want to use an ellipsis, set this to empty string. *on-click*: ++ typeof: string ++ diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 6e8004d6..d2837734 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -206,7 +206,7 @@ size_t utf8_truncate(std::string& str, size_t width = std::string::npos) { return str.length(); } else if (g_unichar_iswide(c)) { 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; } @@ -339,6 +339,11 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) -> } 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 (showAlbum) dynamic << album << " - "; if (showTitle) dynamic << title; @@ -472,21 +477,21 @@ auto Mpris::getPlayerInfo() -> std::optional { if (auto artist_ = playerctl_player_get_artist(player, &error)) { spdlog::debug("mpris[{}]: artist = {}", info.name, artist_); - info.artist = Glib::Markup::escape_text(artist_); + info.artist = artist_; g_free(artist_); } if (error) goto errorexit; if (auto album_ = playerctl_player_get_album(player, &error)) { spdlog::debug("mpris[{}]: album = {}", info.name, album_); - info.album = Glib::Markup::escape_text(album_); + info.album = album_; g_free(album_); } if (error) goto errorexit; if (auto title_ = playerctl_player_get_title(player, &error)) { spdlog::debug("mpris[{}]: title = {}", info.name, title_); - info.title = Glib::Markup::escape_text(title_); + info.title = title_; g_free(title_); } if (error) goto errorexit;