#!/bin/bash
# -*- mode: shell-script; coding: utf-8 -*-
#
# Copyright 2002-2014 Cendio AB.
# For more information, see http://www.cendio.com
#

[ -h "$0" ] && ORIGIN=`ls -l "$0" | sed "s/.*-> //g"` || ORIGIN="$0"
ORIGIN=`(cd "\`dirname \"$ORIGIN\"\`"; pwd -P 2>/dev/null || pwd)`

source ${ORIGIN}/../libexec/functions

if [ "$#" -eq 0 ]; then
   echo "Usage: $0 <application> [application arguments]"
   exit 1
fi

# Clean up after earlier WMs
xprop -root -remove _NET_NUMBER_OF_DESKTOPS \
      -remove _NET_DESKTOP_NAMES \
      -remove _NET_CURRENT_DESKTOP 2> /dev/null

# Start WM
${ORIGIN}/../libexec/openbox --config-file ${ORIGIN}/../etc/xdg/openbox/rc-single-app.xml &

# Wait for WM to start
if ! wait_for_wm; then
    echo "$0: Timeout waiting for window manager to start"
fi

# Execute application
"$@"

# Stop WM
${ORIGIN}/../libexec/openbox --exit
