From a9ec184faa42b97a13a1df49e091fa4de0881b33 Mon Sep 17 00:00:00 2001 From: 0scar Date: Sun, 29 Dec 2024 12:59:48 +0100 Subject: Organize source properly --- status.c | 63 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 25 deletions(-) (limited to 'status.c') diff --git a/status.c b/status.c index aadc632..c134d1f 100644 --- a/status.c +++ b/status.c @@ -1,30 +1,33 @@ +#include #include #include +#include #include #include +#include #include -#include #include +#include #include #include -#define __USE_MISC -#include -#include -#include #include #include +/* Required for timercmp */ +#define __USE_MISC #include -#include #include #include +/* Constants */ #define ELEMENT_SEPERATOR " " #define STATUS_STRBUF_SZ 512 #define ELEMENT_STRBUF_SZ 64 +/* Type definitions */ typedef void (*element_function)(char*); +/* Data structures */ struct element { const element_function f; const struct timeval fire_interval; @@ -32,15 +35,6 @@ struct element { char buf[ELEMENT_STRBUF_SZ]; }; -void -date(char* buf) { - time_t now = time(NULL); - struct tm tm; - tm = *localtime(&now); - - strftime(buf, ELEMENT_STRBUF_SZ, "%Y-%m-%d %H:%M", &tm); -} - enum battery_status_charge { bat_unknown, bat_not_charging, @@ -53,7 +47,16 @@ struct battery_status { float charge; }; -char* battery_level_icon[] = { +/* Prototypes */ +void date(char* buf); +struct battery_status get_battery_status(const char* buf); +void get_battery1_status(char* buf); +void get_battery0_status(char* buf); +void get_all_bat_status(char* buf); +void get_net_link_status(char* buf); + +/* Data */ +static char* battery_level_icon[] = { "", /* "\uf579" */ "", /* "\uf57a" */ "", /* "\uf57b" */ @@ -67,6 +70,25 @@ char* battery_level_icon[] = { "", /* "\uf578" */ }; +static struct element statusbar[] = { + /* Add status elements here */ + + {get_net_link_status, {5, 0}, {0}, {0}}, + { get_all_bat_status, {60, 0}, {0}, {0}}, + { date, {2, 500000}, {0}, {0}}, + +}; + +/* Functions */ +void +date(char* buf) { + time_t now = time(NULL); + struct tm tm; + tm = *localtime(&now); + + strftime(buf, ELEMENT_STRBUF_SZ, "%Y-%m-%d %H:%M", &tm); +} + struct battery_status get_battery_status(const char* buf) { const char path_prefix[] = "/sys/class/power_supply/"; @@ -226,15 +248,6 @@ get_net_link_status(char* buf) { } } -static struct element statusbar[] = { - /* Add status elements here */ - - {get_net_link_status, {5, 0}, {0}, {0}}, - { get_all_bat_status, {60, 0}, {0}, {0}}, - { date, {2, 500000}, {0}, {0}}, - -}; - int main(void) { const int num_elems = sizeof(statusbar) / sizeof(statusbar[0]); -- cgit v1.3