|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
_pid_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice"
|
|
|
|
mkdir -p "$_pid_dir"
|
|
|
|
PID_FILE="$_pid_dir/ajuice-bar.pid"
|
|
|
|
unset _pid_dir
|
|
|
|
|
|
|
|
if [ -f "$PID_FILE" ]; then
|
|
|
|
while read -r pid; do
|
|
|
|
ppids="$(ps -o pid= --ppid $pid || :)"
|
|
|
|
if [ ! -z "$ppids" ]; then
|
|
|
|
printf "%s\n" "$ppids" | xargs kill -9
|
|
|
|
fi
|
|
|
|
kill -15 $pid || :
|
|
|
|
done < "$PID_FILE"
|
|
|
|
|
|
|
|
rm "$PID_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Give a grace period for all processes to terminate gracefully
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
# PID of this script
|
|
|
|
printf "%s\n" "$$" >> "$PID_FILE"
|
|
|
|
|
|
|
|
acejuice_monitors() {
|
|
|
|
_pipe_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice"
|
|
|
|
mkdir -p "$_pipe_dir"
|
|
|
|
NPIPE_OUT="$_pipe_dir/main.sock"
|
|
|
|
unset _pipe_dir
|
|
|
|
|
|
|
|
if ! mkfifo "$NPIPE_OUT" 2> /dev/null; then
|
|
|
|
printf "fifo '%s' already present\n" "$NPIPE_OUT" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if command -v xrandr > /dev/null; then
|
|
|
|
__monitor_list=""
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
for line in $(xrandr --listmonitors); do
|
|
|
|
case "$line" in
|
|
|
|
" "[0-9]*)
|
|
|
|
__monitor_list="$__monitor_list ${line##* }"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
# Remove space character prefix in the list
|
|
|
|
__monitor_list="${__monitor_list# }"
|
|
|
|
if [ -n "$__monitor_list" ]; then
|
|
|
|
printf ":MON LIST %s\n" "$__monitor_list" > "$NPIPE_OUT"
|
|
|
|
fi
|
|
|
|
unset __monitor_list
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
acejuice_monitors &
|
|
|
|
printf "%s\n" "$!" >> "$PID_FILE"
|
|
|
|
|
|
|
|
audio-pulse --subscribe | acejuice-pulse --socket --newline --icon ascii --icon-mute --no-value &
|
|
|
|
printf "%s\n" "$!" >> "$PID_FILE"
|
|
|
|
|
|
|
|
acejuice-interval --socket &
|
|
|
|
printf "%s\n" "$!" >> "$PID_FILE"
|
|
|
|
|
|
|
|
acejuice | /usr/bin/lemonbar -p &
|
|
|
|
printf "%s\n" "$!" >> "$PID_FILE"
|