2017-09-08 03:27:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <pulse/pulseaudio.h>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "settings.hpp"
|
|
|
|
#include "errors.hpp"
|
|
|
|
|
|
|
|
#include "utils/math.hpp"
|
|
|
|
// fwd
|
|
|
|
struct pa_context;
|
|
|
|
struct pa_threaded_mainloop;
|
|
|
|
struct pa_cvolume;
|
|
|
|
typedef struct pa_context pa_context;
|
|
|
|
typedef struct pa_threaded_mainloop pa_threaded_mainloop;
|
|
|
|
|
|
|
|
POLYBAR_NS
|
2017-10-29 05:50:51 +00:00
|
|
|
class logger;
|
2017-09-08 03:27:21 +00:00
|
|
|
|
|
|
|
DEFINE_ERROR(pulseaudio_error);
|
|
|
|
|
|
|
|
class pulseaudio {
|
|
|
|
// events to add to our queue
|
2018-04-15 00:04:48 +00:00
|
|
|
enum class evtype { NEW = 0, CHANGE, REMOVE, SERVER };
|
2017-09-08 03:27:21 +00:00
|
|
|
using queue = std::queue<evtype>;
|
|
|
|
|
|
|
|
public:
|
2018-04-09 23:13:04 +00:00
|
|
|
explicit pulseaudio(const logger& logger, string&& sink_name, bool m_max_volume);
|
2017-09-08 03:27:21 +00:00
|
|
|
~pulseaudio();
|
|
|
|
|
|
|
|
pulseaudio(const pulseaudio& o) = delete;
|
|
|
|
pulseaudio& operator=(const pulseaudio& o) = delete;
|
|
|
|
|
|
|
|
const string& get_name();
|
|
|
|
|
2017-10-08 03:19:06 +00:00
|
|
|
bool wait();
|
2017-09-08 03:27:21 +00:00
|
|
|
int process_events();
|
|
|
|
|
|
|
|
int get_volume();
|
2019-10-09 00:13:58 +00:00
|
|
|
double get_decibels();
|
2017-09-08 03:27:21 +00:00
|
|
|
void set_volume(float percentage);
|
2017-09-16 21:49:46 +00:00
|
|
|
void inc_volume(int delta_perc);
|
2017-09-08 03:27:21 +00:00
|
|
|
void set_mute(bool mode);
|
|
|
|
void toggle_mute();
|
|
|
|
bool is_muted();
|
|
|
|
|
|
|
|
private:
|
2017-10-29 06:35:26 +00:00
|
|
|
void update_volume(pa_operation *o);
|
2017-09-08 03:27:21 +00:00
|
|
|
static void check_mute_callback(pa_context *context, const pa_sink_info *info, int eol, void *userdata);
|
|
|
|
static void get_sink_volume_callback(pa_context *context, const pa_sink_info *info, int is_last, void *userdata);
|
|
|
|
static void subscribe_callback(pa_context* context, pa_subscription_event_type_t t, uint32_t idx, void* userdata);
|
|
|
|
static void simple_callback(pa_context *context, int success, void *userdata);
|
|
|
|
static void sink_info_callback(pa_context *context, const pa_sink_info *info, int eol, void *userdata);
|
|
|
|
static void context_state_callback(pa_context *context, void *userdata);
|
|
|
|
|
2017-09-16 04:10:25 +00:00
|
|
|
inline void wait_loop(pa_operation *op, pa_threaded_mainloop *loop);
|
|
|
|
|
2017-10-29 05:50:51 +00:00
|
|
|
const logger& m_log;
|
|
|
|
|
2017-09-08 03:27:21 +00:00
|
|
|
// used for temporary callback results
|
2017-09-25 23:42:42 +00:00
|
|
|
int success{0};
|
2017-09-08 03:27:21 +00:00
|
|
|
pa_cvolume cv;
|
2017-09-25 23:42:42 +00:00
|
|
|
bool muted{false};
|
|
|
|
// default sink name
|
2018-04-15 00:04:48 +00:00
|
|
|
static constexpr auto DEFAULT_SINK{"@DEFAULT_SINK@"};
|
2017-09-08 03:27:21 +00:00
|
|
|
|
|
|
|
pa_context* m_context{nullptr};
|
|
|
|
pa_threaded_mainloop* m_mainloop{nullptr};
|
|
|
|
|
|
|
|
queue m_events;
|
|
|
|
|
|
|
|
// specified sink name
|
|
|
|
string spec_s_name;
|
2017-09-25 23:42:42 +00:00
|
|
|
string s_name;
|
2017-09-17 23:46:51 +00:00
|
|
|
uint32_t m_index{0};
|
2018-04-09 23:13:04 +00:00
|
|
|
|
2018-04-15 00:12:02 +00:00
|
|
|
pa_volume_t m_max_volume{PA_VOLUME_UI_MAX};
|
2017-09-08 03:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|