Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add length limits for MPD module tags #1002

Merged
merged 8 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions man/waybar-mpd.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ Addressed by *mpd*
default: "MPD (disconnected)" ++
Tooltip information displayed when the MPD server can't be reached.

*artist-len*: ++
typeof: integer ++
Maximum length of the Artist tag.

*album-len*: ++
typeof: integer ++
Maximum length of the Album tag.

*album-artist-len*: ++
typeof: integer ++
Maximum length of the Album Artist tag.

*title-len*: ++
typeof: integer ++
Maximum length of the Title tag.

*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
Expand Down
34 changes: 23 additions & 11 deletions src/modules/mpd/mpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <fmt/chrono.h>
#include <spdlog/spdlog.h>

#include <glibmm/ustring.h>
#include "modules/mpd/state.hpp"
#if defined(MPD_NOINLINE)
namespace waybar::modules {
Expand Down Expand Up @@ -98,8 +98,8 @@ void waybar::modules::MPD::setLabel() {
}

auto format = format_;

std::string artist, album_artist, album, title, date;
Glib::ustring artist, album_artist, album, title;
std::string date;
int song_pos = 0, queue_length = 0;
std::chrono::seconds elapsedTime, totalTime;

Expand Down Expand Up @@ -144,13 +144,25 @@ void waybar::modules::MPD::setLabel() {
bool singleActivated = mpd_status_get_single(status_.get());
std::string singleIcon = getOptionIcon("single", singleActivated);

auto artistLen = config_["artist-len"].isInt() ?
nullobsi marked this conversation as resolved.
Show resolved Hide resolved
config_["artist-len"].asInt() : artist.size();

auto albumArtistLen = config_["album-artist-len"].isInt() ?
config_["album-artist-len"].asInt() : album_artist.size();

auto albumLen = config_["album-len"].isInt() ?
config_["album-len"].asInt() : album.size();

auto titleLen = config_["title-len"].isInt() ?
config_["title-len"].asInt() : title.size();

try {
label_.set_markup(
fmt::format(format,
fmt::arg("artist", Glib::Markup::escape_text(artist).raw()),
fmt::arg("albumArtist", Glib::Markup::escape_text(album_artist).raw()),
fmt::arg("album", Glib::Markup::escape_text(album).raw()),
fmt::arg("title", Glib::Markup::escape_text(title).raw()),
fmt::arg("artist", Glib::Markup::escape_text(artist.substr(0, artistLen)).raw()),
fmt::arg("albumArtist", Glib::Markup::escape_text(album_artist.substr(0, albumArtistLen)).raw()),
fmt::arg("album", Glib::Markup::escape_text(album.substr(0, albumLen)).raw()),
fmt::arg("title", Glib::Markup::escape_text(title.substr(0, titleLen)).raw()),
fmt::arg("date", Glib::Markup::escape_text(date).raw()),
fmt::arg("elapsedTime", elapsedTime),
fmt::arg("totalTime", totalTime),
Expand All @@ -171,10 +183,10 @@ void waybar::modules::MPD::setLabel() {
: "MPD (connected)";
try {
auto tooltip_text = fmt::format(tooltip_format,
fmt::arg("artist", artist),
fmt::arg("albumArtist", album_artist),
fmt::arg("album", album),
fmt::arg("title", title),
fmt::arg("artist", artist.substr(0, artistLen).raw()),
fmt::arg("albumArtist", album_artist.substr(0, albumArtistLen).raw()),
fmt::arg("album", album.substr(0, albumLen).raw()),
fmt::arg("title", title.substr(0, titleLen).raw()),
fmt::arg("date", date),
fmt::arg("elapsedTime", elapsedTime),
fmt::arg("totalTime", totalTime),
Expand Down