1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-10-27 05:23:39 -04:00
polybar/include/modules/battery.hpp

78 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
2016-05-19 10:41:06 -04:00
#include "common.hpp"
2016-06-14 23:32:35 -04:00
#include "config.hpp"
2016-11-20 17:04:31 -05:00
#include "modules/meta/inotify_module.hpp"
2016-06-14 23:32:35 -04:00
2016-11-19 00:22:44 -05:00
POLYBAR_NS
2016-06-14 23:32:35 -04:00
namespace modules {
enum class battery_state {
NONE = 0,
CHARGING,
DISCHARGING,
FULL,
};
enum class battery_value {
NONE = 0,
ADAPTER,
CAPACITY,
CAPACITY_MAX,
CAPACITY_PERC,
VOLTAGE,
RATE,
};
2016-06-14 23:32:35 -04:00
class battery_module : public inotify_module<battery_module> {
public:
using inotify_module::inotify_module;
2016-11-02 15:22:45 -04:00
void setup();
void start();
void teardown();
void idle();
2016-11-02 15:22:45 -04:00
bool on_event(inotify_event* event);
string get_format() const;
2016-11-25 07:55:15 -05:00
bool build(builder* builder, const string& tag) const;
2016-06-14 23:32:35 -04:00
protected:
2016-11-02 15:22:45 -04:00
int current_percentage();
battery_state current_state();
string current_time();
2016-11-02 15:22:45 -04:00
void subthread();
2016-06-14 23:32:35 -04:00
private:
static constexpr auto FORMAT_CHARGING = "format-charging";
static constexpr auto FORMAT_DISCHARGING = "format-discharging";
static constexpr auto FORMAT_FULL = "format-full";
static constexpr auto TAG_ANIMATION_CHARGING = "<animation-charging>";
static constexpr auto TAG_BAR_CAPACITY = "<bar-capacity>";
static constexpr auto TAG_RAMP_CAPACITY = "<ramp-capacity>";
static constexpr auto TAG_LABEL_CHARGING = "<label-charging>";
static constexpr auto TAG_LABEL_DISCHARGING = "<label-discharging>";
static constexpr auto TAG_LABEL_FULL = "<label-full>";
static const int SKIP_N_UNCHANGED{3};
2016-06-14 23:32:35 -04:00
animation_t m_animation_charging;
ramp_t m_ramp_capacity;
progressbar_t m_bar_capacity;
label_t m_label_charging;
label_t m_label_discharging;
label_t m_label_full;
battery_state m_state{battery_state::DISCHARGING};
map<battery_value, string> m_valuepath;
std::atomic<int> m_percentage{0};
int m_fullat{100};
2016-11-20 17:04:31 -05:00
chrono::duration<double> m_interval;
chrono::system_clock::time_point m_lastpoll;
string m_timeformat;
int m_unchanged{SKIP_N_UNCHANGED};
2016-05-19 10:41:06 -04:00
};
}
2016-06-14 23:32:35 -04:00
2016-11-19 00:22:44 -05:00
POLYBAR_NS_END