From d59e7c98d57361d9545ad216b15414fbfa86d433 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Wed, 8 Oct 2025 13:52:24 +0300 Subject: [PATCH] feat: added smart title param --- src/modules/mpd/mpd.cpp | 15 +++++++++++++-- subprojects/.wraplock | 0 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 subprojects/.wraplock diff --git a/src/modules/mpd/mpd.cpp b/src/modules/mpd/mpd.cpp index 8e6bbb25..89b500a8 100644 --- a/src/modules/mpd/mpd.cpp +++ b/src/modules/mpd/mpd.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include @@ -118,7 +120,7 @@ void waybar::modules::MPD::setLabel() { auto format = format_; Glib::ustring artist, album_artist, album, title; - std::string date, filename, uri; + std::string date, filename, uri, titleSmart; int song_pos = 0, queue_length = 0, volume = 0; std::chrono::seconds elapsedTime, totalTime; @@ -152,6 +154,13 @@ void waybar::modules::MPD::setLabel() { date = sanitize_string(getTag(MPD_TAG_DATE)); filename = sanitize_string(getFilename()); uri = mpd_song_get_uri(song_.get()); + + if (title == "n/a" || artist == "n/a") { + titleSmart = std::regex_replace(filename, std::regex(R"((\s*$$.*?$$)|(\.(mp3|m4a|opus|ogx))$)"), ""); + } else { + titleSmart = static_cast(artist) + " - " + static_cast(title); + } + song_pos = mpd_status_get_song_pos(status_.get()) + 1; volume = mpd_status_get_volume(status_.get()); if (volume < 0) { @@ -175,6 +184,7 @@ void waybar::modules::MPD::setLabel() { 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()); + if (config_["title-len"].isInt()) titleSmart = titleSmart.substr(0, config_["title-len"].asInt()); try { auto text = fmt::format( @@ -185,7 +195,8 @@ void waybar::modules::MPD::setLabel() { fmt::arg("songPosition", song_pos), fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon), - fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri)); + fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri), + fmt::arg("titleSmart", titleSmart)); if (text.empty()) { label_.hide(); } else { diff --git a/subprojects/.wraplock b/subprojects/.wraplock new file mode 100644 index 00000000..e69de29b