diff --git a/include/modules/jack.hpp b/include/modules/jack.hpp index 2433a43e..71753985 100644 --- a/include/modules/jack.hpp +++ b/include/modules/jack.hpp @@ -15,16 +15,20 @@ class JACK : public ALabel { JACK(const std::string&, const Json::Value&); ~JACK() = default; auto update() -> void; - jack_nframes_t bufsize_; - jack_client_t* client_; - unsigned int xruns_; - std::string state_; - pthread_t jack_thread_; + + int bufSize(unsigned int size); + int xrun(); + void shutdown(); private: std::string JACKState(); + jack_client_t* client_; + jack_nframes_t bufsize_; jack_nframes_t samplerate_; + unsigned int xruns_; + std::string state_; + pthread_t jack_thread_; util::SleeperThread thread_; }; diff --git a/src/modules/jack.cpp b/src/modules/jack.cpp index fd183c7e..45dab230 100644 --- a/src/modules/jack.cpp +++ b/src/modules/jack.cpp @@ -105,23 +105,32 @@ auto waybar::modules::JACK::update() -> void { ALabel::update(); } -int bufSizeCallback(unsigned int size, void *obj) { - waybar::modules::JACK* x = (waybar::modules::JACK*)obj; - x->bufsize_ = size; +int waybar::modules::JACK::bufSize(unsigned int size) { + bufsize_ = size; return size; } -int xrunCallback(void *obj) { - waybar::modules::JACK* x = (waybar::modules::JACK*)obj; - x->xruns_ += 1; - x->state_ = "xrun"; +int waybar::modules::JACK::xrun() { + xruns_ += 1; + state_ = "xrun"; return 0; } -void shutdownCallback(void *obj) { - waybar::modules::JACK* x = (waybar::modules::JACK*)obj; - pthread_cancel(x->jack_thread_); - x->client_ = NULL; - x->state_ = "disconnected"; - x->xruns_ = 0; +void waybar::modules::JACK::shutdown() { + pthread_cancel(jack_thread_); + client_ = NULL; + state_ = "disconnected"; + xruns_ = 0; +} + +int bufSizeCallback(unsigned int size, void *obj) { + return static_cast(obj)->bufSize(size); +} + +int xrunCallback(void *obj) { + return static_cast(obj)->xrun(); +} + +void shutdownCallback(void *obj) { + return static_cast(obj)->shutdown(); }