wip
This commit is contained in:
@@ -3,16 +3,13 @@
|
|||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
# Objects we actually need
|
# Objects we actually need
|
||||||
OBJ = slstatus.o util.o
|
OBJ = slstatus.o
|
||||||
|
|
||||||
all: slstatus
|
all: slstatus
|
||||||
|
|
||||||
slstatus.o: slstatus.c util.h
|
slstatus.o: slstatus.c
|
||||||
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) slstatus.c
|
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) slstatus.c
|
||||||
|
|
||||||
util.o: util.c util.h
|
|
||||||
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) util.c
|
|
||||||
|
|
||||||
slstatus: $(OBJ)
|
slstatus: $(OBJ)
|
||||||
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS)
|
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS)
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
|
||||||
@@ -5,8 +5,52 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#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 {
|
struct arg {
|
||||||
const char *(*func)(const char *);
|
const char *(*func)(const char *);
|
||||||
@@ -14,15 +58,6 @@ struct arg {
|
|||||||
const char *args;
|
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
|
static void
|
||||||
terminate(const int signo)
|
terminate(const int signo)
|
||||||
{
|
{
|
||||||
@@ -63,7 +98,7 @@ run_command(const char *cmd)
|
|||||||
|
|
||||||
static const
|
static const
|
||||||
struct arg args[] = {
|
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, "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 ))'" },
|
{ run_command, "%s / 731 installed ", "sh -c 'echo $(( ( $(date +%s) - $(stat -c %W /) ) / 86400 ))'" },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
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, ...);
|
|
||||||
+13
@@ -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"
|
||||||
Reference in New Issue
Block a user