feat(mpd): add playing-interval option
This commit is contained in:
@@ -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_;
|
||||||
@@ -59,6 +61,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)
|
||||||
|
|||||||
@@ -194,6 +194,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();
|
||||||
|
|||||||
@@ -8,6 +8,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_.count(); }
|
constexpr inline std::size_t Context::interval() const { return mpd_module_->interval_.count(); }
|
||||||
|
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_; }
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ 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) {
|
||||||
@@ -33,6 +34,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_);
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ bool Idle::on_io(Glib::IOCondition const&) {
|
|||||||
|
|
||||||
void Playing::entry() noexcept {
|
void Playing::entry() 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());
|
||||||
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 {
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user