# Relax screen locking for the passwordless (non-homed) live user, who has no
# password to unlock with. No-op for homed and installed users (no marker).
# Sourced by fll_home after the user exists. Wayland tiling sessions are handled
# elsewhere (hyprland masks hypridle.service, sway/labwc gate their idle exec);
# lxqt/lxde do not auto-lock by default and are not covered here.

if [ -e /run/fll/passwordless ]; then
    case "${FLL_XSESSION}" in
        cinnamon)
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.cinnamon.desktop.lockdown disable-lock-screen true
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.cinnamon.desktop.screensaver lock-enabled false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.cinnamon.desktop.session idle-delay 0
            ;;
        gnome|budgie*)
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.gnome.desktop.lockdown disable-lock-screen true
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.gnome.desktop.screensaver lock-enabled false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.gnome.desktop.session idle-delay 0
            ;;
        mate)
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.mate.screensaver lock-enabled false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- gsettings set \
                org.mate.screensaver idle-activation-enabled false
            ;;
        *plasma*)
            if ! grep -q '^\[Daemon\]' /etc/xdg/kscreenlockerrc 2>/dev/null; then
                cat >> /etc/xdg/kscreenlockerrc <<EOF

[Daemon]
Autolock=false
LockOnResume=false
EOF
            fi
            # No password to unlock KWallet; disable it so apps skip the wizard.
            if ! grep -q '^\[Wallet\]' /etc/xdg/kwalletrc 2>/dev/null; then
                cat >> /etc/xdg/kwalletrc <<EOF
[Wallet]
Enabled=false
EOF
            fi
            ;;
        xfce)
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-session \
                --property /general/LockCommand --type string \
                --set /usr/bin/true
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-session \
                --property /shutdown/ShowSwitchUser --type bool \
                --set false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-screensaver \
                --property /lock/enabled --type bool \
                --set false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-screensaver \
                --property /lock/sleep-activation --type bool \
                --set false
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-power-manager \
                --property /xfce4-power-manager/presentation-mode --type bool \
                --set true
            sudo -u "${FLL_LIVE_USER}" dbus-run-session -- xfconf-query \
                --create --channel xfce4-power-manager \
                --property /xfce4-power-manager/lock-screen-suspend-hibernate \
                --type bool --set false
            ;;
    esac
fi
