vincentbernat.i3wm-configur.../bin/polybar
2024-11-02 21:41:04 +01:00

39 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
export DPI=$(xrdb -query | sed -nE 's/^Xft\.dpi:\s*//p')
export HEIGHT=$((20 * DPI / 96))
export BACKLIGHT=$(cd /sys/class/backlight ; ls | head -1)
export I3SOCK=$(i3 --get-socketpath)
polybar --version
# Example of setup:
# xrandr --setmonitor '*'DisplayPort-3-left 1920/444x1440/334+0+0 DisplayPort-3
# xrandr --setmonitor DisplayPort-3-right 1520/352x1440/334+1920+0 none
MONITORS=$(polybar --list-monitors | sed -nE 's/([^ ]+): .*/\1/p' | tr '\n' ' ')
PRIMARY=$(polybar --list-monitors | grep -F '(primary)' | sed -nE 's/([^ ]+): .*/\1/p')
NMONITORS=$(echo $MONITORS | wc -w)
PRIMARY=${PRIMARY:-${MONITORS%% *}}
awk 'BEGIN { i=0 } ($4 == "/" && $3 !~ /^0:/) {print "mount-"i" = "$5; i++}' /proc/self/mountinfo \
> $XDG_RUNTIME_DIR/i3/polybar-filesystems.conf
case $NMONITORS in
1)
MONITOR=$PRIMARY polybar --reload alone &
systemd-notify --status="Single polybar instance running on $PRIMARY"
;;
*)
MONITOR=$PRIMARY polybar --reload primary &
for MONITOR in ${MONITORS}; do
[ $MONITOR != $PRIMARY ] || continue
MONITOR=$MONITOR polybar --reload secondary &
done
systemd-notify --status="$NMONITORS polybar instances running"
;;
esac
systemd-notify --ready
trap "systemd-notify WATCHDOG=trigger" CHLD
wait