#!/bin/sh
# hide mouse cursor
unclutter --noevents -b
systemsetting="batocera-settings"
# set the keyboard
settings_lang="`$systemsetting -command load -key system.language`"
# not always true (en_US for us), but it's really better than always english
map_name=$(echo $settings_lang | cut -c 1-2)
setxkbmap "${map_name}"
# disable dpms to prevent screen from blanking
xset -dpms
xset s off
# environment
export HOME=/userdata/system
export LC_ALL="${settings_lang}.UTF-8"
export LANG=${LC_ALL}
# because of xinerama breaking es, enable only one screen at a time
settings_output="`$systemsetting -command load -key global.videooutput`"
batocera-resolution setOutput "${settings_output}" # empty or invalid values defaults to the first valid
# dpi override for nvidia gpus
settings_output="`$systemsetting -command load -key global.dpi`"
[ ! -z "${settings_output}" ] && batocera-resolution setDPI "${settings_output}"
#####################
## CUSTOMISATIONS ###
# to customize your display, you can copy this file to ~/.xinitrc and then modify it
# rotate the screen
# xrandr -o left
# xrandr -o right
# xrandr -o inverted
# change the resolution
xrandr -s 640x480
# change the resolution and the Hz
# xrandr -s 640x480 -r 59.94
### PAL ###
xrandr --newmode "PAL 768x576 (50Hz)" 14.750 768 790 859 944 576 581 586 625 -HSync -VSync interlace
xrandr --addmode DVI-I-1 "PAL 768x576 (50Hz)"
xrandr --output DVI-I-1 --mode "PAL 768x576 (50Hz)"
### NTSC ###
xrandr --newmode "NTSC 640x480 (60Hz)" 12.336 640 662 720 784 480 488 494 525 -HSync -VSync interlace
xrandr --addmode DVI-I-1 "NTSC 640x480 (60Hz)"
# xrandr --output DVI-I-1 --mode "NTSC 640x480 (60Hz)"
### Amiga ###
xrandr --newmode "Amiga 752x576 (50Hz)" 14.25 752 768 840 928 576 579 589 616 -HSync -VSync interlace
xrandr --addmode DVI-I-1 "Amiga 752x576 (50Hz)"
# xrandr --output DVI-I-1 --mode "Amiga 752x576 (50Hz)"
#####################
#####################
# set user desired resolution
# nice workaround for displays which tell X11 to use strange resolutions
settings_output="`$systemsetting -command load -key global.videomode`"
[ ! -z "${settings_output}" ] && batocera-resolution setMode "${settings_output}"
batocera-resolution minTomaxResolution
# allow coredumps for ES
ulimit -H -c unlimited
ulimit -S -c unlimited emulationstation
cd /userdata # es needs a PWD
openbox --config-file /etc/openbox/rc.xml --startup "emulationstation --windowed"