1 #pragma once
2 
3 #include "modules/meta/event_module.hpp"
4 #include "settings.hpp"
5 
6 POLYBAR_NS
7 
8 // fwd
9 namespace alsa {
10   class mixer;
11   class control;
12 }  // namespace alsa
13 
14 namespace modules {
15   enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE };
16   enum class control { NONE = 0, HEADPHONE };
17 
18   using mixer_t = shared_ptr<alsa::mixer>;
19   using control_t = shared_ptr<alsa::control>;
20 
21   class alsa_module : public event_module<alsa_module> {
22    public:
23     explicit alsa_module(const bar_settings&, string);
24 
25     void teardown();
26     bool has_event();
27     bool update();
28     string get_format() const;
29     string get_output();
30     bool build(builder* builder, const string& tag) const;
31 
32     static constexpr auto TYPE = "internal/alsa";
33 
34     static constexpr auto EVENT_INC = "inc";
35     static constexpr auto EVENT_DEC = "dec";
36     static constexpr auto EVENT_TOGGLE = "toggle";
37 
38    protected:
39     bool input(const string& action, const string& data);
40 
41    private:
42     static constexpr auto FORMAT_VOLUME = "format-volume";
43     static constexpr auto FORMAT_MUTED = "format-muted";
44 
45     static constexpr auto TAG_RAMP_VOLUME = "<ramp-volume>";
46     static constexpr auto TAG_RAMP_HEADPHONES = "<ramp-headphones>";
47     static constexpr auto TAG_BAR_VOLUME = "<bar-volume>";
48     static constexpr auto TAG_LABEL_VOLUME = "<label-volume>";
49     static constexpr auto TAG_LABEL_MUTED = "<label-muted>";
50 
51     progressbar_t m_bar_volume;
52     ramp_t m_ramp_volume;
53     ramp_t m_ramp_headphones;
54     label_t m_label_volume;
55     label_t m_label_muted;
56 
57     map<mixer, mixer_t> m_mixer;
58     map<control, control_t> m_ctrl;
59     int m_headphoneid{0};
60     bool m_mapped{false};
61     int m_interval{5};
62     atomic<bool> m_muted{false};
63     atomic<bool> m_headphones{false};
64     atomic<int> m_volume{0};
65   };
66 }  // namespace modules
67 
68 POLYBAR_NS_END
69