diff options
| author | Mark Nipper <nipsy@bitgnome.net> | 2026-02-01 10:21:43 -0800 |
|---|---|---|
| committer | Mark Nipper <nipsy@bitgnome.net> | 2026-02-01 10:21:43 -0800 |
| commit | cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a (patch) | |
| tree | 969be6caf8c5e462aa85ea1f19bed5cce647df6f /home | |
| parent | cf13236e4bd3a147f5972a8610443728f30c7c49 (diff) | |
| download | nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar.gz nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar.bz2 nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar.lz nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar.xz nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.tar.zst nix-cb39f80ff7959fc5bc5d2ffe5d5f893ddb3fce6a.zip | |
Reswizzle swaybg into generic rotatebg to cover both i3 and sway
Diffstat (limited to 'home')
| -rw-r--r-- | home/nipsy/common/optional/desktops/default.nix | 4 | ||||
| -rw-r--r-- | home/nipsy/common/optional/desktops/i3/default.nix | 2 | ||||
| -rwxr-xr-x | home/nipsy/common/optional/desktops/rotatebg | 53 | ||||
| -rw-r--r-- | home/nipsy/common/optional/desktops/sway/config | 2 | ||||
| -rw-r--r-- | home/nipsy/common/optional/desktops/sway/default.nix | 1 | ||||
| -rwxr-xr-x | home/nipsy/common/optional/desktops/sway/swaybg | 46 |
6 files changed, 59 insertions, 49 deletions
diff --git a/home/nipsy/common/optional/desktops/default.nix b/home/nipsy/common/optional/desktops/default.nix index 4209fc9..9f8596a 100644 --- a/home/nipsy/common/optional/desktops/default.nix +++ b/home/nipsy/common/optional/desktops/default.nix @@ -1,4 +1,8 @@ { + home.file = { + "bin/rotatebg".source = ./rotatebg; + }; + imports = [ ./fonts.nix ./ghostty.nix diff --git a/home/nipsy/common/optional/desktops/i3/default.nix b/home/nipsy/common/optional/desktops/i3/default.nix index 15f90d4..56803f3 100644 --- a/home/nipsy/common/optional/desktops/i3/default.nix +++ b/home/nipsy/common/optional/desktops/i3/default.nix @@ -42,7 +42,7 @@ }; startup = [ { - command = "${pkgs.feh}/bin/feh --no-fehbg --bg-center ~/bg/StarWarsRetro-BrentCheshire.jpg"; + command = "~/bin/rotatebg"; always = true; notification = false; } diff --git a/home/nipsy/common/optional/desktops/rotatebg b/home/nipsy/common/optional/desktops/rotatebg new file mode 100755 index 0000000..d3b4d6e --- /dev/null +++ b/home/nipsy/common/optional/desktops/rotatebg @@ -0,0 +1,53 @@ +#!/usr/bin/env zsh + +# bail out if not running under i3 or sway +if [[ ! -S ${I3SOCK} || ! -S ${SWAYSOCK} ]]; then + echo "no running window manager detected, ${0:t} bailing out" >&2 + exit 0 +fi + +# record our own PID to avoid duplicate invocations +PIDFILE="/dev/shm/${0:t}.pid" + +# check for already running script +if [[ -f ${PIDFILE} ]]; then + for i in $(pidof -x ${0:t}); do + if [[ ${i} -eq $(cat ${PIDFILE}) ]]; then + echo "${0:t} already running!" >&2 + exit 1 + fi + done +fi + +# record current PID +echo ${$} > ${PIDFILE} + +# main loop +while true; do + + # test for continued presence of a running window manager and bail if not found + if [[ ! -S ${I3SOCK} || ! -S ${SWAYSOCK} ]]; then + echo "window manager has stopped running, ${0:t} bailing out" >&2 + exit 0 + fi + + # build array of only type file present underneath my background directory + bg=(~/bg/**/*(.)) + + # if running i3, we need to set the background immediately, at random based on the array length + if [[ -S ${I3SOCK} ]]; then + feh --no-fehbg --bg-max ${bg[$((RANDOM % $#bg + 1))]} + fi + + # wait a bit + sleep 10m + + # if running sway, select and set our new background at random based on the array length + if [[ -S ${SWAYSOCK} ]]; then + swaymsg -s ${SWAYSOCK} output '*' bg ${bg[$((RANDOM % $#bg + 1))]} fit + fi + +done + +# exit with error since we should never get here +exit 1 diff --git a/home/nipsy/common/optional/desktops/sway/config b/home/nipsy/common/optional/desktops/sway/config index 632a7e6..7b4d661 100644 --- a/home/nipsy/common/optional/desktops/sway/config +++ b/home/nipsy/common/optional/desktops/sway/config @@ -45,7 +45,7 @@ output * mode 2560x1440@143.972Hz adaptive_sync on allow_tearing yes bg ~/bg/Sta exec swayidle -w \ timeout 900 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' -exec ~/bin/swaybg +exec ~/bin/rotatebg ### Default options default_border none diff --git a/home/nipsy/common/optional/desktops/sway/default.nix b/home/nipsy/common/optional/desktops/sway/default.nix index 7ef26f4..bc1b6bc 100644 --- a/home/nipsy/common/optional/desktops/sway/default.nix +++ b/home/nipsy/common/optional/desktops/sway/default.nix @@ -1,6 +1,5 @@ { home.file = { ".config/sway/config".source = ./config; - "bin/swaybg".source = ./swaybg; }; } diff --git a/home/nipsy/common/optional/desktops/sway/swaybg b/home/nipsy/common/optional/desktops/sway/swaybg deleted file mode 100755 index 71b3634..0000000 --- a/home/nipsy/common/optional/desktops/sway/swaybg +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env zsh - -# bail out if not running under sway -if [[ ! -S ${SWAYSOCK} ]]; then - echo "no running sway detected, ${0:t} bailing out" >&2 - exit 0 -fi - -# record our own PID to avoid duplicate invocations -PIDFILE="/dev/shm/${0:t}.pid" - -# check for already running script -if [[ -f ${PIDFILE} ]]; then - for i in $(pidof -x ${0:t}); do - if [[ ${i} -eq $(cat ${PIDFILE}) ]]; then - echo "${0:t} already running!" >&2 - exit 1 - fi - done -fi - -# record current PID -echo ${$} > ${PIDFILE} - -# main loop -while true; do - - # sleep initially as sway will load its default background - sleep 10m - - # test for continued presence of sway and bail if not found - if [[ ! -S ${SWAYSOCK} ]]; then - echo "sway has stopped running, ${0:t} bailing out" >&2 - exit 0 - fi - - # build array of only type file present underneath my background directory - bg=(~/bg/**/*(.)) - - # select and set our new background at random based on the array length - swaymsg -s ${SWAYSOCK} output '*' bg ${bg[$((RANDOM % $#bg + 1))]} fit - -done - -# exit with error since we should never get here -exit 1 |
