From 5c3b468652757b7344c98a0c7c7dc5f5652b4424 Mon Sep 17 00:00:00 2001 From: choc Date: Sun, 2 Oct 2022 21:09:32 +0800 Subject: [PATCH] fixes (thanks @Sevz17!) and new bad modules system --- dsystao/README | 10 ++++++++++ dsystao/dsystao | 23 +++++++++++++++++++++++ dsystao/dsystao.conf | 3 +++ dsystao/modules/audio | 22 ++++++++++++++++++++++ dsystao/modules/battery | 20 ++++++++++++++++++++ dsystao/modules/clock | 8 ++++++++ dsystao/modules/interfaces | 30 ++++++++++++++++++++++++++++++ dsystao/modules/testing | 7 +++++++ dtao.c | 23 +++++++++++------------ 9 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 dsystao/README create mode 100755 dsystao/dsystao create mode 100644 dsystao/dsystao.conf create mode 100755 dsystao/modules/audio create mode 100755 dsystao/modules/battery create mode 100755 dsystao/modules/clock create mode 100755 dsystao/modules/interfaces create mode 100755 dsystao/modules/testing diff --git a/dsystao/README b/dsystao/README new file mode 100644 index 0000000..07d0abc --- /dev/null +++ b/dsystao/README @@ -0,0 +1,10 @@ +copy modules/ into /usr/local/lib/dsystao + +OR just cd here and run `MODULES=modules ./dsystao` + +this is a huge hodgepodge of terribly applied sh knowledge +counselling/contributions greatly appreciated + +what am I doing with my life + +have fun diff --git a/dsystao/dsystao b/dsystao/dsystao new file mode 100755 index 0000000..d6f0ec8 --- /dev/null +++ b/dsystao/dsystao @@ -0,0 +1,23 @@ +#!/bin/sh + +trap "kill -- -$$" INT EXIT + +CONFIG=${CONFIG:-~/.config/dsystao/dsystao.conf} +if ! [ -f "$CONFIG" ]; then + # make the default one + echo '${clock} | ${interfaces} | ${audio} | ${battery}' > "$CONFIG" +fi + +# TODO: find a better home for the module things +MODULES=${MODULES:-/usr/local/lib/dsystao} +[ -d "$MODULES" ] || echo "bad modules directory: '$MODULES'" >&2 + +( + for m in $(sed -e 's/[^$]*${\([^}]*\)}[^$]*/\1 /g' $CONFIG); do + $MODULES/$m | while IFS= read -r l; do echo "$m=$l"; done & #sed -e "s/^/$m=/" & + done +) | while IFS= read -r l; do + export -- "$l" + echo "$l" >&2 + . "$CONFIG" +done #| dtao -fn "monospace:pixelsize=16" -h 32 -z -z -fg "#f0f0e0" -bg "#101010" diff --git a/dsystao/dsystao.conf b/dsystao/dsystao.conf new file mode 100644 index 0000000..ec1c2f2 --- /dev/null +++ b/dsystao/dsystao.conf @@ -0,0 +1,3 @@ +# change as needed +MODULES='.' +FORMAT= diff --git a/dsystao/modules/audio b/dsystao/modules/audio new file mode 100755 index 0000000..4180366 --- /dev/null +++ b/dsystao/modules/audio @@ -0,0 +1,22 @@ +#!/bin/sh + +refresh=${refresh:-10} + +loop() { + set -f + set -- $(amixer sget Master | tail -n 1 | awk 'BEGIN {FS="["; RS="]"; ORS=" "} {print $2}') + set +f + printf '^ca(1,amixer -q set Master ' + if [ "$3" = "on" ]; then + printf 'mute && %s)<(' "$_update" + else + printf 'unmute && %s)=1000 && length(s)>1) + {$1/=1024; s=substr(s,2)} + print int($1+0.5) substr(s,1,1) + }' +} + +rxb=0 +txb=0 +t=0 + +while true; do + _rxb=$rxb + _txb=$txb + rxb=$(($(paste -d+ /sys/class/net/*/statistics/rx_bytes))) + txb=$(($(paste -d+ /sys/class/net/*/statistics/tx_bytes))) + _t=$t + t="$(cut -d' ' -f1 /proc/uptime)" + _rxb="$(echo "($rxb-$_rxb)/($t-$_t)" | bc | hr)" + _txb="$(echo "($txb-$_txb)/($t-$_t)" | bc | hr)" + # shellcheck disable=3057 + printf '%4s/%4s\n' "$_rxb" "$_txb" + sleep "$refresh" +done diff --git a/dsystao/modules/testing b/dsystao/modules/testing new file mode 100755 index 0000000..3a8b4ad --- /dev/null +++ b/dsystao/modules/testing @@ -0,0 +1,7 @@ +#!/bin/sh + +while true; do + sleep 1 & sleepid=$! + echo "^ca(1,kill -s USR1 $sleepid)$sleepid^ca()" + wait $sleepid +done diff --git a/dtao.c b/dtao.c index 09d5072..16a7fa2 100644 --- a/dtao.c +++ b/dtao.c @@ -153,15 +153,17 @@ parse_clickable_area(char *str, struct clickable *c, uint32_t xpos, uint32_t ypo { c->x1 = xpos; c->y1 = 0; - c->btn = 0; while (*str != ',' && *str != '\0') if (isdigit(*str)) c->btn = c->btn*10 + (*str++ - '0'); - if (*str++ == '\0') BARF("bad clickarea cmd"); - c->cmd = malloc(strlen(str) + 1); + if (*str++ == '\0') + BARF("bad clickarea cmd"); - if (!c->cmd) BARF("bad malloc clickarea cmd"); + free(c->cmd); + c->cmd = strdup(str); + if (!c->cmd) + EBARF("malloc: "); strcpy(c->cmd, str); return 0; } @@ -453,10 +455,10 @@ spawn(const char *arg) { if(fork() == 0) { setsid(); execl(shell, shell, "-c", arg, (char *)NULL); - fprintf(stderr, "dtao: execl '%s -c %s'", shell, arg); - perror(" failed"); + EBARF("dtao: execl '%s -c %s' failed: ", shell, arg); } - wait(0); + if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) + EBARF("failed to ignore SIGCHLD"); } static void @@ -747,11 +749,9 @@ main(int argc, char **argv) struct wl_registry *registry = wl_display_get_registry(display); - struct input_state *istate = calloc(1, sizeof(struct input_state)); - if (!istate) - BARF("Failed to create inputstate"); + struct input_state istate = {0}; - wl_registry_add_listener(registry, ®istry_listener, istate); + wl_registry_add_listener(registry, ®istry_listener, &istate); wl_display_roundtrip(display); if (!compositor || !shm || !layer_shell) @@ -797,7 +797,6 @@ main(int argc, char **argv) wl_compositor_destroy(compositor); wl_registry_destroy(registry); wl_display_disconnect(display); - free(istate); return 0; }