#!/bin/bash
set -euo pipefail

export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export DISPLAY=:1 XAUTHORITY=/run/beam-desktop/.Xauthority

# Font DPI and GTK density are set by the shared display supervisor.
xrdb -merge <<'EOF'
Xft.antialias: 1
Xft.hintstyle: hintslight
Xft.rgba: none
XTerm*faceName: Ubuntu Mono
XTerm*faceSize: 12
XTerm*renderFont: true
XTerm*background: #17171c
XTerm*foreground: #ededee
EOF
if [ -f "$HOME/.Xresources" ]; then
  xrdb -merge "$HOME/.Xresources" || echo 'Unable to load ~/.Xresources; continuing' >&2
fi

xsetroot -solid '#17171c'
if [ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ]; then
  for launcher in "$HOME/Desktop/browser.desktop" "$HOME/Desktop/terminal.desktop"; do
    if [ -f "$launcher" ]; then
      gio set -t string "$launcher" metadata::trusted true || echo 'Unable to trust desktop launcher' >&2
    fi
  done
  exec gnome-session --session=ubuntu
fi
exec dbus-run-session -- gnome-session --session=ubuntu
