diff --git a/CMakeLists.txt b/CMakeLists.txt index a70379ee4..bb569c19d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -698,7 +698,7 @@ elseif(NetBSD) src/common/networking_linux.c src/common/processing_linux.c src/common/sysctl.c - src/detection/battery/battery_nosupport.c + src/detection/battery/battery_nbsd.c src/detection/bios/bios_nbsd.c src/detection/bluetooth/bluetooth_linux.c src/detection/bluetoothradio/bluetoothradio_linux.c @@ -1486,6 +1486,7 @@ elseif(OpenBSD) elseif(NetBSD) target_link_libraries(libfastfetch PRIVATE "m" + PRIVATE "prop" ) elseif(SunOS) target_link_libraries(libfastfetch diff --git a/src/detection/battery/battery_nbsd.c b/src/detection/battery/battery_nbsd.c new file mode 100644 index 000000000..49f637559 --- /dev/null +++ b/src/detection/battery/battery_nbsd.c @@ -0,0 +1,42 @@ +#include "fastfetch.h" +#include "battery.h" +#include "common/io/io.h" + +#include +#include +#include +#include +#include +#include + +const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) +{ + FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY); + if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY) failed"; + + prop_dictionary_t root = NULL; + if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0) + return "prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed"; + + prop_array_t array = prop_dictionary_get(root, "acpiacad0"); + if (!array) + return "No key `acpibat0` in root dictionary"; + + if (prop_array_count(array) != 2) + return "Unexpect `acpibat0` data"; + + prop_dictionary_t dict = prop_array_get(array, 0); + if (prop_object_type(dict) != PROP_TYPE_DICTIONARY) + return "Unexpect `acpibat0[0]`"; + + //prop_array_t keys = prop_dictionary_all_keys(dict); + //for (uint32_t i = 0; i < prop_array_count(keys); ++i) + // puts(prop_dictionary_keysym_value(prop_array_get(keys, i))); + + int acConnected = false; + prop_dictionary_get_int(dict, "cur-value", &acConnected); + + // TODO: actually use acpibat0 + + return acConnected ? "AC Connected" : "Discharging"; +}