river: Add init reload without program restarts

By passing the 'no-restart' argument as the first parameter of the river init
file, we can prevent program restarting which we do not want to have restarted
every time (e.g. kanshi, wlsunset, waybar, swayidle, etc)

By default these programs will still always be restarted. However, passing the
parameter means that if the program is already running, we do not restart it.
If the program is not yet running it will still be started like normally.

The functionality makes use of the `pidof` program, so on Arch it requires the
'procps-ng' package. This is by default installed as a requirement for the
'base' package group.


Reverted changes from earlier wallpaper switch.
This commit is contained in:
Marty Oehme 2025-02-10 19:21:01 +01:00
parent 1ab2b3a94f
commit c19dbefb2c
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -8,6 +8,23 @@ time_to_lockscreen=300
time_to_screendim=600
time_to_suspend=900
NO_RESTART="$1"
should_start() { # 1=program binary name
# not running, start
if ! pidof "$1"; then
return 0
fi
# only reload, no restarting
if [ "$NO_RESTART" = "no-restart" ]; then
return 1
else
# kill then it can restart
killall "$1"
return 0
fi
}
## OPTIONS
riverctl spawn "dbus-update-activation-environment SEATD_SOCK DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=river"
riverctl focus-follows-cursor normal
@ -31,7 +48,8 @@ riverctl rule-add -app-id "org.pwmt.zathura" csd
## DEBUG
# Reload river configuration
riverctl map normal $mod+Shift F12 spawn "$HOME/.config/river/init"
riverctl map normal $mod+Shift F12 spawn "$HOME/.config/river/init no-restart"
riverctl map normal $mod+Shift+Control F12 spawn "$HOME/.config/river/init"
## HOTKEYS
# close focused view
@ -125,7 +143,7 @@ riverctl map normal $mod+Control L snap right
# Mod+F to toggle fullscreen
riverctl map normal $mod F toggle-fullscreen
# if we are running filtile we also have access to monocle mode
if [ "$layout" = "filtile" ]; then
if [ "$layout" = "filtile" ]; then
riverctl map normal $mod+Shift F spawn "riverctl send-layout-cmd $layout monocle"
fi
@ -267,7 +285,7 @@ done
setxkbmap -option "compose:menu"
# start dynamic display configuration
[ "$(pidof kanshi)" -eq 0 ] || riverctl spawn kanshi
should_start kanshi && riverctl spawn kanshi
# set a nice wallpaper
if exist swaybg; then
@ -288,37 +306,36 @@ elif exist swww; then
fi
# start status bar
killall waybar
riverctl spawn waybar
should_start waybar && riverctl spawn waybar
# start redshift-like sundown warming using current location or standard values
killall wlsunset
loc=$(curl ipinfo.io | grep -e '"loc": ' | sed -e 's/^.*"loc": "\(.*\)",$/\1/')
if [ -n "$loc" ]; then
riverctl spawn "wlsunset -l \"$(echo "$loc" | cut -d, -f1)\" -L \"$(echo "$loc" | cut -d, -f2)\""
else
riverctl spawn "wlsunset -S \"09:00\" -s \"21:00\" -d \"3600\""
if should_start wlsunset; then
loc=$(curl ipinfo.io | grep -e '"loc": ' | sed -e 's/^.*"loc": "\(.*\)",$/\1/')
if [ -n "$loc" ]; then
riverctl spawn "wlsunset -l \"$(echo "$loc" | cut -d, -f1)\" -L \"$(echo "$loc" | cut -d, -f2)\""
else
riverctl spawn "wlsunset -S \"09:00\" -s \"21:00\" -d \"3600\""
fi
unset loc
fi
unset loc
# start screen idle locking/dimming/sleep tool
killall swayidle
riverctl spawn "swayidle \
should_start swayidle && riverctl spawn "swayidle \
timeout ${time_to_suspend} \"[ $(cat /sys/class/power_supply/AC/online) -eq 0 ] && systemctl suspend-then-hibernate\"
timeout ${time_to_screendim} \"wlopm --off '*'\" \
resume \"wlopm --on '*'\" \
timeout ${time_to_lockscreen} \"pidof waylock || lockscreen\" \
after-resume \"wlopm --on '*'\" \
before-sleep \"pidof waylock || lockscreen\" &"
killall clipman
riverctl spawn "wl-paste -t text --watch clipman store"
should_start wl-paste && riverctl spawn "wl-paste -t text --watch clipman store"
# bash ~/.config/bin/gtktheme # setting our gtk variables
# killall polkit-gnome-authentication-agent-1
# /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
# start layouting engine
killall $layout
riverctl spawn "$layout\
--tags all --output all main-ratio 0.65,\
riverctl spawn "$layout --tags all --output all main-ratio 0.65,\
--tags all --output all view-padding 6,\
--tags all --output all outer-padding 0,\
--tags all --output all smart-padding on,\