Skip to content

Commit

Permalink
more fixes (thanks @sevz17!), new bad modules system, inputregion fix
Browse files Browse the repository at this point in the history
accidentally amended and can't be bothered to unsquash
  • Loading branch information
youbitchoc committed Oct 19, 2022
1 parent 57da6eb commit b7a63c5
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 21 deletions.
10 changes: 10 additions & 0 deletions dsystao/README
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions dsystao/dsystao
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions dsystao/dsystao.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "${clock} | ${interfaces} | ${audio} | ${battery}"
22 changes: 22 additions & 0 deletions dsystao/modules/audio
Original file line number Diff line number Diff line change
@@ -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)<X' "$_update"
fi
printf '%3s^ca()^ca(1,amixer -q set Master 5- && %s)-^ca()^ca(1,amixer -q set Master 5+ && %s)+^ca()\n' "${1%%\%}" "$_update" "$_update"
}

while true; do
sleep "$refresh" & _update="kill -s USR1 $!"
echo "$(loop)"
wait
done
20 changes: 20 additions & 0 deletions dsystao/modules/battery
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

refresh="${refresh:-60}"

while true; do
batt="$(awk '{sum += $1; n++;} END{printf "%d", sum/n;}' /sys/class/power_supply/BAT*/capacity || echo '??')"
if [ "$batt" -lt 100 ]; then
case $(cat /sys/class/power_supply/BAT*/status) in
Full) ;;
Charging)
batt="+${batt}";;
Discharging)
batt="-${batt}";;
*)
batt="?${batt}";;
esac
fi
printf "%3s%%\n" "${batt}"
sleep "$refresh"
done
8 changes: 8 additions & 0 deletions dsystao/modules/clock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

refresh="${refresh:-60}"

while true; do
printf "%16s\n" "$(date '+%H:%M %a %d %b')"
sleep "$((60 - $(date +%S)))"
done
30 changes: 30 additions & 0 deletions dsystao/modules/interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

refresh="${refresh:-4}"

hr() {
awk '{
s="bkMGTPEZY";
while ($1>=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
7 changes: 7 additions & 0 deletions dsystao/modules/testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

while true; do
sleep 1 & sleepid=$!
echo "^ca(1,kill -s USR1 $sleepid)$sleepid^ca()"
wait $sleepid
done
68 changes: 47 additions & 21 deletions dtao.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +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");
strcpy(c->cmd, str);
free(c->cmd);
c->cmd = strdup(str);
if (!c->cmd)
EBARF("malloc: ");
return 0;
}

Expand Down Expand Up @@ -347,6 +348,13 @@ draw_frame(char *text)
clickies[clicky_i].x2 += xdraw;
}

if (expand) {
struct wl_region *inputregion = wl_compositor_create_region(compositor);
wl_region_add(inputregion, xdraw, 0, MAX(maxxpos, 1), height);
wl_surface_set_input_region(wl_surface, inputregion);
wl_region_destroy(inputregion);
}

pixman_image_composite32(PIXMAN_OP_OVER, background, NULL, bar, 0, 0, 0, 0,
xdraw, 0, width, height);
pixman_image_composite32(PIXMAN_OP_OVER, foreground, NULL, bar, 0, 0, 0, 0,
Expand Down Expand Up @@ -402,9 +410,6 @@ struct input_state {
uint32_t button;
};

static void
noop() {}

static void
wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface,
Expand Down Expand Up @@ -453,12 +458,32 @@ 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
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time,
uint32_t axis, wl_fixed_t value)
{}

static void
wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
uint32_t axis_source)
{}

static void
wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis)
{}

static void
wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
uint32_t axis, int32_t discrete)
{}

static void
wl_pointer_frame(void *data, struct wl_pointer *wl_pointer)
{
Expand All @@ -483,10 +508,10 @@ static const struct wl_pointer_listener wl_pointer_listener = {
.leave = wl_pointer_leave,
.motion = wl_pointer_motion,
.button = wl_pointer_button,
.axis = noop,
.axis_source = noop,
.axis_stop = noop,
.axis_discrete = noop,
.axis = wl_pointer_axis,
.axis_source = wl_pointer_axis_source,
.axis_stop = wl_pointer_axis_stop,
.axis_discrete = wl_pointer_axis_discrete,
.frame = wl_pointer_frame,
};

Expand Down Expand Up @@ -545,9 +570,13 @@ handle_global(void *data, struct wl_registry *registry,

}

static void
handle_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name)
{}

static const struct wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = noop,
.global_remove = handle_global_remove,
};

static void
Expand Down Expand Up @@ -747,11 +776,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, &registry_listener, istate);
wl_registry_add_listener(registry, &registry_listener, &istate);
wl_display_roundtrip(display);

if (!compositor || !shm || !layer_shell)
Expand Down Expand Up @@ -797,7 +824,6 @@ main(int argc, char **argv)
wl_compositor_destroy(compositor);
wl_registry_destroy(registry);
wl_display_disconnect(display);
free(istate);

return 0;
}

0 comments on commit b7a63c5

Please sign in to comment.