diff --git a/.config/suckless/slstatus/Makefile b/.config/suckless/slstatus/Makefile index d1202c0..1c2f059 100644 --- a/.config/suckless/slstatus/Makefile +++ b/.config/suckless/slstatus/Makefile @@ -3,16 +3,13 @@ include config.mk # Objects we actually need -OBJ = slstatus.o util.o +OBJ = slstatus.o all: slstatus -slstatus.o: slstatus.c util.h +slstatus.o: slstatus.c $(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) slstatus.c -util.o: util.c util.h - $(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) util.c - slstatus: $(OBJ) $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS) diff --git a/.config/suckless/slstatus/scripts/wallpaper-countdown.sh b/.config/suckless/slstatus/scripts/wallpaper-countdown.sh deleted file mode 100755 index 965120c..0000000 --- a/.config/suckless/slstatus/scripts/wallpaper-countdown.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -INTERVAL=600 # 10 minutes - -if [ -f /tmp/last_wallpaper_time ]; then - last=$(cat /tmp/last_wallpaper_time) -else - last=$(date +%s) -fi - -now=$(date +%s) -elapsed=$((now - last)) -remaining=$((INTERVAL - elapsed)) - -if [ "$remaining" -lt 0 ]; then - remaining=0 -fi - -min=$((remaining / 60)) -sec=$((remaining % 60)) - -# Format as mm:ss -printf "%02d:%02d\n" "$min" "$sec" diff --git a/.config/suckless/slstatus/slstatus.c b/.config/suckless/slstatus/slstatus.c index 5446327..921061c 100644 --- a/.config/suckless/slstatus/slstatus.c +++ b/.config/suckless/slstatus/slstatus.c @@ -5,8 +5,52 @@ #include #include #include +#include +#include +#define LEN(x) (sizeof(x) / sizeof((x)[0])) +#define MAXLEN 2048 -#include "util.h" +char buf[1024]; +static volatile sig_atomic_t done; +static Display *dpy; +const unsigned short interval = 1000; +const char unknown_str[] = "n/a"; + +void +die(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } + va_end(ap); + exit(1); +} + +int +esnprintf(char *str, size_t size, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vsnprintf(str, size, fmt, ap); + + if (ret < 0) { + return -1; + } else if ((size_t)ret >= size) { + return -1; + } + va_end(ap); + + return ret; +} struct arg { const char *(*func)(const char *); @@ -14,15 +58,6 @@ struct arg { const char *args; }; -char buf[1024]; -static volatile sig_atomic_t done; -static Display *dpy; - -const unsigned short interval = 1000; -const char unknown_str[] = "n/a"; -#define MAXLEN 2048 - - static void terminate(const int signo) { @@ -63,7 +98,7 @@ run_command(const char *cmd) static const struct arg args[] = { - { run_command, " %s till swap • ", "sh /home/andrew/.config/suckless/slstatus/scripts/wallpaper-countdown.sh" }, + { run_command, " %s till swap • ", "sh /home/andrew/.config/suckless/slstatus/wallpaper-countdown.sh" }, { run_command, "VOL at %s • ", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{printf \"%d%%\", $2 * 100}'" }, { run_command, "%s / 731 installed ", "sh -c 'echo $(( ( $(date +%s) - $(stat -c %W /) ) / 86400 ))'" }, }; diff --git a/.config/suckless/slstatus/util.c b/.config/suckless/slstatus/util.c deleted file mode 100644 index 6915f09..0000000 --- a/.config/suckless/slstatus/util.c +++ /dev/null @@ -1,126 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include -#include -#include -#include -#include - -#include "util.h" - -char *argv0; - -static void -verr(const char *fmt, va_list ap) -{ - vfprintf(stderr, fmt, ap); - - if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { - fputc(' ', stderr); - perror(NULL); - } else { - fputc('\n', stderr); - } -} - -void -die(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - verr(fmt, ap); - va_end(ap); - - exit(1); -} - -static int -evsnprintf(char *str, size_t size, const char *fmt, va_list ap) -{ - int ret; - - ret = vsnprintf(str, size, fmt, ap); - - if (ret < 0) { - return -1; - } else if ((size_t)ret >= size) { - return -1; - } - - return ret; -} - -int -esnprintf(char *str, size_t size, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = evsnprintf(str, size, fmt, ap); - va_end(ap); - - return ret; -} - -const char * -bprintf(const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = evsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - - return (ret < 0) ? NULL : buf; -} - -const char * -fmt_human(uintmax_t num, int base) -{ - double scaled; - size_t i, prefixlen; - const char **prefix; - const char *prefix_1000[] = { "", "k", "M", "G", "T", "P", "E", "Z", - "Y" }; - const char *prefix_1024[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", - "Zi", "Yi" }; - - switch (base) { - case 1000: - prefix = prefix_1000; - prefixlen = LEN(prefix_1000); - break; - case 1024: - prefix = prefix_1024; - prefixlen = LEN(prefix_1024); - break; - default: - return NULL; - } - - scaled = num; - for (i = 0; i < prefixlen && scaled >= base; i++) - scaled /= base; - - return bprintf("%.1f %s", scaled, prefix[i]); -} - -int -pscanf(const char *path, const char *fmt, ...) -{ - FILE *fp; - va_list ap; - int n; - - if (!(fp = fopen(path, "r"))) { - return -1; - } - va_start(ap, fmt); - n = vfscanf(fp, fmt, ap); - va_end(ap); - fclose(fp); - - return (n == EOF) ? -1 : n; -} diff --git a/.config/suckless/slstatus/util.h b/.config/suckless/slstatus/util.h deleted file mode 100644 index acd6d81..0000000 --- a/.config/suckless/slstatus/util.h +++ /dev/null @@ -1,14 +0,0 @@ -#include - -extern char buf[1024]; - -#define LEN(x) (sizeof(x) / sizeof((x)[0])) - -extern char *argv0; - -void die(const char *, ...); - -int esnprintf(char *str, size_t size, const char *fmt, ...); -const char *bprintf(const char *fmt, ...); -const char *fmt_human(uintmax_t num, int base); -int pscanf(const char *path, const char *fmt, ...); diff --git a/.config/suckless/slstatus/wallpaper-countdown.sh b/.config/suckless/slstatus/wallpaper-countdown.sh new file mode 100755 index 0000000..aebe9f5 --- /dev/null +++ b/.config/suckless/slstatus/wallpaper-countdown.sh @@ -0,0 +1,13 @@ +#!/bin/sh +last=$(cat /tmp/last_wallpaper_time) + +now=$(date +%s) +remaining=$((600 - (now - last))) + +[ "$remaining" -lt 0 ] && remaining=0 + +min=$((remaining / 60)) +sec=$((remaining % 60)) + +# Format as mm:ss +printf "%02d:%02d\n" "$min" "$sec"