# X11 configuration

include = ["desktop.toml"]

# Override the default settings here

# General settings
[general]
# Filesystem size in MiB
filesystem_size = 2048

# Package settings
[packages]
adwaita-icon-theme = {}
dbus = {}
gtk3 = {}
libxcursor = {} # loaded dynamically
#mate-common = {}
mesa-demos-x11 = {}
#firefox = {}
#webkitgtk3 = {} # not compiling
xfce4-full = {}
x11-full = {}
zenity = {}

[[files]]
path = "/usr/lib/init.d/10_dbus"
data = """
requires_weak 10_net.target
bash /usr/bin/start-dbus.sh
"""

[[files]]
path = "/usr/bin/start-dbus.sh"
mode = 0o755
data = """
#!/usr/bin/env bash
export DBUS_DEBUG_OUTPUT=1
#export DBUS_VERBOSE=1
#export G_DBUS_DEBUG=all
mkdir -p /var/lib/dbus
dbus-uuidgen --ensure
mkdir -p /run/dbus
rm -f /run/dbus/pid
dbus-daemon --system
"""

[[files]]
path = "/usr/lib/init.d/10_xenv"
data = """
requires_weak 10_net.target
glib-compile-schemas /usr/share/glib-2.0/schemas/
"""

# Overridden to launch X instead of orblogin
[[files]]
path = "/usr/lib/init.d/20_orbital"
data = """
requires_weak 10_dbus 10_xenv 20_audiod.service
nowait BROWSER=/bin/netsurf-fb VT=3 orbital orbital-x11
"""

[[files]]
path = "/run/user/0"
data = ""
directory = true
mode = 0o700

[[files]]
path = "/home/root/.config/dconf"
data = ""
directory = true

[[files]]
path = "/home/root/Desktop"
data = ""
directory = true


[[files]]
path = "/usr/share/X11/xorg.conf.d"
data = ""
directory = true

[[files]]
path = "/usr/bin/orbital-x11"
mode = 0o755
data = """
#!/usr/bin/env bash

set -ex

# for ice authority and pixbuf
export HOME=/home/root
export XDG_DATA_DIRS=/usr/share
export XDG_RUNTIME_DIR=/run/user/0
export XDG_CONFIG_HOME=/home/root/.config

# Generate config file
WIDTH="$((0x$(grep FRAMEBUFFER_WIDTH /scheme/sys/env | cut -d '=' -f 2)))"
HEIGHT="$((0x$(grep FRAMEBUFFER_HEIGHT /scheme/sys/env | cut -d '=' -f 2)))"
cat > /usr/share/X11/xorg.conf.d/orbital.conf <<EOF
Section "Device"
    Identifier  "Configured Video Device"
    Driver      "dummy"
    VideoRam 256000
EndSection

Section "Monitor"
    Identifier  "Configured Monitor"
    HorizSync 5.0 - 1000.0
    VertRefresh 5.0 - 200.0
    $(cvt "${WIDTH}" "${HEIGHT}")
EndSection

Section "Screen"
    Identifier  "Default Screen"
    Monitor     "Configured Monitor"
    Device      "Configured Video Device"
    DefaultDepth 24
    SubSection "Display"
    Depth 24
    Modes "${WIDTH}x${HEIGHT}"
    EndSubSection
EndSection
EOF

# Launch X11 and session on display 0
export DISPLAY=":0"
X "${DISPLAY}" &
sleep 1
exec dbus-launch --exit-with-x11 xfce4-x11-session
"""

[[files]]
path = "/usr/bin/mate-x11-session"
mode = 0o755
data = """
#!/usr/bin/env bash
set -ex

gdk-pixbuf-query-loaders --update-cache
/usr/libexec/dconf-service &

xterm&
#zenity --info --text="running mate as $(id)!"
#exec marco
exec mate-session
"""


[[files]]
path = "/usr/bin/xfce4-x11-session"
mode = 0o755
data = """
#!/usr/bin/env bash
set -ex

gdk-pixbuf-query-loaders --update-cache
/usr/lib/xfce4/xfconf/xfconfd &
/usr/lib/tumbler-1/tumblerd &
/usr/libexec/upowerd &
xfsettingsd &

xterm&
#zenity --info --text="running xfce4 as $(id)!"
#exec xfwm4
exec xfce4-session
"""


[[files]]
path = "/usr/lib/environment.d/10_x11"
data = """
DISPLAY=:0
"""


[[files]]
path = "/usr/bin/browser"
mode = 0o755
data = """
#!/usr/bin/env bash

set -ex

#export G_MAIN_POLL_DEBUG=1
export G_MESSAGES_DEBUG=all
#export GDK_DEBUG=all
#export GTK_DEBUG=all
export LD_DEBUG=all
#export WEBKIT_DEBUG=all
exec MiniBrowser --dark-mode --ignore-tls-errors "about:blank"
"""

[users.messagebus]
uid = 100
gid = 100
name = "messagebus"
home = "/nonexistent"
shell = "/usr/bin/false"

