Compare commits
4 Commits
icon-chang
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
4dc68f322f | ||
|
59be5d4cd5 | ||
|
764813c0c1 | ||
|
1d22eea138 |
@@ -1,6 +1,9 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../util.h"
|
||||
|
||||
@@ -52,6 +55,7 @@
|
||||
} map[] = {
|
||||
{ "Charging", "+" },
|
||||
{ "Discharging", "-" },
|
||||
{ "Full", "=" },
|
||||
};
|
||||
size_t i;
|
||||
char path[PATH_MAX], state[12];
|
||||
@@ -115,6 +119,79 @@
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *
|
||||
battery_all_in_one(const char *bat)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (esnprintf(path, sizeof(path),
|
||||
"/sys/class/power_supply/%s", bat) < 0) {
|
||||
return " AC";
|
||||
}
|
||||
|
||||
DIR* dir = opendir(path);
|
||||
|
||||
if (dir) {
|
||||
// Battery exists
|
||||
closedir(dir);
|
||||
}
|
||||
else if (ENOENT == errno) {
|
||||
// Battery doesn't exist
|
||||
return " AC";
|
||||
}
|
||||
|
||||
int percentage = atoi(battery_perc(bat));
|
||||
char *bat_icon = "";
|
||||
char *bat_status = "";
|
||||
char *bat_rem = "";
|
||||
|
||||
// Add battery percentage icon
|
||||
if (percentage < 20) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 30) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 40) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 50) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 60) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 70) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 80) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 90) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage < 100) {
|
||||
bat_icon = "";
|
||||
}
|
||||
else if (percentage == 100) {
|
||||
bat_icon = "";
|
||||
}
|
||||
|
||||
if (!strcmp(battery_state(bat), "-")) {
|
||||
bat_status = "";
|
||||
|
||||
const char *temp = battery_remaining(bat);
|
||||
bat_rem = (char*) malloc(sizeof(temp) + 2);
|
||||
sprintf(bat_rem, " (%s)", temp);
|
||||
}
|
||||
else {
|
||||
bat_status = " ";
|
||||
bat_rem = "";
|
||||
}
|
||||
|
||||
return bprintf(" %s%s %i%%%s ", bat_status, bat_icon, percentage, bat_rem);
|
||||
}
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <fcntl.h>
|
||||
#include <machine/apmvar.h>
|
||||
|
7
config.h
7
config.h
@@ -10,7 +10,7 @@ static const char unknown_str[] = "?";
|
||||
#define MAXLEN 2048
|
||||
|
||||
static const char battery_name[] = "BAT0";
|
||||
static const char divider_symbol[] = "";
|
||||
static const char divider_symbol[] = "|";
|
||||
|
||||
/*
|
||||
* function description argument (example)
|
||||
@@ -21,6 +21,7 @@ static const char divider_symbol[] = "";
|
||||
* NULL on OpenBSD/FreeBSD
|
||||
* battery_remaining battery remaining HH:MM battery name (BAT0)
|
||||
* NULL on OpenBSD/FreeBSD
|
||||
* battery_all_in_one all-in-one battery status battery name (BAT0)
|
||||
* check_updates num available updates NULL
|
||||
* cpu_perc cpu usage in percent NULL
|
||||
* cpu_freq cpu frequency in MHz NULL
|
||||
@@ -77,9 +78,7 @@ static const struct arg args[] = {
|
||||
{ divider, " %s ", divider_symbol },
|
||||
{ disk_perc, " %s%%", "/home" },
|
||||
{ divider, " %s ", divider_symbol },
|
||||
{ battery_state, " %s", battery_name }, // TODO: Make the battery icon change with the level and charging status
|
||||
{ battery_perc, "%s%%", battery_name },
|
||||
{ battery_remaining, " (%s)", battery_name },
|
||||
{ battery_all_in_one, "%s", battery_name, },
|
||||
{ divider, " %s ", divider_symbol },
|
||||
{ datetime, " %s", "%a %x" },
|
||||
{ divider, " %s ", divider_symbol },
|
||||
|
@@ -4,6 +4,7 @@
|
||||
const char *battery_perc(const char *);
|
||||
const char *battery_state(const char *);
|
||||
const char *battery_remaining(const char *);
|
||||
const char *battery_all_in_one(const char *bat);
|
||||
|
||||
/* check updates */
|
||||
const char *check_updates(void);
|
||||
|
Reference in New Issue
Block a user