#include <dirent.h>
#include <getopt.h>
+#include "queue.h"
+
#ifdef LINUX
#include <linux/ethtool.h>
#include <linux/sockios.h>
#define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)"
+struct battery {
+ const char *path;
+ SIMPLEQ_ENTRY(battery) batteries;
+};
+
+SIMPLEQ_HEAD(battery_head, battery) batteries;
+
/* socket file descriptor for general purposes */
static int general_socket;
*
*/
static void cleanup_rbar_dir() {
+#ifdef DZEN
+ return;
+#endif
struct dirent *ent;
DIR *dir;
char pathbuf[strlen(wmii_path)+256+1];
*
*/
static void create_file(const char *name) {
+#ifdef DZEN
+ return;
+#endif
char pathbuf[strlen(wmii_path)+256+1];
int fd;
int flags = O_CREAT | O_WRONLY;
*/
static void setup(void) {
unsigned int i;
- struct stat statbuf;
char pathbuf[512];
+#ifndef DZEN
+ struct stat statbuf;
/* Wait until wmii_path/rbar exists */
for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
+#endif
cleanup_rbar_dir();
if (wlan_interface)
* worn off your battery is.
*
*/
-static char *get_battery_info() {
+static char *get_battery_info(const char *path) {
char buf[1024];
static char part[512];
char *walk, *last;
present_rate = -1;
charging_status_t status = CS_DISCHARGING;
- if ((fd = open(battery_path, O_RDONLY)) == -1)
+ if ((fd = open(path, O_RDONLY)) == -1)
return "No battery found";
memset(part, 0, sizeof(part));
last = walk+1;
(void)close(fd);
- if ((full_design != -1) && (remaining != -1) && (present_rate != -1)) {
+ if ((full_design == 1) || (remaining == -1))
+ return part;
+
+ if (present_rate > 0) {
float remaining_time;
int seconds, hours, minutes;
if (status == CS_CHARGING)
(status == CS_DISCHARGING ? "BAT" : "FULL")),
(((float)remaining / (float)full_design) * 100),
hours, minutes, seconds);
+ } else {
+ (void)snprintf(part, sizeof(part), "%s %.02f%%",
+ (status == CS_CHARGING ? "CHR" :
+ (status == CS_DISCHARGING ? "BAT" : "FULL")),
+ (((float)remaining / (float)full_design) * 100));
}
return part;
}
if (handle == NULL)
die("Could not open configfile\n");
char dest_name[512], dest_value[512], whole_buffer[1026];
- struct stat stbuf;
+
while (!feof(handle)) {
char *ret;
if ((ret = fgets(whole_buffer, 1024, handle)) == whole_buffer) {
eth_interface = strdup(dest_value);
OPT("time_format")
time_format = strdup(dest_value);
- OPT("battery_path")
- battery_path = strdup(dest_value);
- OPT("color")
+ OPT("battery_path") {
+ struct battery *new = calloc(1, sizeof(struct battery));
+ if (new == NULL)
+ die("Could not allocate memory\n");
+ new->path = strdup(dest_value);
+ SIMPLEQ_INSERT_TAIL(&batteries, new, batteries);
+ } OPT("color")
use_colors = true;
OPT("get_ethspeed")
get_ethspeed = true;
interval = atoi(dest_value);
OPT("wmii_path")
{
+#ifndef DZEN
static glob_t globbuf;
+ struct stat stbuf;
if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
die("glob() failed\n");
wmii_path = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : dest_value);
}
if (wmii_path[strlen(wmii_path)-1] != '/')
die("wmii_path is not terminated by /\n");
+#endif
}
OPT("run_watch")
{
}
fclose(handle);
+#ifndef DZEN
if (wmii_path == NULL)
exit(EXIT_FAILURE);
+#endif
return result;
}
{0, 0, 0, 0}
};
+ SIMPLEQ_INIT(&batteries);
+
while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
if ((char)o == 'c')
configfile = optarg;
write_to_statusbar(concat(order[ORDER_WLAN], "wlan"), get_wireless_info(), false);
if (eth_interface)
write_to_statusbar(concat(order[ORDER_ETH], "eth"), get_eth_info(), false);
- if (battery_path)
- write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(), false);
+ struct battery *current_battery;
+ SIMPLEQ_FOREACH(current_battery, &batteries, batteries) {
+ write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(current_battery->path), false);
+ }
/* Get load */
#ifdef LINUX