mpris: don't put ellipsis after whitespace

This commit is contained in:
chayleaf 2023-02-21 03:38:26 +07:00
parent e5524d5059
commit 0cfd1c7094
3 changed files with 19 additions and 18 deletions

View File

@ -39,8 +39,8 @@ class Mpris : public ALabel {
std::optional<std::string> artist; std::optional<std::string> artist;
std::optional<std::string> album; std::optional<std::string> album;
std::optional<std::string> title; std::optional<std::string> title;
std::optional<std::string> length; // as HH:MM:SS std::optional<std::string> length; // as HH:MM:SS
std::optional<std::string> position; // same format std::optional<std::string> position; // same format
}; };
auto getPlayerInfo() -> std::optional<PlayerInfo>; auto getPlayerInfo() -> std::optional<PlayerInfo>;

View File

@ -50,30 +50,30 @@ The *mpris* module displays currently playing media via libplayerctl.
*artist-len*: ++ *artist-len*: ++
typeof: integer ++ typeof: integer ++
Maximum length of the Artist tag (Wide/Fullwidth Unicode characters 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*: ++ *album-len*: ++
typeof: integer ++ typeof: integer ++
Maximum length of the Album tag (Wide/Fullwidth Unicode characters count 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*: ++ *title-len*: ++
typeof: integer ++ typeof: integer ++
Maximum length of the Title tag (Wide/Fullwidth Unicode characters count 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*: ++ *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). The dynamic tag will not truncate any tags beyond their 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 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 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 something less than or equal to this value, so the title will always be ++
displayed. displayed.
*dynamic-priority* ++ *dynamic-priority*: ++
typeof: []string ++ 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 Priority of the tags when truncating the Dynamic tag (absence in this
list means force inclusion). list means force inclusion).
@ -108,7 +108,8 @@ The *mpris* module displays currently playing media via libplayerctl.
*align*: ++ *align*: ++
typeof: float ++ 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*: ++ *on-click*: ++
typeof: string ++ typeof: string ++
@ -126,11 +127,11 @@ The *mpris* module displays currently playing media via libplayerctl.
Overwrite default action toggles. Overwrite default action toggles.
*player-icons*: ++ *player-icons*: ++
typeof: map[string]string typeof: map[string]string ++
Allows setting _{player-icon}_ based on player-name property. Allows setting _{player-icon}_ based on player-name property.
*status-icons*: ++ *status-icons*: ++
typeof: map[string]string typeof: map[string]string ++
Allows setting _{status-icon}_ based on player status (playing, paused, Allows setting _{status-icon}_ based on player status (playing, paused,
stopped). stopped).

View File

@ -32,7 +32,6 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
player_("playerctld"), player_("playerctld"),
manager(), manager(),
player() { player() {
if (config_["format-playing"].isString()) { if (config_["format-playing"].isString()) {
format_playing_ = config_["format-playing"].asString(); 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(); 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) && 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; total_width += 1;
} }
data = g_utf8_find_next_char(data, end); 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()); if (trunc_end) str.resize(trunc_end - str.data());