#!/bin/sh

# Restrict execution to standalone labwc session
case "$XDG_CURRENT_DESKTOP" in
    labwc:wlroots)
        ;;
    *)
        exit 0
        ;;
esac

# Display configuration: https://sr.ht/~emersion/kanshi/
[ -x /usr/bin/kanshi ] && kanshi >/dev/null 2>&1 &

# Set background: https://github.com/swaywm/swaybg
[ -x /usr/bin/swaybg ] && swaybg -m fill -i /usr/share/wallpapers/aptosid-nemesis-wide.png >/dev/null 2>&1 &

# Taskbar: https://github.com/LBCrion/sfwbar
if [ -x /usr/bin/sfwbar ] && [ ! -d ~/.config/sfwbar/ ]; then
    mkdir -p ~/.config/sfwbar/
    cp /usr/share/sfwbar/w10.config ~/.config/sfwbar/sfwbar.config
    # Set agnostic terminal default
    sed -i 's#alacritty#x-terminal-emulator#' ~/.config/sfwbar/sfwbar.config
    # Bump font size
    sed -i 's#font: 12px sans;#font: 14px sans;#' ~/.config/sfwbar/sfwbar.config
fi
[ -x /usr/bin/sfwbar ] && sfwbar >/dev/null 2>&1 &

# Notification daemon: https://github.com/emersion/mako
[ -x /usr/bin/mako ] && mako >/dev/null 2>&1 &

# Only launch swayidle in non live/fll environemnts
if [ ! -e /etc/default/distro ]; then
    # Setup screenlock (gtklock) and turn screen off (wlopm)
    [ -x /usr/bin/swayidle ] && swayidle -w \
            timeout 300 'gtklock -i' \
            timeout 600 'wlopm --off \*' \
            resume 'wlopm --on \*' \
            before-sleep 'gtklock -i' >/dev/null 2>&1 &
fi

# start policykit agent
mate-polkit &

# update XDG user dirs (blueman-applet)
xdg-user-dirs-update

# update environment for xdg-desktop-portals
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
