Merge pull request #4334 from theoratkin/master

feat(mpd): add playing-interval option
This commit is contained in:
Alexis Rouillard
2026-07-04 00:11:01 +02:00
committed by GitHub
6 changed files with 19 additions and 3 deletions
+3
View File
@@ -28,6 +28,8 @@ class MPD : public ALabel {
unsigned timeout_; unsigned timeout_;
unsigned playing_interval_;
detail::unique_connection connection_; detail::unique_connection connection_;
detail::unique_status status_; detail::unique_status status_;
@@ -63,6 +65,7 @@ class MPD : public ALabel {
inline bool stopped() const { return connection_ && state_ == MPD_STATE_STOP; } inline bool stopped() const { return connection_ && state_ == MPD_STATE_STOP; }
inline bool playing() const { return connection_ && state_ == MPD_STATE_PLAY; } inline bool playing() const { return connection_ && state_ == MPD_STATE_PLAY; }
inline bool paused() const { return connection_ && state_ == MPD_STATE_PAUSE; } inline bool paused() const { return connection_ && state_ == MPD_STATE_PAUSE; }
inline unsigned playing_interval() const { return playing_interval_; }
}; };
#if !defined(MPD_NOINLINE) #if !defined(MPD_NOINLINE)
+1
View File
@@ -198,6 +198,7 @@ class Context {
bool is_paused() const; bool is_paused() const;
bool is_stopped() const; bool is_stopped() const;
constexpr std::size_t interval() const; constexpr std::size_t interval() const;
unsigned playing_interval() const;
void tryConnect() const; void tryConnect() const;
void checkErrors(mpd_connection*) const; void checkErrors(mpd_connection*) const;
void do_update(); void do_update();
+1
View File
@@ -9,6 +9,7 @@ inline bool Context::is_paused() const { return mpd_module_->paused(); }
inline bool Context::is_stopped() const { return mpd_module_->stopped(); } inline bool Context::is_stopped() const { return mpd_module_->stopped(); }
constexpr inline std::size_t Context::interval() const { return mpd_module_->interval_ / 1s; } constexpr inline std::size_t Context::interval() const { return mpd_module_->interval_ / 1s; }
inline unsigned Context::playing_interval() const { return mpd_module_->playing_interval(); }
inline void Context::tryConnect() const { mpd_module_->tryConnect(); } inline void Context::tryConnect() const { mpd_module_->tryConnect(); }
inline unique_connection& Context::connection() { return mpd_module_->connection_; } inline unique_connection& Context::connection() { return mpd_module_->connection_; }
constexpr inline mpd_state Context::state() const { return mpd_module_->state_; } constexpr inline mpd_state Context::state() const { return mpd_module_->state_; }
+5
View File
@@ -29,6 +29,11 @@ Addressed by *mpd*
default: 5 ++ default: 5 ++
The interval in which the connection to the MPD server is retried The interval in which the connection to the MPD server is retried
*playing-interval*: ++
typeof: integer++
default: 1000 ++
The interval (in milliseconds) in which the playing state is updated.
*timeout*: ++ *timeout*: ++
typeof: integer++ typeof: integer++
default: 30 ++ default: 30 ++
+6
View File
@@ -23,6 +23,8 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
port_(config_["port"].isUInt() ? config["port"].asUInt() : 0), port_(config_["port"].isUInt() ? config["port"].asUInt() : 0),
password_(config_["password"].empty() ? "" : config_["password"].asString()), password_(config_["password"].empty() ? "" : config_["password"].asString()),
timeout_(config_["timeout"].isUInt() ? config_["timeout"].asUInt() * 1'000 : 30'000), timeout_(config_["timeout"].isUInt() ? config_["timeout"].asUInt() * 1'000 : 30'000),
playing_interval_(config_["playing-interval"].isUInt() ? config_["playing-interval"].asUInt()
: 1'000),
connection_(nullptr, &mpd_connection_free), connection_(nullptr, &mpd_connection_free),
status_(nullptr, &mpd_status_free), status_(nullptr, &mpd_status_free),
song_(nullptr, &mpd_song_free), song_(nullptr, &mpd_song_free),
@@ -35,6 +37,10 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
spdlog::warn("{}: `timeout` configuration should be an unsigned int", module_name_); spdlog::warn("{}: `timeout` configuration should be an unsigned int", module_name_);
} }
if (!config_["playing-interval"].isNull() && !config_["playing-interval"].isUInt()) {
spdlog::warn("{}: `playing-interval` configuration should be an unsigned int", module_name_);
}
if (!config["server"].isNull()) { if (!config["server"].isNull()) {
if (!config_["server"].isString()) { if (!config_["server"].isString()) {
spdlog::warn("{}:`server` configuration should be a string", module_name_); spdlog::warn("{}:`server` configuration should be a string", module_name_);
+3 -3
View File
@@ -115,7 +115,7 @@ bool Idle::on_io(Glib::IOCondition const&) {
void Playing::entry() noexcept { void Playing::entry() noexcept {
timer(); timer();
idle(); idle();
spdlog::debug("mpd: Playing: enabled 1 second periodic timer."); spdlog::debug("mpd: Playing: enabled {}ms periodic timer.", ctx_->playing_interval());
} }
void Playing::exit() noexcept { void Playing::exit() noexcept {
@@ -126,7 +126,7 @@ void Playing::exit() noexcept {
if (timer_connection_.connected()) { if (timer_connection_.connected()) {
timer_connection_.disconnect(); timer_connection_.disconnect();
spdlog::debug("mpd: Playing: disabled 1 second periodic timer."); spdlog::debug("mpd: Playing: disabled {}ms periodic timer.", ctx_->playing_interval());
} }
} }
@@ -136,7 +136,7 @@ void Playing::timer() noexcept {
} }
sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Playing::on_timer); sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Playing::on_timer);
timer_connection_ = Glib::signal_timeout().connect_seconds(timer_slot, 1); timer_connection_ = Glib::signal_timeout().connect(timer_slot, ctx_->playing_interval());
} }
void Playing::idle() noexcept { void Playing::idle() noexcept {