wip
This commit is contained in:
@@ -2,22 +2,22 @@
|
||||
|
||||
include config.mk
|
||||
|
||||
REQ = util
|
||||
COM = run_command
|
||||
# Objects we actually need
|
||||
OBJ = slstatus.o util.o
|
||||
|
||||
all: slstatus
|
||||
|
||||
$(COM:=.o): config.mk $(REQ:=.h) slstatus.h
|
||||
slstatus.o: slstatus.c slstatus.h arg.h config.h config.mk $(REQ:=.h)
|
||||
slstatus.o: slstatus.c util.h
|
||||
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) slstatus.c
|
||||
|
||||
.c.o:
|
||||
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
util.o: util.c util.h
|
||||
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) util.c
|
||||
|
||||
slstatus: slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||
$(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS)
|
||||
slstatus: $(OBJ)
|
||||
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||
rm -f slstatus $(OBJ)
|
||||
|
||||
install: all
|
||||
mkdir -p "$(DESTDIR)$(PREFIX)/bin"
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#ifndef ARG_H
|
||||
#define ARG_H
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
/* int main(int argc, char *argv[]) */
|
||||
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
|
||||
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
|
||||
int i_, argused_; \
|
||||
if ((*argv)[1] == '-' && !(*argv)[2]) { \
|
||||
argc--, argv++; \
|
||||
break; \
|
||||
} \
|
||||
for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \
|
||||
switch ((*argv)[i_])
|
||||
#define ARGEND if (argused_) { \
|
||||
if ((*argv)[i_ + 1]) { \
|
||||
break; \
|
||||
} else { \
|
||||
argc--, argv++; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define ARGC() ((*argv)[i_])
|
||||
#define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \
|
||||
(*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x))
|
||||
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
|
||||
#define ARGF() ARGF_((char *)0)
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
const unsigned short interval = 1000;
|
||||
static const char unknown_str[] = "n/a";
|
||||
#define MAXLEN 2048
|
||||
|
||||
static const struct arg args[] = {
|
||||
{ run_command, "VOL: %s • ", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{printf \"%d%%\", $2 * 100}'" },
|
||||
{ run_command, "Next Wallpaper: %s • ", "sh /home/andrew/.config/suckless/slstatus/scripts/wallpaper-countdown.sh" },
|
||||
{ run_command, "Age: %s Days • ", "sh -c 'echo $(( ( $(date +%s) - $(stat -c %W /) ) / 86400 ))'" },
|
||||
{ run_command, "Layout: %s • ", "sh /home/andrew/.config/suckless/slstatus/scripts/get_layout.sh" },
|
||||
{ run_command, "Up: %s ", "uptime -p | cut -d ' ' -f2-" },
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
VERSION = 1.0
|
||||
PREFIX = /usr/local
|
||||
|
||||
CPPFLAGS = $(shell pkg-config --cflags x11) -D_DEFAULT_SOURCE -DVERSION=\"${VERSION}\"
|
||||
CPPFLAGS = $(shell pkg-config --cflags x11) -D_DEFAULT_SOURCE
|
||||
LDFLAGS = $(shell pkg-config --libs-only-L x11) -s
|
||||
LDLIBS = $(shell pkg-config --libs-only-l x11)
|
||||
CFLAGS = -std=c17 -pedantic -Wall -Wextra -Wno-unused-parameter -O2 -march=native
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "slstatus.h"
|
||||
#include "util.h"
|
||||
|
||||
const char *
|
||||
run_command(const char *cmd)
|
||||
{
|
||||
char *p;
|
||||
FILE *fp;
|
||||
|
||||
if (!(fp = popen(cmd, "r"))) {
|
||||
warn("popen '%s':", cmd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = fgets(buf, sizeof(buf) - 1, fp);
|
||||
if (pclose(fp) < 0) {
|
||||
warn("pclose '%s':", cmd);
|
||||
return NULL;
|
||||
}
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
if ((p = strrchr(buf, '\n')))
|
||||
p[0] = '\0';
|
||||
|
||||
return buf[0] ? buf : NULL;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
variant=$(setxkbmap -query | awk '/variant:/ { print $2 }')
|
||||
|
||||
if [[ "$variant" == "colemak_dh" ]]; then
|
||||
echo "CLMK"
|
||||
else
|
||||
echo "QWRT"
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@@ -7,8 +6,6 @@
|
||||
#include <time.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "arg.h"
|
||||
#include "slstatus.h"
|
||||
#include "util.h"
|
||||
|
||||
struct arg {
|
||||
@@ -21,7 +18,10 @@ char buf[1024];
|
||||
static volatile sig_atomic_t done;
|
||||
static Display *dpy;
|
||||
|
||||
#include "config.h"
|
||||
const unsigned short interval = 1000;
|
||||
const char unknown_str[] = "n/a";
|
||||
#define MAXLEN 2048
|
||||
|
||||
|
||||
static void
|
||||
terminate(const int signo)
|
||||
@@ -38,40 +38,46 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
|
||||
(a->tv_nsec < b->tv_nsec) * 1E9;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
const char *
|
||||
run_command(const char *cmd)
|
||||
{
|
||||
die("usage: %s [-v] [-s] [-1]", argv0);
|
||||
char *p;
|
||||
FILE *fp;
|
||||
|
||||
if (!(fp = popen(cmd, "r"))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = fgets(buf, sizeof(buf) - 1, fp);
|
||||
if (pclose(fp) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
if ((p = strrchr(buf, '\n')))
|
||||
p[0] = '\0';
|
||||
|
||||
return buf[0] ? buf : NULL;
|
||||
}
|
||||
|
||||
static const
|
||||
struct arg args[] = {
|
||||
{ run_command, " %s till swap • ", "sh /home/andrew/.config/suckless/slstatus/scripts/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 ))'" },
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct sigaction act;
|
||||
struct timespec start, current, diff, intspec, wait;
|
||||
size_t i, len;
|
||||
int sflag, ret;
|
||||
int ret;
|
||||
char status[MAXLEN];
|
||||
const char *res;
|
||||
|
||||
sflag = 0;
|
||||
ARGBEGIN {
|
||||
case 'v':
|
||||
die("slstatus-"VERSION);
|
||||
/* fallthrough */
|
||||
case '1':
|
||||
done = 1;
|
||||
/* FALLTHROUGH */
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND
|
||||
|
||||
if (argc)
|
||||
usage();
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = terminate;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
@@ -79,7 +85,7 @@ main(int argc, char *argv[])
|
||||
act.sa_flags |= SA_RESTART;
|
||||
sigaction(SIGUSR1, &act, NULL);
|
||||
|
||||
if (!sflag && !(dpy = XOpenDisplay(NULL)))
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("XOpenDisplay: Failed to open display");
|
||||
|
||||
do {
|
||||
@@ -98,16 +104,9 @@ main(int argc, char *argv[])
|
||||
len += ret;
|
||||
}
|
||||
|
||||
if (sflag) {
|
||||
puts(status);
|
||||
fflush(stdout);
|
||||
if (ferror(stdout))
|
||||
die("puts:");
|
||||
} else {
|
||||
if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0)
|
||||
die("XStoreName: Allocation failed");
|
||||
XFlush(dpy);
|
||||
}
|
||||
if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0)
|
||||
die("XStoreName: Allocation failed");
|
||||
XFlush(dpy);
|
||||
|
||||
if (!done) {
|
||||
if (clock_gettime(CLOCK_MONOTONIC, ¤t) < 0)
|
||||
@@ -125,11 +124,9 @@ main(int argc, char *argv[])
|
||||
}
|
||||
} while (!done);
|
||||
|
||||
if (!sflag) {
|
||||
XStoreName(dpy, DefaultRootWindow(dpy), NULL);
|
||||
if (XCloseDisplay(dpy) < 0)
|
||||
die("XCloseDisplay: Failed to close display");
|
||||
}
|
||||
XStoreName(dpy, DefaultRootWindow(dpy), NULL);
|
||||
if (XCloseDisplay(dpy) < 0)
|
||||
die("XCloseDisplay: Failed to close display");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
const char *run_command(const char *cmd);
|
||||
@@ -1,5 +1,4 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -23,16 +22,6 @@ verr(const char *fmt, va_list ap)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
verr(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
die(const char *fmt, ...)
|
||||
{
|
||||
@@ -53,10 +42,8 @@ evsnprintf(char *str, size_t size, const char *fmt, va_list ap)
|
||||
ret = vsnprintf(str, size, fmt, ap);
|
||||
|
||||
if (ret < 0) {
|
||||
warn("vsnprintf:");
|
||||
return -1;
|
||||
} else if ((size_t)ret >= size) {
|
||||
warn("vsnprintf: Output truncated");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -110,7 +97,6 @@ fmt_human(uintmax_t num, int base)
|
||||
prefixlen = LEN(prefix_1024);
|
||||
break;
|
||||
default:
|
||||
warn("fmt_human: Invalid base");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -129,7 +115,6 @@ pscanf(const char *path, const char *fmt, ...)
|
||||
int n;
|
||||
|
||||
if (!(fp = fopen(path, "r"))) {
|
||||
warn("fopen '%s':", path);
|
||||
return -1;
|
||||
}
|
||||
va_start(ap, fmt);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdint.h>
|
||||
|
||||
extern char buf[1024];
|
||||
@@ -7,7 +6,6 @@ extern char buf[1024];
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
void warn(const char *, ...);
|
||||
void die(const char *, ...);
|
||||
|
||||
int esnprintf(char *str, size_t size, const char *fmt, ...);
|
||||
|
||||
Reference in New Issue
Block a user