#!/bin/sh

# This file runs when a DM logs you into a graphical session.
# If you use startx/xinit like a Chad, this file will also be sourced.

dbus-update-activation-environment --systemd DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY
xrdb -merge ~/.config/x11/Xresources
#mpv --no-video "$XDG_CONFIG_HOME/windows_xp_startup.ogg"
setbg &			# set the background with the `setbg` script

xrdb ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources & xrdbpid=$!	# Uncomment to use Xresources colors/settings on startup

autostart="picom mpd dunst unclutter dwmblocks update_musicbar pipewire remapd pipewire"
for program in $autostart; do
	pidof -s "$program" || setsid -f "$program"
done >/dev/null 2>&1
sleep 30 && jellyfin-mpv-shim &	# Start jellyfin-mpv-shim after 30 seconds, to ensure that internet is connected (bodged, not relevant though)
xrandr --auto
xrandr --dpi 140		# Set DPI. User may want to use a larger number for larger screens.
sb-bright 40			# set brighntess by default to 40% instead of ~38%
xrandr --listactivemonitors | grep -qE '1920.*x1080.*DP-7$' && ( xrandr --output  DP-7 --scale 1.666666666666 && setbg ) # set scale for 2nd monitor if connected
echo "$DBUS_SESSION_BUS_ADDRESS" > /tmp/dbus_session_bus_address

# Ensure that xrdb has finished running before moving on to start the WM/DE.
[ -n "$xrdbpid" ] && wait "$xrdbpid"
