waybar/include/modules/pulseaudio.hpp

55 lines
1.4 KiB
C++
Raw Permalink Normal View History

2018-08-09 23:55:38 +02:00
#pragma once
#include <fmt/format.h>
#include <pulse/pulseaudio.h>
#include <pulse/volume.h>
2022-04-06 08:37:19 +02:00
2018-08-13 22:33:07 +02:00
#include <algorithm>
#include <array>
2022-04-06 08:37:19 +02:00
2022-11-24 12:28:52 +01:00
#include "ALabel.hpp"
2018-08-09 23:55:38 +02:00
namespace waybar::modules {
2022-11-24 12:28:52 +01:00
class Pulseaudio : public ALabel {
2019-04-18 17:52:00 +02:00
public:
Pulseaudio(const std::string&, const Json::Value&);
2023-03-02 14:57:07 +01:00
virtual ~Pulseaudio();
auto update() -> void override;
2018-08-16 14:29:41 +02:00
2019-04-18 17:52:00 +02:00
private:
static void subscribeCb(pa_context*, pa_subscription_event_type_t, uint32_t, void*);
static void contextStateCb(pa_context*, void*);
static void sinkInfoCb(pa_context*, const pa_sink_info*, int, void*);
2019-05-21 14:53:31 +02:00
static void sourceInfoCb(pa_context*, const pa_source_info* i, int, void* data);
2019-04-18 17:52:00 +02:00
static void serverInfoCb(pa_context*, const pa_server_info*, void*);
static void volumeModifyCb(pa_context*, int, void*);
2018-08-29 23:50:41 +02:00
2023-03-02 14:57:07 +01:00
bool handleScroll(GdkEventScroll* e) override;
2021-07-15 08:52:02 +02:00
const std::vector<std::string> getPulseIcon() const;
2019-04-18 17:52:00 +02:00
pa_threaded_mainloop* mainloop_;
2022-04-06 08:37:19 +02:00
pa_mainloop_api* mainloop_api_;
pa_context* context_;
2019-05-21 14:53:31 +02:00
// SINK
2022-04-06 08:37:19 +02:00
uint32_t sink_idx_{0};
uint16_t volume_;
pa_cvolume pa_volume_;
bool muted_;
2019-05-21 14:53:31 +02:00
std::string port_name_;
std::string form_factor_;
2019-05-21 14:53:31 +02:00
std::string desc_;
std::string monitor_;
std::string current_sink_name_;
2022-04-06 08:37:19 +02:00
bool current_sink_running_;
2019-05-21 14:53:31 +02:00
// SOURCE
2022-04-06 08:37:19 +02:00
uint32_t source_idx_{0};
uint16_t source_volume_;
bool source_muted_;
2019-05-21 14:53:31 +02:00
std::string source_port_name_;
std::string source_desc_;
std::string default_source_name_;
2018-08-16 14:29:41 +02:00
};
2018-08-09 23:55:38 +02:00
} // namespace waybar::modules