Skip to content

Commit

Permalink
Merge pull request #1002 from nullobsi/master
Browse files Browse the repository at this point in the history
add length limits for MPD module tags
  • Loading branch information
Alexays authored Mar 15, 2021
2 parents b4ffb8a + bf3efdb commit b1dd620
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
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
18 changes: 11 additions & 7 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 @@ -143,6 +143,10 @@ void waybar::modules::MPD::setLabel() {
std::string repeatIcon = getOptionIcon("repeat", repeatActivated);
bool singleActivated = mpd_status_get_single(status_.get());
std::string singleIcon = getOptionIcon("single", singleActivated);
if (config_["artist-len"].isInt()) artist = artist.substr(0, config_["artist-len"].asInt());
if (config_["album-artist-len"].isInt()) album_artist = album_artist.substr(0, config_["album-artist-len"].asInt());
if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt());
if (config_["title-len"].isInt()) title = title.substr(0,config_["title-len"].asInt());
try {
label_.set_markup(
Expand Down Expand Up @@ -171,10 +175,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.raw()),
fmt::arg("albumArtist", album_artist.raw()),
fmt::arg("album", album.raw()),
fmt::arg("title", title.raw()),
fmt::arg("date", date),
fmt::arg("elapsedTime", elapsedTime),
fmt::arg("totalTime", totalTime),
Expand Down

0 comments on commit b1dd620

Please sign in to comment.