mirror of
https://github.com/polybar/polybar.git
synced 2024-11-18 13:55:11 -05:00
parent
48da703970
commit
c1162960cc
4 changed files with 42 additions and 40 deletions
|
@ -65,22 +65,14 @@ set(SETTING_BSPWM_STATUS_PREFIX "W"
|
||||||
CACHE STRING "Prefix prepended to the bspwm status line")
|
CACHE STRING "Prefix prepended to the bspwm status line")
|
||||||
set(SETTING_CONNECTION_TEST_IP "8.8.8.8"
|
set(SETTING_CONNECTION_TEST_IP "8.8.8.8"
|
||||||
CACHE STRING "Address to ping when testing network connection")
|
CACHE STRING "Address to ping when testing network connection")
|
||||||
set(SETTING_PATH_ADAPTER_STATUS "/sys/class/power_supply/%adapter%/online"
|
set(SETTING_PATH_ADAPTER "/sys/class/power_supply/%adapter%"
|
||||||
CACHE STRING "Path to file containing the current adapter status")
|
CACHE STRING "Path to adapter")
|
||||||
set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness"
|
set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness"
|
||||||
CACHE STRING "Path to file containing the maximum backlight value")
|
CACHE STRING "Path to file containing the maximum backlight value")
|
||||||
set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/brightness"
|
set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/brightness"
|
||||||
CACHE STRING "Path to file containing the current backlight value")
|
CACHE STRING "Path to file containing the current backlight value")
|
||||||
set(SETTING_PATH_BATTERY_CAPACITY "/sys/class/power_supply/%battery%/charge_now"
|
set(SETTING_PATH_BATTERY "/sys/class/power_supply/%battery%"
|
||||||
CACHE STRING "Path to file containing the current battery capacity")
|
CACHE STRING "Path to battery")
|
||||||
set(SETTING_PATH_BATTERY_CAPACITY_MAX "/sys/class/power_supply/%battery%/charge_full"
|
|
||||||
CACHE STRING "Path to file containing the current battery capacity")
|
|
||||||
set(SETTING_PATH_BATTERY_CAPACITY_PERC "/sys/class/power_supply/%battery%/capacity"
|
|
||||||
CACHE STRING "Path to file containing the current battery capacity in percentage")
|
|
||||||
set(SETTING_PATH_BATTERY_RATE "/sys/class/power_supply/%battery%/current_now"
|
|
||||||
CACHE STRING "Path to file containing the current battery rate")
|
|
||||||
set(SETTING_PATH_BATTERY_VOLTAGE "/sys/class/power_supply/%battery%/voltage_now"
|
|
||||||
CACHE STRING "Path to file containing the current battery voltage")
|
|
||||||
set(SETTING_PATH_CPU_INFO "/proc/stat"
|
set(SETTING_PATH_CPU_INFO "/proc/stat"
|
||||||
CACHE STRING "Path to file containing cpu info")
|
CACHE STRING "Path to file containing cpu info")
|
||||||
set(SETTING_PATH_MEMORY_INFO "/proc/meminfo"
|
set(SETTING_PATH_MEMORY_INFO "/proc/meminfo"
|
||||||
|
|
|
@ -27,8 +27,8 @@ endif()
|
||||||
# }}}
|
# }}}
|
||||||
# Get battery/adapter name {{{
|
# Get battery/adapter name {{{
|
||||||
|
|
||||||
string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY_CAPACITY})
|
string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY})
|
||||||
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER_STATUS})
|
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER})
|
||||||
|
|
||||||
file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*)
|
file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*)
|
||||||
file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*)
|
file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*)
|
||||||
|
@ -49,9 +49,6 @@ endif()
|
||||||
# Get network interfaces {{{
|
# Get network interfaces {{{
|
||||||
|
|
||||||
if(ENABLE_NETWORK)
|
if(ENABLE_NETWORK)
|
||||||
string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY_CAPACITY})
|
|
||||||
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER_STATUS})
|
|
||||||
|
|
||||||
file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*)
|
file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*)
|
||||||
|
|
||||||
foreach(INTERFACE ${IFLIST})
|
foreach(INTERFACE ${IFLIST})
|
||||||
|
|
|
@ -34,14 +34,10 @@
|
||||||
#define BSPWM_SOCKET_PATH "@SETTING_BSPWM_SOCKET_PATH@"
|
#define BSPWM_SOCKET_PATH "@SETTING_BSPWM_SOCKET_PATH@"
|
||||||
#define BSPWM_STATUS_PREFIX "@SETTING_BSPWM_STATUS_PREFIX@"
|
#define BSPWM_STATUS_PREFIX "@SETTING_BSPWM_STATUS_PREFIX@"
|
||||||
#define CONNECTION_TEST_IP "@SETTING_CONNECTION_TEST_IP@"
|
#define CONNECTION_TEST_IP "@SETTING_CONNECTION_TEST_IP@"
|
||||||
#define PATH_ADAPTER_STATUS "@SETTING_PATH_ADAPTER_STATUS@"
|
#define PATH_ADAPTER "@SETTING_PATH_ADAPTER@"
|
||||||
#define PATH_BACKLIGHT_MAX "@SETTING_PATH_BACKLIGHT_MAX@"
|
#define PATH_BACKLIGHT_MAX "@SETTING_PATH_BACKLIGHT_MAX@"
|
||||||
#define PATH_BACKLIGHT_VAL "@SETTING_PATH_BACKLIGHT_VAL@"
|
#define PATH_BACKLIGHT_VAL "@SETTING_PATH_BACKLIGHT_VAL@"
|
||||||
#define PATH_BATTERY_CAPACITY "@SETTING_PATH_BATTERY_CAPACITY@"
|
#define PATH_BATTERY "@SETTING_PATH_BATTERY@"
|
||||||
#define PATH_BATTERY_CAPACITY_MAX "@SETTING_PATH_BATTERY_CAPACITY_MAX@"
|
|
||||||
#define PATH_BATTERY_CAPACITY_PERC "@SETTING_PATH_BATTERY_CAPACITY_PERC@"
|
|
||||||
#define PATH_BATTERY_RATE "@SETTING_PATH_BATTERY_RATE@"
|
|
||||||
#define PATH_BATTERY_VOLTAGE "@SETTING_PATH_BATTERY_VOLTAGE@"
|
|
||||||
#define PATH_CPU_INFO "@SETTING_PATH_CPU_INFO@"
|
#define PATH_CPU_INFO "@SETTING_PATH_CPU_INFO@"
|
||||||
#define PATH_MEMORY_INFO "@SETTING_PATH_MEMORY_INFO@"
|
#define PATH_MEMORY_INFO "@SETTING_PATH_MEMORY_INFO@"
|
||||||
#define PATH_MESSAGING_FIFO "@SETTING_PATH_MESSAGING_FIFO@"
|
#define PATH_MESSAGING_FIFO "@SETTING_PATH_MESSAGING_FIFO@"
|
||||||
|
@ -77,15 +73,10 @@ auto print_build_info = [](bool extended = false) {
|
||||||
<< "BSPWM_STATUS_PREFIX " << BSPWM_STATUS_PREFIX << "\n"
|
<< "BSPWM_STATUS_PREFIX " << BSPWM_STATUS_PREFIX << "\n"
|
||||||
<< "BUILDER_SPACE_TOKEN " << BUILDER_SPACE_TOKEN << "\n"
|
<< "BUILDER_SPACE_TOKEN " << BUILDER_SPACE_TOKEN << "\n"
|
||||||
<< "CONNECTION_TEST_IP " << CONNECTION_TEST_IP << "\n"
|
<< "CONNECTION_TEST_IP " << CONNECTION_TEST_IP << "\n"
|
||||||
<< "PATH_ADAPTER_STATUS " << PATH_ADAPTER_STATUS << "\n"
|
<< "PATH_ADAPTER " << PATH_ADAPTER << "\n"
|
||||||
<< "PATH_BACKLIGHT_MAX " << PATH_BACKLIGHT_MAX << "\n"
|
<< "PATH_BACKLIGHT_MAX " << PATH_BACKLIGHT_MAX << "\n"
|
||||||
<< "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n"
|
<< "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n"
|
||||||
<< "PATH_BATTERY_CAPACITY " << PATH_BATTERY_CAPACITY << "\n"
|
<< "PATH_BATTERY " << PATH_BATTERY << "\n"
|
||||||
<< "PATH_BATTERY_CAPACITY " << PATH_BATTERY_CAPACITY << "\n"
|
|
||||||
<< "PATH_BATTERY_CAPACITY_MAX " << PATH_BATTERY_CAPACITY_MAX << "\n"
|
|
||||||
<< "PATH_BATTERY_CAPACITY_PERC " << PATH_BATTERY_CAPACITY_PERC << "\n"
|
|
||||||
<< "PATH_BATTERY_RATE " << PATH_BATTERY_RATE << "\n"
|
|
||||||
<< "PATH_BATTERY_VOLTAGE " << PATH_BATTERY_VOLTAGE << "\n"
|
|
||||||
<< "PATH_CPU_INFO " << PATH_CPU_INFO << "\n"
|
<< "PATH_CPU_INFO " << PATH_CPU_INFO << "\n"
|
||||||
<< "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n"
|
<< "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n"
|
||||||
<< "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n";
|
<< "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n";
|
||||||
|
|
|
@ -21,22 +21,44 @@ namespace modules {
|
||||||
* Bootstrap module by setting up required components
|
* Bootstrap module by setting up required components
|
||||||
*/
|
*/
|
||||||
void battery_module::setup() {
|
void battery_module::setup() {
|
||||||
// Load configuration values
|
|
||||||
auto battery = m_conf.get<string>(name(), "battery", "BAT0");
|
auto battery = m_conf.get<string>(name(), "battery", "BAT0");
|
||||||
auto adapter = m_conf.get<string>(name(), "adapter", "ADP1");
|
auto adapter = m_conf.get<string>(name(), "adapter", "ADP1");
|
||||||
|
|
||||||
m_valuepath[battery_value::ADAPTER] = string_util::replace(PATH_ADAPTER_STATUS, "%adapter%", adapter);
|
auto path_adapter = string_util::replace(PATH_ADAPTER, "%adapter%", adapter) + "/";
|
||||||
m_valuepath[battery_value::CAPACITY] = string_util::replace(PATH_BATTERY_CAPACITY, "%battery%", battery);
|
auto path_battery = string_util::replace(PATH_BATTERY, "%battery%", battery) + "/";
|
||||||
m_valuepath[battery_value::CAPACITY_MAX] = string_util::replace(PATH_BATTERY_CAPACITY_MAX, "%battery%", battery);
|
|
||||||
m_valuepath[battery_value::CAPACITY_PERC] = string_util::replace(PATH_BATTERY_CAPACITY_PERC, "%battery%", battery);
|
|
||||||
m_valuepath[battery_value::VOLTAGE] = string_util::replace(PATH_BATTERY_VOLTAGE, "%battery%", battery);
|
|
||||||
m_valuepath[battery_value::RATE] = string_util::replace(PATH_BATTERY_RATE, "%battery%", battery);
|
|
||||||
|
|
||||||
for (auto&& file : m_valuepath) {
|
if (!file_util::exists(path_adapter + "online"))
|
||||||
if (!file_util::exists(file.second))
|
throw module_error("The file '" + path_adapter + "online' does not exist");
|
||||||
throw module_error("The file '" + file.second + "' does not exist");
|
m_valuepath[battery_value::ADAPTER] = path_adapter + "online";
|
||||||
|
|
||||||
|
if (!file_util::exists(path_battery + "capacity"))
|
||||||
|
throw module_error("The file '" + path_battery + "capacity' does not exist");
|
||||||
|
m_valuepath[battery_value::CAPACITY_PERC] = path_battery + "capacity";
|
||||||
|
|
||||||
|
if (!file_util::exists(path_battery + "voltage_now"))
|
||||||
|
throw module_error("The file '" + path_battery + "voltage_now' does not exist");
|
||||||
|
m_valuepath[battery_value::VOLTAGE] = path_battery + "voltage_now";
|
||||||
|
|
||||||
|
for (auto&& file : vector<string>{"charge", "energy"}) {
|
||||||
|
if (file_util::exists(path_battery + file + "_now"))
|
||||||
|
m_valuepath[battery_value::CAPACITY] = path_battery + file + "_now";
|
||||||
|
if (file_util::exists(path_battery + file + "_full"))
|
||||||
|
m_valuepath[battery_value::CAPACITY_MAX] = path_battery + file + "_full";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_valuepath[battery_value::CAPACITY].empty())
|
||||||
|
throw module_error("The file '" + path_battery + "[charge|energy]_now' does not exist");
|
||||||
|
if (m_valuepath[battery_value::CAPACITY_MAX].empty())
|
||||||
|
throw module_error("The file '" + path_battery + "[charge|energy]_full' does not exist");
|
||||||
|
|
||||||
|
for (auto&& file : vector<string>{"current", "power"}) {
|
||||||
|
if (file_util::exists(path_battery + file + "_now"))
|
||||||
|
m_valuepath[battery_value::RATE] = path_battery + file + "_now";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_valuepath[battery_value::RATE].empty())
|
||||||
|
throw module_error("The file '" + path_battery + "[current|power]_now' does not exist");
|
||||||
|
|
||||||
m_fullat = m_conf.get<int>(name(), "full-at", 100);
|
m_fullat = m_conf.get<int>(name(), "full-at", 100);
|
||||||
m_interval = chrono::duration<double>{m_conf.get<float>(name(), "poll-interval", 5.0f)};
|
m_interval = chrono::duration<double>{m_conf.get<float>(name(), "poll-interval", 5.0f)};
|
||||||
m_lastpoll = chrono::system_clock::now();
|
m_lastpoll = chrono::system_clock::now();
|
||||||
|
|
Loading…
Reference in a new issue