#!/bin/sh

userresources=$HOME/.config/X11/Xresources
usermodmap=$HOME/.config/X11/Xmodmap

# merge in defaults and keymaps
if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

if ! pgrep -f mpd > /dev/null
then
  mpd &
fi
picom -b &
# $HOME/.local/bin/garbage/off_touch &

export XDG_SESSION_TYPE=x11
export PATH=$HOME/.local/bin/X11:$PATH
# $HOME/.config/emacs/bin/doom env

session=${1:-exwm}

case $session in
  bspwm    ) exec bspwm ;;
  spectrwm ) exec spectrwm -c ~/.config/spectrwm/spectrwm-nord.conf ;;
  exwm     )
    # In case no elogind
    if [ -z "${XDG_RUNTIME_DIR}" ]
    then
      export XDG_RUNTIME_DIR="/tmp/$(mktemp -d $(id -u ${USER})-runtime-XXXXXX)"
      if [ ! -d "${XDG_RUNTIME_DIR}" ]
      then
        mkdir "${XDG_RUNTIME_DIR}"
        chmod 0700 "${XDG_RUNTIME_DIR}"
      fi
    fi
    exec dbus-run-session emacs -mm --debug-init -l ~/.config/doom/exwm.el > "${XDG_RUNTIME_DIR}/exwm-$(date "+%Y-%m-%d").log" 2>&1 ;;
  *        ) exec "$1" ;;
esac
