1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00
polybar/include/modules/pulseaudio.hpp
Patrick Ziegler 26be83f893
module: Implement action router (#2336)
* module: Implement proof of concept action router

Action implementation inside module becomes much cleaner because each
module just registers action names together with a callback (pointer to
member function) and the action router does the rest.

* Make input function final

This forces all modules to use the action router

* modules: Catch exceptions in action handlers

* Use action router for all modules

* Use action_ prefix for function names

The mpd module's 'stop' action overwrote the base module's stop function
which caused difficult to debug behavior.

To prevent this in the future we now prefix each function that is
responsible for an action with 'action_'

* Cleanup

* actions: Throw exception when re-registering action

Action names are unique inside modules. Unfortunately there is no way to
ensure this statically, the next best thing is to crash the module and
let the user know that this is a bug.

* Formatting

* actions: Ignore data for actions without data

This is the same behavior as before.

* action_router: Write tests
2021-01-04 10:25:52 +01:00

59 lines
1.4 KiB
C++

#pragma once
#include "modules/meta/event_module.hpp"
#include "settings.hpp"
POLYBAR_NS
// fwd
class pulseaudio;
namespace modules {
using pulseaudio_t = shared_ptr<pulseaudio>;
class pulseaudio_module : public event_module<pulseaudio_module> {
public:
explicit pulseaudio_module(const bar_settings&, string);
void teardown();
bool has_event();
bool update();
string get_format() const;
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/pulseaudio";
static constexpr auto EVENT_INC = "inc";
static constexpr auto EVENT_DEC = "dec";
static constexpr auto EVENT_TOGGLE = "toggle";
protected:
void action_inc();
void action_dec();
void action_toggle();
private:
static constexpr auto FORMAT_VOLUME = "format-volume";
static constexpr auto FORMAT_MUTED = "format-muted";
static constexpr auto TAG_RAMP_VOLUME = "<ramp-volume>";
static constexpr auto TAG_BAR_VOLUME = "<bar-volume>";
static constexpr auto TAG_LABEL_VOLUME = "<label-volume>";
static constexpr auto TAG_LABEL_MUTED = "<label-muted>";
progressbar_t m_bar_volume;
ramp_t m_ramp_volume;
label_t m_label_volume;
label_t m_label_muted;
pulseaudio_t m_pulseaudio;
int m_interval{5};
atomic<bool> m_muted{false};
atomic<int> m_volume{0};
atomic<double> m_decibels{0};
};
} // namespace modules
POLYBAR_NS_END