Merge pull request #3320 from rtgiskard/dev
fix mpris: hide on current player vanished
This commit is contained in:
commit
e8a2882796
|
@ -12,7 +12,8 @@
|
|||
|
||||
#ifdef HAVE_LANGINFO_1STDAY
|
||||
#include <langinfo.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <clocale>
|
||||
#endif
|
||||
|
||||
namespace fmt_lib = waybar::util::date::format;
|
||||
|
@ -126,8 +127,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
}
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_has_tooltip(true);
|
||||
label_.signal_query_tooltip().connect(sigc::mem_fun(*this, &Clock::query_tlp_cb));
|
||||
}
|
||||
|
||||
thread_ = [this] {
|
||||
dp.emit();
|
||||
|
@ -194,8 +197,8 @@ const unsigned cldRowsInMonth(const year_month& ym, const weekday& firstdow) {
|
|||
return 2u + ceil<weeks>((weekday{ym / 1} - firstdow) + ((ym / last).day() - day{0})).count();
|
||||
}
|
||||
|
||||
auto cldGetWeekForLine(const year_month& ym, const weekday& firstdow, const unsigned line)
|
||||
-> const year_month_weekday {
|
||||
auto cldGetWeekForLine(const year_month& ym, const weekday& firstdow,
|
||||
const unsigned line) -> const year_month_weekday {
|
||||
unsigned index{line - 2};
|
||||
if (weekday{ym / 1} == firstdow) ++index;
|
||||
return ym / firstdow[index];
|
||||
|
|
|
@ -96,9 +96,9 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
if (config_["dynamic-order"].isArray()) {
|
||||
dynamic_order_.clear();
|
||||
for (auto it = config_["dynamic-order"].begin(); it != config_["dynamic-order"].end(); ++it) {
|
||||
if (it->isString()) {
|
||||
dynamic_order_.push_back(it->asString());
|
||||
for (const auto& item : config_["dynamic-order"]) {
|
||||
if (item.isString()) {
|
||||
dynamic_order_.push_back(item.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,10 +110,9 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||
player_ = config_["player"].asString();
|
||||
}
|
||||
if (config_["ignored-players"].isArray()) {
|
||||
for (auto it = config_["ignored-players"].begin(); it != config_["ignored-players"].end();
|
||||
++it) {
|
||||
if (it->isString()) {
|
||||
ignored_players_.push_back(it->asString());
|
||||
for (const auto& item : config_["ignored-players"]) {
|
||||
if (item.isString()) {
|
||||
ignored_players_.push_back(item.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +145,8 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||
throw std::runtime_error(fmt::format("unable to list players: {}", error->message));
|
||||
}
|
||||
|
||||
for (auto p = players; p != NULL; p = p->next) {
|
||||
auto pn = static_cast<PlayerctlPlayerName*>(p->data);
|
||||
for (auto* p = players; p != nullptr; p = p->next) {
|
||||
auto* pn = static_cast<PlayerctlPlayerName*>(p->data);
|
||||
if (strcmp(pn->name, player_.c_str()) == 0) {
|
||||
player = playerctl_player_new_from_name(pn, &error);
|
||||
break;
|
||||
|
@ -180,17 +179,14 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
|
||||
Mpris::~Mpris() {
|
||||
if (manager != NULL) g_object_unref(manager);
|
||||
if (player != NULL) g_object_unref(player);
|
||||
if (manager != nullptr) g_object_unref(manager);
|
||||
if (player != nullptr) g_object_unref(player);
|
||||
}
|
||||
|
||||
auto Mpris::getIconFromJson(const Json::Value& icons, const std::string& key) -> std::string {
|
||||
if (icons.isObject()) {
|
||||
if (icons[key].isString()) {
|
||||
return icons[key].asString();
|
||||
} else if (icons["default"].isString()) {
|
||||
return icons["default"].asString();
|
||||
}
|
||||
if (icons[key].isString()) return icons[key].asString();
|
||||
if (icons["default"].isString()) return icons["default"].asString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -205,7 +201,7 @@ size_t utf8_truncate(std::string& str, size_t width = std::string::npos) {
|
|||
|
||||
size_t total_width = 0;
|
||||
|
||||
for (gchar *data = str.data(), *end = data + str.size(); data;) {
|
||||
for (gchar *data = str.data(), *end = data + str.size(); data != nullptr;) {
|
||||
gunichar c = g_utf8_get_char_validated(data, end - data);
|
||||
if (c == -1U || c == -2U) {
|
||||
// invalid unicode, treat string as ascii
|
||||
|
@ -269,7 +265,7 @@ auto Mpris::getLengthStr(const PlayerInfo& info, bool truncated) -> std::string
|
|||
auto length = info.length.value();
|
||||
return (truncated && length.substr(0, 3) == "00:") ? length.substr(3) : length;
|
||||
}
|
||||
return std::string();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Mpris::getPositionStr(const PlayerInfo& info, bool truncated) -> std::string {
|
||||
|
@ -277,7 +273,7 @@ auto Mpris::getPositionStr(const PlayerInfo& info, bool truncated) -> std::strin
|
|||
auto position = info.position.value();
|
||||
return (truncated && position.substr(0, 3) == "00:") ? position.substr(3) : position;
|
||||
}
|
||||
return std::string();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) -> std::string {
|
||||
|
@ -319,33 +315,33 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) ->
|
|||
|
||||
size_t totalLen = 0;
|
||||
|
||||
for (auto it = dynamic_prio_.begin(); it != dynamic_prio_.end(); ++it) {
|
||||
if (*it == "artist") {
|
||||
for (const auto& item : dynamic_prio_) {
|
||||
if (item == "artist") {
|
||||
if (totalLen + artistLen > dynamicLen) {
|
||||
showArtist = false;
|
||||
} else if (showArtist) {
|
||||
totalLen += artistLen;
|
||||
}
|
||||
} else if (*it == "album") {
|
||||
} else if (item == "album") {
|
||||
if (totalLen + albumLen > dynamicLen) {
|
||||
showAlbum = false;
|
||||
} else if (showAlbum) {
|
||||
totalLen += albumLen;
|
||||
}
|
||||
} else if (*it == "title") {
|
||||
} else if (item == "title") {
|
||||
if (totalLen + titleLen > dynamicLen) {
|
||||
showTitle = false;
|
||||
} else if (showTitle) {
|
||||
totalLen += titleLen;
|
||||
}
|
||||
} else if (*it == "length") {
|
||||
} else if (item == "length") {
|
||||
if (totalLen + lengthLen > dynamicLen) {
|
||||
showLength = false;
|
||||
} else if (showLength) {
|
||||
totalLen += lengthLen;
|
||||
posLen = std::max((size_t)2, posLen) - 2;
|
||||
}
|
||||
} else if (*it == "position") {
|
||||
} else if (item == "position") {
|
||||
if (totalLen + posLen > dynamicLen) {
|
||||
showPos = false;
|
||||
} else if (showPos) {
|
||||
|
@ -406,7 +402,7 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) ->
|
|||
|
||||
auto Mpris::onPlayerNameAppeared(PlayerctlPlayerManager* manager, PlayerctlPlayerName* player_name,
|
||||
gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: name-appeared callback: {}", player_name->name);
|
||||
|
@ -415,7 +411,7 @@ auto Mpris::onPlayerNameAppeared(PlayerctlPlayerManager* manager, PlayerctlPlaye
|
|||
return;
|
||||
}
|
||||
|
||||
mpris->player = playerctl_player_new_from_name(player_name, NULL);
|
||||
mpris->player = playerctl_player_new_from_name(player_name, nullptr);
|
||||
g_object_connect(mpris->player, "signal::play", G_CALLBACK(onPlayerPlay), mpris, "signal::pause",
|
||||
G_CALLBACK(onPlayerPause), mpris, "signal::stop", G_CALLBACK(onPlayerStop),
|
||||
mpris, "signal::stop", G_CALLBACK(onPlayerStop), mpris, "signal::metadata",
|
||||
|
@ -426,19 +422,20 @@ auto Mpris::onPlayerNameAppeared(PlayerctlPlayerManager* manager, PlayerctlPlaye
|
|||
|
||||
auto Mpris::onPlayerNameVanished(PlayerctlPlayerManager* manager, PlayerctlPlayerName* player_name,
|
||||
gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: player-vanished callback: {}", player_name->name);
|
||||
|
||||
if (std::string(player_name->name) == mpris->player_) {
|
||||
mpris->player = nullptr;
|
||||
mpris->event_box_.set_visible(false);
|
||||
mpris->dp.emit();
|
||||
}
|
||||
}
|
||||
|
||||
auto Mpris::onPlayerPlay(PlayerctlPlayer* player, gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: player-play callback");
|
||||
|
@ -447,7 +444,7 @@ auto Mpris::onPlayerPlay(PlayerctlPlayer* player, gpointer data) -> void {
|
|||
}
|
||||
|
||||
auto Mpris::onPlayerPause(PlayerctlPlayer* player, gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: player-pause callback");
|
||||
|
@ -456,7 +453,7 @@ auto Mpris::onPlayerPause(PlayerctlPlayer* player, gpointer data) -> void {
|
|||
}
|
||||
|
||||
auto Mpris::onPlayerStop(PlayerctlPlayer* player, gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: player-stop callback");
|
||||
|
@ -468,7 +465,7 @@ auto Mpris::onPlayerStop(PlayerctlPlayer* player, gpointer data) -> void {
|
|||
}
|
||||
|
||||
auto Mpris::onPlayerMetadata(PlayerctlPlayer* player, GVariant* metadata, gpointer data) -> void {
|
||||
Mpris* mpris = static_cast<Mpris*>(data);
|
||||
auto* mpris = static_cast<Mpris*>(data);
|
||||
if (!mpris) return;
|
||||
|
||||
spdlog::debug("mpris: player-metadata callback");
|
||||
|
@ -523,30 +520,30 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
|
|||
.length = std::nullopt,
|
||||
};
|
||||
|
||||
if (auto artist_ = playerctl_player_get_artist(player, &error)) {
|
||||
if (auto* artist_ = playerctl_player_get_artist(player, &error)) {
|
||||
spdlog::debug("mpris[{}]: artist = {}", info.name, artist_);
|
||||
info.artist = artist_;
|
||||
g_free(artist_);
|
||||
}
|
||||
if (error) goto errorexit;
|
||||
|
||||
if (auto album_ = playerctl_player_get_album(player, &error)) {
|
||||
if (auto* album_ = playerctl_player_get_album(player, &error)) {
|
||||
spdlog::debug("mpris[{}]: album = {}", info.name, album_);
|
||||
info.album = album_;
|
||||
g_free(album_);
|
||||
}
|
||||
if (error) goto errorexit;
|
||||
|
||||
if (auto title_ = playerctl_player_get_title(player, &error)) {
|
||||
if (auto* title_ = playerctl_player_get_title(player, &error)) {
|
||||
spdlog::debug("mpris[{}]: title = {}", info.name, title_);
|
||||
info.title = title_;
|
||||
g_free(title_);
|
||||
}
|
||||
if (error) goto errorexit;
|
||||
|
||||
if (auto length_ = playerctl_player_print_metadata_prop(player, "mpris:length", &error)) {
|
||||
if (auto* length_ = playerctl_player_print_metadata_prop(player, "mpris:length", &error)) {
|
||||
spdlog::debug("mpris[{}]: mpris:length = {}", info.name, length_);
|
||||
std::chrono::microseconds len = std::chrono::microseconds(std::strtol(length_, nullptr, 10));
|
||||
auto len = std::chrono::microseconds(std::strtol(length_, nullptr, 10));
|
||||
auto len_h = std::chrono::duration_cast<std::chrono::hours>(len);
|
||||
auto len_m = std::chrono::duration_cast<std::chrono::minutes>(len - len_h);
|
||||
auto len_s = std::chrono::duration_cast<std::chrono::seconds>(len - len_h - len_m);
|
||||
|
@ -563,7 +560,7 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
|
|||
error = nullptr;
|
||||
} else {
|
||||
spdlog::debug("mpris[{}]: position = {}", info.name, position_);
|
||||
std::chrono::microseconds len = std::chrono::microseconds(position_);
|
||||
auto len = std::chrono::microseconds(position_);
|
||||
auto len_h = std::chrono::duration_cast<std::chrono::hours>(len);
|
||||
auto len_m = std::chrono::duration_cast<std::chrono::minutes>(len - len_h);
|
||||
auto len_s = std::chrono::duration_cast<std::chrono::seconds>(len - len_h - len_m);
|
||||
|
|
Loading…
Reference in New Issue