Merge pull request #4084 from PandorasFox/master
add prefer-album-artist to mpris module
This commit is contained in:
@@ -38,6 +38,7 @@ 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> album_artist;
|
||||||
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
|
||||||
@@ -76,6 +77,8 @@ class Mpris : public ALabel {
|
|||||||
std::string player_;
|
std::string player_;
|
||||||
std::vector<std::string> ignored_players_;
|
std::vector<std::string> ignored_players_;
|
||||||
|
|
||||||
|
bool prefer_album_artist_;
|
||||||
|
|
||||||
PlayerctlPlayerManager* manager;
|
PlayerctlPlayerManager* manager;
|
||||||
PlayerctlPlayer* player;
|
PlayerctlPlayer* player;
|
||||||
PlayerctlPlayer* last_active_player_ = nullptr;
|
PlayerctlPlayer* last_active_player_ = nullptr;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||||||
dynamic_separator_(" - "),
|
dynamic_separator_(" - "),
|
||||||
truncate_hours_(true),
|
truncate_hours_(true),
|
||||||
tooltip_len_limits_(false),
|
tooltip_len_limits_(false),
|
||||||
|
prefer_album_artist_(false),
|
||||||
// this character is used in Gnome so it's fine to use it here
|
// this character is used in Gnome so it's fine to use it here
|
||||||
ellipsis_("\u2026"),
|
ellipsis_("\u2026"),
|
||||||
player_("playerctld"),
|
player_("playerctld"),
|
||||||
@@ -68,6 +69,9 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||||||
if (config_["enable-tooltip-len-limits"].isBool()) {
|
if (config_["enable-tooltip-len-limits"].isBool()) {
|
||||||
tooltip_len_limits_ = config["enable-tooltip-len-limits"].asBool();
|
tooltip_len_limits_ = config["enable-tooltip-len-limits"].asBool();
|
||||||
}
|
}
|
||||||
|
if (config_["prefer-album-artist"].isBool()) {
|
||||||
|
prefer_album_artist_ = config["prefer-album-artist"].asBool();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config["artist-len"].isUInt()) {
|
if (config["artist-len"].isUInt()) {
|
||||||
@@ -206,6 +210,12 @@ auto Mpris::getIconFromJson(const Json::Value& icons, const std::string& key) ->
|
|||||||
|
|
||||||
auto Mpris::getArtistStr(const PlayerInfo& info, bool truncated) -> std::string {
|
auto Mpris::getArtistStr(const PlayerInfo& info, bool truncated) -> std::string {
|
||||||
auto artist = info.artist.value_or(std::string());
|
auto artist = info.artist.value_or(std::string());
|
||||||
|
if (prefer_album_artist_) {
|
||||||
|
auto album_artist = info.album_artist.value_or(std::string());
|
||||||
|
if (!album_artist.empty()) {
|
||||||
|
artist = album_artist;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (truncated && artist_len_ >= 0) waybar::util::utf8_truncate(artist, ellipsis_, artist_len_);
|
if (truncated && artist_len_ >= 0) waybar::util::utf8_truncate(artist, ellipsis_, artist_len_);
|
||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
@@ -521,6 +531,7 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
|
|||||||
.status_string = player_status,
|
.status_string = player_status,
|
||||||
.artist = std::nullopt,
|
.artist = std::nullopt,
|
||||||
.album = std::nullopt,
|
.album = std::nullopt,
|
||||||
|
.album_artist = std::nullopt,
|
||||||
.title = std::nullopt,
|
.title = std::nullopt,
|
||||||
.length = std::nullopt,
|
.length = std::nullopt,
|
||||||
};
|
};
|
||||||
@@ -532,6 +543,13 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
|
|||||||
}
|
}
|
||||||
if (error) goto errorexit;
|
if (error) goto errorexit;
|
||||||
|
|
||||||
|
if (auto* album_artist_ =
|
||||||
|
playerctl_player_print_metadata_prop(player, "xesam:albumArtist", &error)) {
|
||||||
|
spdlog::debug("mpris[{}]: albumArtist = {}", info.name, album_artist_);
|
||||||
|
info.album_artist = album_artist_;
|
||||||
|
g_free(album_artist_);
|
||||||
|
}
|
||||||
|
|
||||||
if (auto* album_ = playerctl_player_get_album(last_active_player_, &error)) {
|
if (auto* album_ = playerctl_player_get_album(last_active_player_, &error)) {
|
||||||
spdlog::debug("mpris[{}]: album = {}", info.name, album_);
|
spdlog::debug("mpris[{}]: album = {}", info.name, album_);
|
||||||
info.album = album_;
|
info.album = album_;
|
||||||
|
|||||||
Reference in New Issue
Block a user