fix(replace,wm,autostart): preserve workspaces across slow/3rd-party replace and guard polkit agent startup

This commit is contained in:
Luxferre committed 2026-11-27 09:06:02 +02:00
1 parent 4ec3f59e02
commit c5ce065c33
6 files changed
+759 -53

No files matched your search

+61 -14
View File
@@ -7,6 +7,7 @@ set -u
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
REPLACE_WM=0
NO_AUTOSTART=0
FORCE_AUTOSTART=0
while [ $# -gt 0 ]; do
case "$1" in
@@ -28,6 +29,12 @@ while [ $# -gt 0 ]; do
;;
--no-autostart)
NO_AUTOSTART=1
FORCE_AUTOSTART=0
shift
;;
--autostart)
FORCE_AUTOSTART=1
NO_AUTOSTART=0
shift
;;
*)
@@ -94,7 +101,7 @@ for _envfile in "$ANODE_PREFIX/share/anode/env.sh" "$SCRIPT_DIR/../data/env.sh";
done
unset _envfile
if [ -n "${DISPLAY:-}" ] && command -v anode-apply-display >/dev/null 2>&1; then
if [ "$REPLACE_WM" != "1" ] && [ -n "${DISPLAY:-}" ] && command -v anode-apply-display >/dev/null 2>&1; then
anode-apply-display >/dev/null 2>&1 || true
fi
if [ ! -f "$XDG_CONFIG_HOME/anode/scale.conf" ] && command -v anode-apply-scale >/dev/null 2>&1; then
@@ -116,17 +123,22 @@ if [ "${ANODE_NO_DBUS:-0}" != "1" ]; then
fi
fi
DEFER_THEME_SYNC=0
if [ ! -f "$HOME/.Xresources" ] && command -v anode-apply-theme >/dev/null 2>&1; then
anode-apply-theme Anodized >/dev/null 2>&1 || true
elif [ -f "$HOME/.Xresources" ]; then
if command -v xrdb >/dev/null 2>&1; then
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
if command -v anode-sync-gtk-theme >/dev/null 2>&1; then
ANODE_NO_SIGNAL=1 anode-sync-gtk-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
if command -v anode-sync-dunst-theme >/dev/null 2>&1; then
ANODE_NO_SIGNAL=1 anode-sync-dunst-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
if [ "$REPLACE_WM" = "1" ]; then
DEFER_THEME_SYNC=1
else
if command -v anode-sync-gtk-theme >/dev/null 2>&1; then
ANODE_NO_SIGNAL=1 anode-sync-gtk-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
if command -v anode-sync-dunst-theme >/dev/null 2>&1; then
ANODE_NO_SIGNAL=1 anode-sync-dunst-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
fi
fi
@@ -137,7 +149,10 @@ fi
BG_PIDS=""
spawn_bg() {
if command -v "$1" >/dev/null 2>&1; then
"$@" >/dev/null 2>&1 &
(
unset ANODE_REPLACE_SNAP_FILE ANODE_REPLACE_PREV_WM_WIN || true
exec "$@"
) </dev/null >/dev/null 2>&1 &
BG_PIDS="$BG_PIDS $!"
fi
}
@@ -161,6 +176,19 @@ if [ "${ANODE_TOUCH:-0}" = "1" ]; then
spawn_bg anode-vkbd
fi
if [ "$DEFER_THEME_SYNC" = "1" ]; then
(
unset ANODE_REPLACE_SNAP_FILE ANODE_REPLACE_PREV_WM_WIN || true
if command -v anode-sync-gtk-theme >/dev/null 2>&1; then
anode-sync-gtk-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
if command -v anode-sync-dunst-theme >/dev/null 2>&1; then
anode-sync-dunst-theme "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
) </dev/null >/dev/null 2>&1 &
BG_PIDS="$BG_PIDS $!"
fi
# Seed default user autostart files on first session launch
mkdir -p "$XDG_CONFIG_HOME/anode/autostart.d"
if [ ! -e "$XDG_CONFIG_HOME/anode/autostart" ]; then
@@ -173,12 +201,24 @@ if [ ! -e "$XDG_CONFIG_HOME/anode/autostart" ]; then
unset _tpl
fi
_prev_wm_id="${ANODE_REPLACE_PREV_WM_WIN:-}"
if [ "$REPLACE_WM" = "1" ] && [ -z "$_prev_wm_id" ] && [ -n "${DISPLAY:-}" ] && command -v xprop >/dev/null 2>&1; then
_prev_wm_id="$(xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null | awk '
/window id/ {
for (i = 1; i <= NF; i++) {
if ($i ~ /^0x[0-9a-fA-F]+/) { sub(/,$/, "", $i); print $i; exit }
}
}
')"
fi
# Launch i3-style and XDG session autostart entries once ANODE DWM is ready
if [ "$NO_AUTOSTART" != "1" ] && command -v anode-autostart >/dev/null 2>&1; then
(
unset ANODE_REPLACE_SNAP_FILE ANODE_REPLACE_PREV_WM_WIN || true
_i=0
if command -v xprop >/dev/null 2>&1; then
while [ "$_i" -lt 50 ]; do
while [ "$_i" -lt 80 ]; do
_wm_id="$(xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null | awk '
/window id/ {
for (i = 1; i <= NF; i++) {
@@ -187,10 +227,12 @@ if [ "$NO_AUTOSTART" != "1" ] && command -v anode-autostart >/dev/null 2>&1; the
}
')"
if [ -n "${_wm_id:-}" ]; then
_wm_name="$(xprop -id "$_wm_id" _NET_WM_NAME 2>/dev/null || true)"
case "$_wm_name" in
*ANODE*) break ;;
esac
if [ "$REPLACE_WM" != "1" ] || [ -z "${_prev_wm_id:-}" ] || [ "$_wm_id" != "$_prev_wm_id" ]; then
_wm_name="$(xprop -id "$_wm_id" _NET_WM_NAME 2>/dev/null || true)"
case "$_wm_name" in
*ANODE*) break ;;
esac
fi
fi
_i=$(( _i + 1 ))
sleep 0.1
@@ -198,8 +240,12 @@ if [ "$NO_AUTOSTART" != "1" ] && command -v anode-autostart >/dev/null 2>&1; the
else
sleep 1
fi
anode-autostart start
) >/dev/null 2>&1 &
if [ "$REPLACE_WM" = "1" ] && [ "$FORCE_AUTOSTART" != "1" ]; then
anode-autostart reload
else
anode-autostart start
fi
) </dev/null >/dev/null 2>&1 &
BG_PIDS="$BG_PIDS $!"
fi
@@ -210,6 +256,7 @@ if command -v dwm >/dev/null 2>&1; then
else
dwm || _dwm_rc=$?
fi
unset ANODE_REPLACE_SNAP_FILE ANODE_REPLACE_PREV_WM_WIN || true
if [ "$_dwm_rc" = "75" ]; then
# Replaced by another ICCCM WM: stop old background daemons and hold the
# session open until the replacement WM exits so display managers stay up.