#!/bin/sh
# nfmc-session — session wrapper for graphical-login (display-manager) launches.
#
# Point an xsessions .desktop Exec= at this script (see nfmc.desktop). It
# guarantees the per-user X session environment is set up before the window
# manager starts, then hands off to nfmc (NeoFlux Media Center).
#
# neoflux itself does NOT source .xprofile or run xrdb (by design — the WM reads
# the *effects* of the session env, e.g. the RESOURCE_MANAGER property, but does
# not own session plumbing). Most display managers run an Xsession wrapper that
# already does this, but it is not universal; doing it here makes neoflux behave
# consistently regardless of how thorough the DM is. Both operations are
# idempotent, so re-doing work the DM already did is harmless.
#
# This mirrors the role startfluxbox plays for Fluxbox.

# Make the user's session environment available (PATH, locale, $EDITOR, ssh/gpg
# agents, autostarted env, etc.). Sourced, not executed, so exported vars stick.
if [ -r "$HOME/.xprofile" ]; then
    . "$HOME/.xprofile"
fi

# Populate the X RESOURCE_MANAGER property so neoflux's Xresources overlay (and
# every other X app that honors Xresources) sees the user's settings.
if command -v xrdb >/dev/null 2>&1; then
    if [ -r "$HOME/.Xresources" ]; then
        xrdb -merge "$HOME/.Xresources"
    elif [ -r "$HOME/.Xdefaults" ]; then
        xrdb -merge "$HOME/.Xdefaults"
    fi
fi

# Hand off as the window manager (no --replace: from a DM there is no prior WM).
exec nfmc "$@"
