Dotfiles/desktopenvs/niri/scripts/ewwstart.sh

27 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Kill any running Eww instance(s) so we start from a clean slate (e.g. after a
# reload or a monitor change re-runs this script). Give the old daemon a moment to
# fully exit and drop its layer-shell surfaces before opening new ones.
killall eww 2>/dev/null || true
sleep 1
# GTK_THEME is read by the GTK3 widgets embedded in Eww. Export it (the previous
# bare assignment was never exported, so it had no effect).
export GTK_THEME=cyberqueer
# One output per "Scale:" line in `niri msg outputs`.
monitorsum=$(niri msg outputs | grep -c "Scale:" || echo 1)
# Open one bar per output, keyed by the 0-based index.
#
# IMPORTANT: we deliberately do NOT run `eww daemon` separately and then loop
# `eww open`. That RACED: the first `eww open` frequently ran before the freshly
# started daemon was ready, so it spawned its OWN second daemon and drew a second
# bar — two stacked bars on a single monitor. `eww open` already auto-starts the
# daemon and blocks until the window is mapped, so the first call establishes a
# single daemon that every subsequent call reuses.
for ((curmon=0; curmon<monitorsum; curmon++)); do
eww open bar --id "bar${curmon}" --arg "monitor=${curmon}"
done