mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +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:
parent
a3b7905df6
commit
1d5c5238b2
29
src/conky.cc
29
src/conky.cc
@ -39,6 +39,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
@ -1989,21 +1990,29 @@ static void update_text() {
|
|||||||
int inotify_fd = -1;
|
int inotify_fd = -1;
|
||||||
#endif
|
#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
|
bool is_on_battery() { // checks if at least one battery specified in
|
||||||
// "detect_battery" is discharging
|
// "detect_battery" is discharging
|
||||||
char buf[64];
|
char buf[64];
|
||||||
std::string detect_battery_str;
|
std::vector<std::string> b_items = split(detect_battery.get(*state), ',');
|
||||||
std::string str_buf = str_buf;
|
|
||||||
detect_battery_str.assign(detect_battery.get(*state));
|
|
||||||
detect_battery_str += ',';
|
|
||||||
|
|
||||||
for (char i : detect_battery_str) { // parse using ',' as delimiter
|
for(auto const& value: b_items) {
|
||||||
if ((i != ',') && (i != ' ')) { str_buf += i; }
|
get_battery_short_status(buf, 64, value.c_str());
|
||||||
if ((i == ',') && !str_buf.empty()) {
|
|
||||||
get_battery_short_status(buf, 64, str_buf.c_str());
|
|
||||||
if (buf[0] == 'D') { return true; }
|
if (buf[0] == 'D') { return true; }
|
||||||
str_buf = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user