#!/usr/bin/env bash
# 
# SCRIPT NAME:
# .config/X11/xinitrc
#
# AUTHOR:
# Severin Kaderli <severin@kaderli.dev>
#
# DESCRIPTION:
# This is the startup script when you start the x-server.
#
# USAGE:
# This script is executed when you start the x-server.
. "${XDG_CONFIG_HOME}/X11/xsetup"

# Load different i3 configuration depending on nvidia-xrun is used because
# the monitor names are different.
NVIDIA_CHECK="$(xrandr | grep "eDP-1-1 connected")"
if [ -z "${NVIDIA_CHECK}" ]; then
    I3_SCREEN_CONFIG="${XDG_CONFIG_HOME}/i3/config.intel" 
else 
    I3_SCREEN_CONFIG="${XDG_CONFIG_HOME}/i3/config.nvidia"
fi

# Load different i3 configuration depending on if it's a work computer.
LOCAL_I3_CONFIG="${XDG_CONFIG_HOME}/i3/config.private"
if [ "${IS_WORK}" = "1" ]; then
    LOCAL_I3_CONFIG="${XDG_CONFIG_HOME}/i3/config.work" 
fi

cat "${I3_SCREEN_CONFIG}" "${XDG_CONFIG_HOME}/i3/config.base" "${LOCAL_I3_CONFIG}" > "${XDG_CONFIG_HOME}/i3/config"

i3 > "${XDG_LOG_HOME}/i3.log" 2>&1