#!/bin/sh

if [ -f /etc/default/distro ]; then
	. /etc/default/distro
fi

# Detects actual display resolution
# Warning ... works only with a single video card 

xorg=$(ps aux | grep -i xorg | grep -v grep)

if [ -z "$xorg" ]; then
	det_res=1920x1080
else
	xrandr -q > /usr/share/siduction-dynamic-dms/xoutput
	det_res=$(cat /usr/share/siduction-dynamic-dms/xoutput | head -n 1 | awk '{print $8.$9.$10}'| cut -d , -f1 )
	rm -f /usr/share/siduction-dynamic-dms/xoutput
fi

# Searches if exists a wallpaper with desired resolution and
# make a new link for it if true as default wallpaper
# it's needed a hard link for cinnamon
if [ -f "${FLL_WALLPAPER}/contents/images/${det_res}.svg" ];then
	ln -f  ${FLL_WALLPAPER}/contents/images/${det_res}.svg /usr/share/wallpapers/${FLL_DISTRO_CODENAME_SAFE}.svg 
fi

exit 0
