I have a 3 monitor display layout as:
  • LEFT - 2K Portrait for vertical games
  • TOP - 4K for horizontal games
  • BOTTOM - 4K for computer emulation

From time to time, after a re-boot or from a suspended display (Fedora 31 / Wayland), I notice that the screen0, screen1, screen2 assignments can get re-ordered. And so from time to time, I have to edit those ini files to reflect my preferred 'screen screenN'.
I crafted this wrapper script in $HOME/bin/mame.sh to help correct moving screen assignments:


while read Screen X1 Position X2 ; do
        declare -i n=$( echo $Screen | tr -d ' :' )
        IFS='+' read -r geom x y <<< $Position
        [ $x -eq 0 ] && LEFT="screen$n"
        [ $y -eq 0 ] && TOP="screen$n"
        [ $y -eq 1600 ] && BOTTOM="screen$n"
done < <(xrandr --listactivemonitors | grep ^[[:space:][:digit:]])

# save monitor layout to my preferences
sed -i "s/^screen \(.*\)/screen ${BOTTOM}/" $INI/computer.ini
sed -i "s/^screen \(.*\)/screen ${TOP}/" $INI/horizont.ini
sed -i "s/^screen \(.*\)/screen ${LEFT}/" $INI/vertical.ini
sed -i "s/^screen \(.*\)/screen ${TOP}/" $INI/dkong.ini
sed -i "s/^screen \(.*\)/screen ${TOP}/" $INI/pacman.ini

mame64 $@

Am I working too hard? Is there a better/correct way to handle this?