From bba37860d72a4d18d8bd33bf71e21987af67354a Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Mon, 20 May 2024 21:47:17 -0400 Subject: [PATCH] sway: Wrap swaybg in systemd-run ...to work around swaybg crashes --- sway/.config/sway/config | 5 +++++ sway/.local/bin/swaybg-systemd-wrapper | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 sway/.local/bin/swaybg-systemd-wrapper diff --git a/sway/.config/sway/config b/sway/.config/sway/config index fea2c50..8126639 100644 --- a/sway/.config/sway/config +++ b/sway/.config/sway/config @@ -222,6 +222,11 @@ bindsym $mod+r mode "resize" include /etc/sway/config.d/* include /home/peter/.config/sway/local.d/* +# Wrap swaybg in systemd-run to allow swaybg to be automatically restarted +# if it ever crashes. The wrapper script will also automatically purge old +# processes of swaybg as needed. +swaybg_command /home/peter/.local/bin/swaybg-systemd-wrapper + output "*" bg $wallpaper fill # Lockscreen - requires jirutka/swaylock-effects diff --git a/sway/.local/bin/swaybg-systemd-wrapper b/sway/.local/bin/swaybg-systemd-wrapper new file mode 100755 index 0000000..a01483a --- /dev/null +++ b/sway/.local/bin/swaybg-systemd-wrapper @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +args=() +output_arg= + +while [ ! -z "$1" ]; do + if [ "$1" == "-o" ]; then + output_arg="$2" + fi + args+=("$1") + shift +done + +[ -z "$output_arg" ] && exit 1 + +if [ "$output_arg" == '*' ]; then + output_arg="all" +fi + +systemctl --user stop "swaybg-$output_arg" >& /dev/null 2>&1 || true + +systemd-run --user --unit="swaybg-$output_arg" --property=Restart=on-failure --property=RestartSec=1 swaybg "${args[@]}"