fix callbacks

pull/1653/head
kennypm 2022-02-12 01:51:11 -05:00
parent f6ee90e5ba
commit c1cda1553a
2 changed files with 13 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include <fstream> #include <fstream>
#include <jack/jack.h> #include <jack/jack.h>
#include <jack/thread.h>
#include <proc/readproc.h> #include <proc/readproc.h>
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
@ -18,6 +19,7 @@ class JACK : public ALabel {
jack_client_t* client_; jack_client_t* client_;
unsigned int xruns_; unsigned int xruns_;
std::string state_; std::string state_;
pthread_t jack_thread_;
private: private:
std::string JACKState(); std::string JACKState();
@ -27,3 +29,7 @@ class JACK : public ALabel {
}; };
} // namespace waybar::modules } // namespace waybar::modules
int bufSizeCallback(unsigned int size, void *obj);
int xrunCallback(void *obj);
void shutdownCallback(void *obj);

View File

@ -1,6 +1,6 @@
#include "modules/jack.hpp" #include "modules/jack.hpp"
extern "C" { //extern "C" {
int bufSizeCallback(unsigned int size, void *obj) { int bufSizeCallback(unsigned int size, void *obj) {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj; waybar::modules::JACK* x = (waybar::modules::JACK*)obj;
@ -17,12 +17,13 @@ extern "C" {
void shutdownCallback(void *obj) { void shutdownCallback(void *obj) {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj; waybar::modules::JACK* x = (waybar::modules::JACK*)obj;
pthread_cancel(x->jack_thread_);
x->client_ = NULL; x->client_ = NULL;
x->state_ = "disconnected"; x->state_ = "disconnected";
x->xruns_ = 0; x->xruns_ = 0;
} }
} //}
waybar::modules::JACK::JACK(const std::string& id, const Json::Value& config) waybar::modules::JACK::JACK(const std::string& id, const Json::Value& config)
: ALabel(config, "jack", id, "{load}%", 1) { : ALabel(config, "jack", id, "{load}%", 1) {
@ -57,8 +58,11 @@ std::string waybar::modules::JACK::JACKState() {
return "disconnected"; return "disconnected";
client_ = jack_client_open("waybar", JackNoStartServer, NULL); client_ = jack_client_open("waybar", JackNoStartServer, NULL);
if (client_) { if (client_) {
jack_thread_ = jack_client_thread_id(client_);
if(config_["realtime"].isBool() && !config_["realtime"].asBool())
jack_drop_real_time_scheduling(jack_thread_);
bufsize_ = jack_get_buffer_size(client_); bufsize_ = jack_get_buffer_size(client_);
samplerate_ = jack_get_sample_rate(client_); samplerate_ = jack_get_sample_rate(client_);
jack_set_buffer_size_callback(client_, bufSizeCallback, this); jack_set_buffer_size_callback(client_, bufSizeCallback, this);