1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

conky.cc: apply intra-au's batteries patch (#558)

* conky.cc: apply intra-au's batteries patch

* Build fix: explicitly include <vector>.
This commit is contained in:
Brenden Matthews 2018-08-04 15:11:22 -04:00 committed by GitHub
parent a3b7905df6
commit 1d5c5238b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,7 @@
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include "common.h"
#include "config.h"
#include "conky.h"
@ -1989,21 +1990,29 @@ static void update_text() {
int inotify_fd = -1;
#endif
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
bool is_on_battery() { // checks if at least one battery specified in
// "detect_battery" is discharging
char buf[64];
std::string detect_battery_str;
std::string str_buf = str_buf;
detect_battery_str.assign(detect_battery.get(*state));
detect_battery_str += ',';
std::vector<std::string> b_items = split(detect_battery.get(*state), ',');
for (char i : detect_battery_str) { // parse using ',' as delimiter
if ((i != ',') && (i != ' ')) { str_buf += i; }
if ((i == ',') && !str_buf.empty()) {
get_battery_short_status(buf, 64, str_buf.c_str());
for(auto const& value: b_items) {
get_battery_short_status(buf, 64, value.c_str());
if (buf[0] == 'D') { return true; }
str_buf = "";
}
}
return false;
}