# Changes require a restart to take effect.

# UWSM doesn't source /etc/profile.d, so pull the env bootstrap in directly.
[ -r /usr/share/omarchy/default/bash/env-bootstrap ] && . /usr/share/omarchy/default/bash/env-bootstrap

# Omarchy session defaults. Users can override these in ~/.config/uwsm/default
# or, preferably, ~/.config/uwsm/env.d/*.
if [ -f "${OMARCHY_PATH%/}/default/uwsm/default" ]; then
  . "${OMARCHY_PATH%/}/default/uwsm/default"
else
  export TERMINAL=xdg-terminal-exec
  export EDITOR="omarchy-launch-editor --inline"
fi

# Optional user overrides kept for compatibility with older installs.
[ -f "$HOME/.config/uwsm/default" ] && . "$HOME/.config/uwsm/default"

# Raise Mesa and NVIDIA shader cache caps from their 1 GiB defaults to avoid
# shader eviction and recompile stutters across browsers, games, and desktop apps.
export MESA_SHADER_CACHE_MAX_SIZE="${MESA_SHADER_CACHE_MAX_SIZE:-4G}"
export __GL_SHADER_DISK_CACHE_SIZE="${__GL_SHADER_DISK_CACHE_SIZE:-4294967296}"

# aquamarine keeps whatever a display shows rather than set its mode, which is
# the boot splash's picture only for the first compositor after it
# (default/splash/hold); after the login screen it is the console. The first
# login after first-boot setup, in the boot that ran it, keeps the picture setup
# painted the same way, until its first shell takes it (omarchy-provision-owner,
# omarchy-launch-shell).
if [ -e /run/omarchy-splash-hold/adopt ] ||
  { [ -d /run/omarchy-provision-owner ] && [ -e "$HOME/.local/state/omarchy/setup-cover.png" ]; }; then
  export AQ_SPLASH_ADOPT=1
else
  unset AQ_SPLASH_ADOPT
fi

# Put mise shims ahead of system binaries, behind the account dispatchers the
# env bootstrap put first, without spawning mise on every graphical login.
if command -v mise >/dev/null 2>&1; then
  omarchy_mise_data_dir="${MISE_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/mise}"
  omarchy_mise_wrappers_dir="$HOME/.local/state/omarchy/agent-accounts/bin"
  omarchy_mise_shims_dir="${MISE_SHIMS_DIR:-$omarchy_mise_data_dir/shims}"
  omarchy_mise_path="$omarchy_mise_wrappers_dir:$omarchy_mise_shims_dir"
  if [ -n "${PATH:-}" ]; then
    omarchy_remaining_path=$PATH
    while :; do
      omarchy_path_entry=${omarchy_remaining_path%%:*}
      if [ "$omarchy_path_entry" != "$omarchy_mise_wrappers_dir" ] &&
         [ "$omarchy_path_entry" != "$omarchy_mise_shims_dir" ]; then
        omarchy_mise_path="$omarchy_mise_path:$omarchy_path_entry"
      fi
      case "$omarchy_remaining_path" in
        *:*) omarchy_remaining_path=${omarchy_remaining_path#*:} ;;
        *) break ;;
      esac
    done
  fi
  PATH=$omarchy_mise_path
  export PATH
  unset omarchy_mise_data_dir omarchy_mise_wrappers_dir omarchy_mise_shims_dir omarchy_mise_path omarchy_remaining_path omarchy_path_entry
fi
