#pragma once #ifdef FILESYSTEM_EXPERIMENTAL #include #else #include #endif #include #include #include #include #include #include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" namespace waybar::modules { #ifdef FILESYSTEM_EXPERIMENTAL namespace fs = std::experimental::filesystem; #else namespace fs = std::filesystem; #endif class Battery : public ALabel { public: Battery(const std::string&, const Json::Value&); ~Battery(); auto update() -> void; private: static inline const fs::path data_dir_ = "/sys/class/power_supply/"; void refreshBatteries(); void worker(); const std::string getAdapterStatus(uint8_t capacity) const; const std::tuple getInfos(); const std::string formatTimeRemaining(float hoursRemaining); int global_watch; std::map batteries_; fs::path adapter_; int battery_watch_fd_; int global_watch_fd_; std::mutex battery_list_mutex_; std::string old_status_; util::SleeperThread thread_; util::SleeperThread thread_battery_update_; util::SleeperThread thread_timer_; }; } // namespace waybar::modules