mpd: adapt Playing::on_io to post-refactor Context API

queryMPD() was removed from Context by the master-side dedup refactor
(perf(mpd): avoid duplicate playing-state updates). fetchState() is
already called earlier in on_io and emit() updates the GUI, so the
redundant queryMPD() call is dropped, matching the identical resolution
applied to Playing::on_timer on master.
This commit is contained in:
Alex
2026-07-03 22:22:35 +02:00
parent 03da065e87
commit 22f6e3c83c
+20 -25
View File
@@ -19,17 +19,17 @@ auto format_as(enum mpd_idle val) {
namespace waybar::modules::detail { namespace waybar::modules::detail {
#define RUN_NOIDLE_AND_CMD(STATE, ...) \ #define RUN_NOIDLE_AND_CMD(STATE, ...) \
if (idle_connection_.connected()) { \ if (idle_connection_.connected()) { \
idle_connection_.disconnect(); \ idle_connection_.disconnect(); \
auto conn = ctx_->connection().get(); \ auto conn = ctx_->connection().get(); \
if (!mpd_run_noidle(conn)) { \ if (!mpd_run_noidle(conn)) { \
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { \ if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { \
spdlog::error("mpd: STATE: failed to unregister for IDLE events"); \ spdlog::error("mpd: STATE: failed to unregister for IDLE events"); \
ctx_->checkErrors(conn); \ ctx_->checkErrors(conn); \
} \ } \
} \ } \
__VA_ARGS__; \ __VA_ARGS__; \
} }
void Idle::play() { void Idle::play() {
@@ -50,7 +50,6 @@ void Idle::stop() {
ctx_->setState(std::make_unique<Stopped>(ctx_)); ctx_->setState(std::make_unique<Stopped>(ctx_));
} }
void Idle::update() noexcept { void Idle::update() noexcept {
// This is intentionally blank. // This is intentionally blank.
} }
@@ -140,7 +139,6 @@ void Playing::timer() noexcept {
timer_connection_ = Glib::signal_timeout().connect_seconds(timer_slot, 1); timer_connection_ = Glib::signal_timeout().connect_seconds(timer_slot, 1);
} }
void Playing::idle() noexcept { void Playing::idle() noexcept {
auto conn = ctx_->connection().get(); auto conn = ctx_->connection().get();
assert(conn != nullptr); assert(conn != nullptr);
@@ -218,7 +216,6 @@ bool Playing::on_io(Glib::IOCondition const&) {
return false; return false;
} }
ctx_->queryMPD();
ctx_->emit(); ctx_->emit();
if (!mpd_send_idle_mask( if (!mpd_send_idle_mask(
@@ -239,25 +236,23 @@ bool Playing::on_io(Glib::IOCondition const&) {
} }
void Playing::stop() { void Playing::stop() {
RUN_NOIDLE_AND_CMD(Playing, RUN_NOIDLE_AND_CMD(
if (timer_connection_.connected()) { Playing, if (timer_connection_.connected()) {
timer_connection_.disconnect(); timer_connection_.disconnect();
mpd_run_stop(ctx_->connection().get()); mpd_run_stop(ctx_->connection().get());
} });
);
ctx_->setState(std::make_unique<Stopped>(ctx_)); ctx_->setState(std::make_unique<Stopped>(ctx_));
} }
void Playing::pause() { void Playing::pause() {
RUN_NOIDLE_AND_CMD(Playing, RUN_NOIDLE_AND_CMD(
if (timer_connection_.connected()) { Playing, if (timer_connection_.connected()) {
timer_connection_.disconnect(); timer_connection_.disconnect();
mpd_run_pause(ctx_->connection().get(), true); mpd_run_pause(ctx_->connection().get(), true);
} });
);
ctx_->setState(std::make_unique<Paused>(ctx_)); ctx_->setState(std::make_unique<Paused>(ctx_));
} }