diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-12-29 11:59:48 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-12-29 12:01:27 +0000 |
| commit | a9ec184faa42b97a13a1df49e091fa4de0881b33 (patch) | |
| tree | 26f07c06bbc7e9cde367fb20e7062dc694dd03fd /status.c | |
| parent | c8a57e4f46e9a3ba452f396bf562ec797e043bdd (diff) | |
Organize source properly
Diffstat (limited to 'status.c')
| -rw-r--r-- | status.c | 63 |
1 files changed, 38 insertions, 25 deletions
@@ -1,30 +1,33 @@ +#include <arpa/inet.h> #include <errno.h> #include <ifaddrs.h> +#include <linux/if.h> #include <linux/net.h> #include <linux/wireless.h> +#include <netinet/in.h> #include <stdbool.h> -#include <stdint.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> -#define __USE_MISC -#include <arpa/inet.h> -#include <netdb.h> -#include <netinet/in.h> #include <sys/ioctl.h> #include <sys/socket.h> +/* Required for timercmp */ +#define __USE_MISC #include <sys/time.h> -#include <sys/types.h> #include <time.h> #include <unistd.h> +/* 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]); |
