fix callbacks

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

View File

@ -3,6 +3,7 @@
#include <fmt/format.h>
#include <fstream>
#include <jack/jack.h>
#include <jack/thread.h>
#include <proc/readproc.h>
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
@ -18,6 +19,7 @@ class JACK : public ALabel {
jack_client_t* client_;
unsigned int xruns_;
std::string state_;
pthread_t jack_thread_;
private:
std::string JACKState();
@ -27,3 +29,7 @@ class JACK : public ALabel {
};
} // 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"
extern "C" {
//extern "C" {
int bufSizeCallback(unsigned int size, void *obj) {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj;
@ -17,12 +17,13 @@ extern "C" {
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;
}
}
//}
waybar::modules::JACK::JACK(const std::string& id, const Json::Value& config)
: ALabel(config, "jack", id, "{load}%", 1) {
@ -57,8 +58,11 @@ std::string waybar::modules::JACK::JACKState() {
return "disconnected";
client_ = jack_client_open("waybar", JackNoStartServer, NULL);
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_);
samplerate_ = jack_get_sample_rate(client_);
jack_set_buffer_size_callback(client_, bufSizeCallback, this);