26be83f893
* 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
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "components/config.hpp"
|
|
#include "modules/meta/inotify_module.hpp"
|
|
#include "settings.hpp"
|
|
|
|
POLYBAR_NS
|
|
|
|
namespace modules {
|
|
class backlight_module : public inotify_module<backlight_module> {
|
|
public:
|
|
struct brightness_handle {
|
|
void filepath(const string& path);
|
|
float read() const;
|
|
|
|
private:
|
|
string m_path;
|
|
};
|
|
|
|
string get_output();
|
|
|
|
public:
|
|
explicit backlight_module(const bar_settings&, string);
|
|
|
|
void idle();
|
|
bool on_event(inotify_event* event);
|
|
bool build(builder* builder, const string& tag) const;
|
|
|
|
static constexpr auto TYPE = "internal/backlight";
|
|
|
|
static constexpr const char* EVENT_INC = "inc";
|
|
static constexpr const char* EVENT_DEC = "dec";
|
|
|
|
protected:
|
|
void action_inc();
|
|
void action_dec();
|
|
|
|
void change_value(int value_mod);
|
|
|
|
private:
|
|
static constexpr auto TAG_LABEL = "<label>";
|
|
static constexpr auto TAG_BAR = "<bar>";
|
|
static constexpr auto TAG_RAMP = "<ramp>";
|
|
|
|
ramp_t m_ramp;
|
|
label_t m_label;
|
|
progressbar_t m_progressbar;
|
|
string m_path_backlight;
|
|
float m_max_brightness;
|
|
bool m_scroll{false};
|
|
|
|
brightness_handle m_val;
|
|
brightness_handle m_max;
|
|
|
|
int m_percentage = 0;
|
|
};
|
|
} // namespace modules
|
|
|
|
POLYBAR_NS_END
|