Corregir posiciones de los monitores en Linux

Wednesday, 6 December 2017

La configuración multimonitor en Linux Mint me ha estado dando problemas, hiciese lo que hiciese siempre quedaba al revés de como deseaba que estuviesen configurados. No se si es un fallo en el driver AMDGPU, o quizás en la herramienta de configuración de pantallas de Cinnamon.

En cualquier caso, he encontrado una solución temporal. Consiste en un script que establece los parámetros apropiados para XRandR, una vez parseado el fichero ~/.config/monitor.xml. En realidad lo hace dos veces, ya que he observado que haciéndolo cambiando las coordenadas Y se fuerza un restablecimiento de la configuración.

El script lo guardo en ~/bin/fix-monitor-position.sh

#!/bin/bash

# monitor.xml path
MONITOR_XML="$HOME/.config/monitors.xml"

# get number of declared monitors
NUM=$(xmllint --xpath 'count(//monitors/configuration['1']/output)' $HOME/.config/monitors.xml)

PARAM_ARR=()
PARAM_AR_ALT=()
# loop thru declared monitors to create the command line parameters
for (( i=1; i<=$NUM; i++)); do
    # get attributes of current monitor (name and x & y positions)
    NAME=$(xmllint --xpath 'string(//monitors/configuration['1']/output['$i']/@name)' $MONITOR_XML 2>/dev/null)
    POS_X=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/x/text()' $MONITOR_XML 2>/dev/null)
    POS_Y=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/y/text()' $MONITOR_XML 2>/dev/null)
    PRIMARY=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/primary/text()' $MONITOR_XML 2>/dev/null)

    POS_Y_ALT=$(($POS_Y + $i))

    # if position is defined for current monitor, add its position to command line parameters
    [ -n "$POS_X" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--output" "$NAME" "--pos" "${POS_X}x${POS_Y}")
    [ -n "$POS_X" ] && PARAM_ARR_ALT=("${PARAM_ARR_ALT[@]}" "--output" "$NAME" "--pos" "${POS_X}x${POS_Y_ALT}")

    # if monitor is defined as primary, adds it to command line parameters
    [ "$PRIMARY" = "yes" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--primary")
    [ "$PRIMARY" = "yes" ] && PARAM_ARR_ALT=("${PARAM_ARR_ALT[@]}" "--primary")
done

# position all monitors
echo "xrandr ${PARAM_ARR_ALT[@]}"
xrandr "${PARAM_ARR_ALT[@]}"

# position all monitors
echo "xrandr ${PARAM_ARR[@]}"
xrandr "${PARAM_ARR[@]}"

Una vez creado se le ponen permisos de ejecucion:

chmod +x ~/bin/fix-monitor-position.sh

Y por ultimo se asocia como una tarea de inicio en Cinnamon.


Coment

Anonymous Anonymous Tuesday, 16 April 08:02