2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-10-19 12:46:43 +00:00
|
|
|
#include "components/config.hpp"
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "modules/meta/inotify_module.hpp"
|
2023-05-08 17:36:12 +00:00
|
|
|
#include "modules/meta/types.hpp"
|
2020-01-15 15:32:17 +00:00
|
|
|
#include "settings.hpp"
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
namespace modules {
|
2023-10-21 17:12:00 +00:00
|
|
|
/**
|
|
|
|
* Reads value from `/sys/class/backlight/` to get a brightness value for some device.
|
|
|
|
*
|
|
|
|
* There are two file providing brightness values: `brightness` and `actual_brightness`.
|
|
|
|
* The `actual_brightness` file is usually more reliable, but in some cases does not work (provides completely wrong
|
|
|
|
* values, doesn't update) depending on kernel version, graphics driver, and/or graphics card.
|
|
|
|
* Which file is used is controlled by the use-actual-brightness setting.
|
|
|
|
*
|
|
|
|
* The general issue with the `brightness` file seems to be that, while it does receive inotify events, the events it
|
|
|
|
* receives are not for modification of the file and arrive just before the file is updated with a new value. The module
|
|
|
|
* thus reads and displays an outdated brightness value. To compensate for this, the module periodically (controlled by
|
|
|
|
* `poll-interval`) forces an update. By default, this is only enabled if the `backlight` file is used.
|
|
|
|
*/
|
2020-05-15 17:59:08 +00:00
|
|
|
class backlight_module : public inotify_module<backlight_module> {
|
2016-12-21 07:38:44 +00:00
|
|
|
public:
|
|
|
|
struct brightness_handle {
|
|
|
|
void filepath(const string& path);
|
|
|
|
float read() const;
|
2016-10-19 12:46:43 +00:00
|
|
|
|
2016-12-21 07:38:44 +00:00
|
|
|
private:
|
|
|
|
string m_path;
|
|
|
|
};
|
2016-10-19 12:46:43 +00:00
|
|
|
|
2020-01-15 15:32:17 +00:00
|
|
|
string get_output();
|
|
|
|
|
2023-05-01 12:58:52 +00:00
|
|
|
explicit backlight_module(const bar_settings&, string, const config&);
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void idle();
|
2022-03-06 16:44:48 +00:00
|
|
|
bool on_event(const inotify_event& event);
|
2016-11-25 12:55:15 +00:00
|
|
|
bool build(builder* builder, const string& tag) const;
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2023-05-08 17:36:12 +00:00
|
|
|
static constexpr auto TYPE = BACKLIGHT_TYPE;
|
2020-05-15 17:59:08 +00:00
|
|
|
|
2020-05-24 16:35:12 +00:00
|
|
|
static constexpr const char* EVENT_INC = "inc";
|
|
|
|
static constexpr const char* EVENT_DEC = "dec";
|
|
|
|
|
2020-01-15 15:32:17 +00:00
|
|
|
protected:
|
2021-01-04 09:25:52 +00:00
|
|
|
void action_inc();
|
|
|
|
void action_dec();
|
|
|
|
|
|
|
|
void change_value(int value_mod);
|
2020-01-15 15:32:17 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
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;
|
2020-01-15 15:32:17 +00:00
|
|
|
string m_path_backlight;
|
2023-10-21 17:12:00 +00:00
|
|
|
float m_max_brightness{};
|
2020-01-15 15:32:17 +00:00
|
|
|
bool m_scroll{false};
|
2022-04-27 17:53:06 +00:00
|
|
|
int m_scroll_interval{5};
|
2021-02-16 09:02:33 +00:00
|
|
|
bool m_use_actual_brightness{true};
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-10-19 12:46:43 +00:00
|
|
|
brightness_handle m_val;
|
|
|
|
brightness_handle m_max;
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-10-19 12:46:43 +00:00
|
|
|
int m_percentage = 0;
|
2023-10-21 17:12:00 +00:00
|
|
|
|
|
|
|
chrono::duration<double> m_interval{};
|
|
|
|
chrono::steady_clock::time_point m_lastpoll;
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|
2022-03-06 16:44:48 +00:00
|
|
|
} // namespace modules
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|