Skip to content

Instantly share code, notes, and snippets.

@steelx
Forked from azappa/backup bash filez
Last active August 17, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steelx/c087d8a1bdcac2e79f33d3f8141c3e73 to your computer and use it in GitHub Desktop.
Save steelx/c087d8a1bdcac2e79f33d3f8141c3e73 to your computer and use it in GitHub Desktop.
Ubuntu fix dual monitor reboot
#!/bin/bash
# -------------------------------------------------
# Get monitors configuration from monitor.xml and apply it for current user session.
# In case of multiple definitions in monitor.xml only first one is used.
#
# See http://bernaerts.dyndns.org/linux/74-ubuntu/309-ubuntu-dual-display-monitor-position-lost
# for instructions
#
# Revision history :
# 19/04/2014, V1.0 - Creation by N. Bernaerts
# 10/07/2014, V1.1 - Wait 5 seconds for X to fully initialize
# 30/07/2014, V1.2 - K. Callenberg added handling of primary monitor setting
# -------------------------------------------------
# get number of declared monitors
NUM=$(xmllint --xpath 'count(//monitors/configuration['1']/output)' $HOME/.config/monitors.xml)
# 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)' $HOME/.config/monitors.xml 2>NULL)
POS_X=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/x/text()' $HOME/.config/monitors.xml 2>NULL)
POS_Y=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/y/text()' $HOME/.config/monitors.xml 2>NULL)
PRIMARY=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/primary/text()' $HOME/.config/monitors.xml 2>NULL)
# if position is defined for current monitor, add its position to command line parameters
if [ "$PRIMARY" == "yes" ] ; then
[ -n "$POS_X" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--output" "$NAME" "--primary" "--pos" "${POS_X}x${POS_Y}")
else
[ -n "$POS_X" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--output" "$NAME" "--pos" "${POS_X}x${POS_Y}")
fi
done
# wait for 5 seconds (for X to finish initialisation)
sleep 5
#echo "${PARAM_ARR[@]}"
# position all monitors
xrandr "${PARAM_ARR[@]}"
  1. rm ~/.config/monitors.xml && gnome-control-center
  2. setup displays
  3. sudo apt-get install libxml2-utils
  4. sudo wget -O /usr/local/sbin/update-monitor-position http://www.calgorithms.com/assets/files/update-monitor-position && sudo chmod +x /usr/local/sbin/update-monitor-position
  5. System - Startup Applications tool > update-monitor-position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment