#!/bin/sh

if [ -z "$XDG_CONFIG_HOME" ]; then
	export XDG_CONFIG_HOME="$HOME/.config"
fi

if [ -z "$XDG_DATA_HOME" ]; then
	export XDG_DATA_HOME="$HOME/.local/share"
fi

# Ensure the existance of openbox config file
OPENBOX_CONF_DIR="$XDG_CONFIG_HOME/openbox"
if [ ! -f "$OPENBOX_CONF_DIR/lxde-rc.xml" ]; then
	mkdir -p "$OPENBOX_CONF_DIR"
	cp /usr/pkg/etc/xdg/openbox/LXDE/rc.xml "$OPENBOX_CONF_DIR/lxde-rc.xml"
fi

# Ensure the existance of the 'Desktop' folder
if [ -e "$XDG_CONFIG_HOME/user-dirs.dirs" ]; then
	. "$XDG_CONFIG_HOME/user-dirs.dirs"
else
	XDG_DESKTOP_DIR="$HOME/Desktop"
fi
mkdir -p "$XDG_DESKTOP_DIR"

# Ensure the existance of the user applications folder
USER_APPS_DIR="$XDG_DATA_HOME/applications"
mkdir -p "$USER_APPS_DIR"

# Clean up after GDM (GDM sets the number of desktops to one)
xprop -root -remove _NET_NUMBER_OF_DESKTOPS -remove _NET_DESKTOP_NAMES -remove _NET_CURRENT_DESKTOP 2> /dev/null

# Enable GTK+2 integration for OpenOffice.org, if available.
export SAL_USE_VCLPLUGIN=gtk

# Launch DBus if needed
if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
	if test -z "$XDG_RUNTIME_DIR" -o ! -S "$XDG_RUNTIME_DIR/bus" -o ! -O "$XDG_RUNTIME_DIR/bus"; then
		eval "$(dbus-launch --sh-syntax --exit-with-session)"
	fi
fi

export XDG_MENU_PREFIX="lxde-"
export XDG_CURRENT_DESKTOP="LXDE"

# Start the LXDE session
exec /usr/pkg/bin/lxsession -s LXDE -e LXDE
