sbar

sbar - a suckless status bar
git clone git://ssnf.xyz/sbar
Log | Files | Refs

commit 4a0e8d9a2614423f52e1e3caf4cd98dd2c9d0ba9
parent 659f66962d7b748bebce703df41de4392ac83197
Author: ssnf <ssnf@ssnf.xyz>
Date:   Tue, 31 May 2022 13:58:23 +0000

Datechk() uses only the standard library now. Fixed wrong argument type in usleep().

Diffstat:
Mconfig.def.h | 3++-
Mlinux.c | 30+++++++-----------------------
Msbar.c | 29+++++++++++++++++++++++++++--
Msbar.h | 33++++++++-------------------------
4 files changed, 44 insertions(+), 51 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,6 +1,7 @@ #define FMT "%s %s %s %s %s", part[0].text, part[1].text, ram.text, date.text, bat.text -double time = 1; +double wtime = 1; +char* datefmt = "%m/%d %I:%M:%S%p"; Partition part[] = { {"/"}, diff --git a/linux.c b/linux.c @@ -1,12 +1,15 @@ -#include "sbar.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> #include <X11/Xlib.h> #include <sys/statfs.h> +#include "sbar.h" + void Batchk(); -void Datechk(); void Partchk(); void Partinit(); void Ramchk(); @@ -28,26 +31,7 @@ Batchk() fclose(f); if (c == bat.c) return; bat.c = c; - snprintf(bat.text, 19, "B(%u%%)", c); -} - -void -Datechk() -{ - FILE* f; - uint h, m, s, d, M; - - if (!(f = fopen("/sys/class/rtc/rtc0/time", "r"))) return; - fscanf(f, "%u:%u:%u", &h, &m, &s); - fclose(f); - if (s == date.s) return; - if (h > 12) h -= 12; - date.s = s; - if (!(f = fopen("/sys/class/rtc/rtc0/date", "r"))) return; - fscanf(f, "%*u-%u-%u", &M, &d); - fclose(f); - ++title.update; - snprintf(date.text, 16, "%u/%u %u:%02u:%02u", M, d, h, m, s); + sprintf(bat.text, "B(%u%%)", c % 100); } void @@ -151,5 +135,5 @@ Titleset() void wait(double t) { - usleep((uchar)t * 1000000); + usleep((int)(t * 1000000)); } diff --git a/sbar.c b/sbar.c @@ -1,11 +1,36 @@ +#include <stdio.h> +#include <time.h> + #include "sbar.h" #include "config.h" +typedef struct { + char text[18]; + uint s; +} Date; + Bat bat; -Ram ram; Date date; +Ram ram; Title title; +static void Datechk(); + +static void +Datechk() +{ + struct tm* tm; + time_t t; + + t = time(NULL); + tm = localtime(&t); + if (tm->tm_sec == date.s) + return; + date.s = tm->tm_sec; + strftime(date.text, 18, datefmt, tm); + ++title.update; +} + int main() { @@ -22,6 +47,6 @@ main() snprintf(title.text, 256, FMT); Titleset(); } - wait(time); + wait(wtime); } } diff --git a/sbar.h b/sbar.h @@ -1,48 +1,32 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdarg.h> - typedef unsigned char uchar; typedef unsigned int uint; typedef unsigned long ulong; -typedef struct Bat Bat; -typedef struct Date Date; -typedef struct Partition Partition; -typedef struct Ram Ram; -typedef struct Title Title; -struct Bat { +typedef struct { char text[8]; ulong c; -}; - -struct Date { - char text[16]; - uint s; -}; +} Bat; -struct Partition { +typedef struct { char* path; char text[32]; ulong free; float size_f; -}; +} Partition; -struct Ram { +typedef struct { char text[24]; ulong free; ulong size; uchar unit; float size_f; -}; +} Ram; -struct Title { +typedef struct { char text[256]; uchar update; -}; +} Title; -void Datechk(); void Batchk(); void Partchk(); void Partinit(); @@ -55,5 +39,4 @@ void wait(double); extern Title title; extern Partition part[]; extern Ram ram; -extern Date date; extern Bat bat;