#!/bin/sh
# ./ide -- start the LightGUI designer.
# The designer is a single process now: the XFrame-native canvas is
# embedded in the designer window (step 1), the palette is the
# designer's own XFrame-only window (547 widgets, step 5), and the
# standalone palette/layout processes are deleted (step 6). There is
# nothing else to launch or clean up.
#
# Usage: ./ide [--build] [--help]
#   --build      rebuild first (plain `make`: designer + widget demos)
# Requires an X display; under Xvfb:  Xvfb :97 -screen 0 1920x1080x24 &
#                                     DISPLAY=:97 ./ide
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)

BUILD=0
for a in "$@"; do
  case "$a" in
    --build) BUILD=1 ;;
    --help|-h)
      echo "Usage: $0 [--build] [--help]"
      echo "Starts the LightGUI designer (single process). Needs an X display."
      exit 0 ;;
    *) echo "ide: unknown option: $a" >&2; exit 2 ;;
  esac
done

if [ -z "$DISPLAY" ]; then
  echo "ide: no X display (DISPLAY is unset)." >&2
  echo "ide: run under Xvfb, e.g.  Xvfb :97 -screen 0 1920x1080x24 &" >&2
  echo "ide:                       DISPLAY=:97 ./ide" >&2
  exit 1
fi

if [ "$BUILD" = 1 ] || [ ! -x "$ROOT/lightgui" ]; then
  echo "ide: building..."
  make -C "$ROOT" || exit 1
fi

export LIGHTGUI_ICONS="$ROOT/widgets/icons"

(cd "$ROOT" && exec ./lightgui)
