From 0cfd1c7094fca18082b166a2dd4f43e761903fed Mon Sep 17 00:00:00 2001 From: chayleaf Date: Tue, 21 Feb 2023 03:38:26 +0700 Subject: [PATCH] mpris: don't put ellipsis after whitespace --- include/modules/mpris/mpris.hpp | 4 ++-- man/waybar-mpris.5.scd | 27 ++++++++++++++------------- src/modules/mpris/mpris.cpp | 6 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/modules/mpris/mpris.hpp b/include/modules/mpris/mpris.hpp index 0563ceec..ea5f7de6 100644 --- a/include/modules/mpris/mpris.hpp +++ b/include/modules/mpris/mpris.hpp @@ -39,8 +39,8 @@ class Mpris : public ALabel { std::optional artist; std::optional album; std::optional title; - std::optional length; // as HH:MM:SS - std::optional position; // same format + std::optional length; // as HH:MM:SS + std::optional position; // same format }; auto getPlayerInfo() -> std::optional; diff --git a/man/waybar-mpris.5.scd b/man/waybar-mpris.5.scd index e8894116..40f132d8 100644 --- a/man/waybar-mpris.5.scd +++ b/man/waybar-mpris.5.scd @@ -50,30 +50,30 @@ The *mpris* module displays currently playing media via libplayerctl. *artist-len*: ++ typeof: integer ++ Maximum length of the Artist tag (Wide/Fullwidth Unicode characters - count as two). + count as two). Set to zero to hide the artist in `{dynamic}` tag. *album-len*: ++ typeof: integer ++ Maximum length of the Album tag (Wide/Fullwidth Unicode characters count - as two). + as two). Set to zero to hide the album in `{dynamic}` tag. *title-len*: ++ typeof: integer ++ Maximum length of the Title tag (Wide/Fullwidth Unicode characters count - as two). + as two). Set to zero to hide the title in `{dynamic}` tag. *dynamic-len*: ++ typeof: integer ++ - Maximum length of the Dynamic tag (Wide/Fullwidth Unicode characters - 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 + Maximum length of the Dynamic tag (Wide/Fullwidth Unicode characters ++ + 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 ++ - default: ["title", "length", "position", "artist", "album"] + default: ["title", "length", "position", "artist", "album"] ++ Priority of the tags when truncating the Dynamic tag (absence in this list means force inclusion). @@ -108,7 +108,8 @@ The *mpris* module displays currently playing media via libplayerctl. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. + If the module is rotated, it will follow the flow of the text. *on-click*: ++ typeof: string ++ @@ -126,11 +127,11 @@ The *mpris* module displays currently playing media via libplayerctl. Overwrite default action toggles. *player-icons*: ++ - typeof: map[string]string + typeof: map[string]string ++ Allows setting _{player-icon}_ based on player-name property. *status-icons*: ++ - typeof: map[string]string + typeof: map[string]string ++ Allows setting _{status-icon}_ based on player status (playing, paused, stopped). diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 01f74c22..d1c94eca 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -32,7 +32,6 @@ Mpris::Mpris(const std::string& id, const Json::Value& config) player_("playerctld"), manager(), player() { - if (config_["format-playing"].isString()) { format_playing_ = config_["format-playing"].asString(); } @@ -192,12 +191,13 @@ 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) && c != 0xAD) { // neither zero-width nor soft hyphen + } else if (!g_unichar_iszerowidth(c) && c != 0xAD) { // neither zero-width nor soft hyphen total_width += 1; } data = g_utf8_find_next_char(data, end); - if (width != std::string::npos && total_width <= width) trunc_end = data; + if (width != std::string::npos && total_width <= width && !g_unichar_isspace(c)) + trunc_end = data; } if (trunc_end) str.resize(trunc_end - str.data());