Ubuntu – How to reset monitor settings to default through terminal

kubuntumultiple-monitors

I have a tricky problem regarding multiple monitors on KDE (Kubuntu). I have a laptop which, at home, is connected to two monitors – VGA and HDMI. That works only when the built-in laptop display is disabled (at least I was told that).

The problem is that now I took the laptop away and booted it up with no external monitors connected. The system remembers that the built-in display was disabled, so it disables it even though it is the only monitor connected. Obviously, that makes the laptop pretty much unusable. Switching to a terminal through Ctrl+Alt+F# works, I can login; even Guest works normally.

The question is, how do I (re)set an account's monitor settings through terminals, since I can't use the GUI?

Thanks

Best Answer

Good question. A bit tricky to answer, but here is a try.

Basic Answer

There is actually a little reset possiblity included in X11. You can find it at /etc/X11/Xreset. You could use the Xreset directory (Xreset.d) to paste a script that runs automatically when a user logs out. The README file:

# Scripts in this directory are executed as root when a user log out from
# a display manager using /etc/X11/Xreset.
# The username of the user logging out is provided in the $USER environment
# variable.

You could thus a) add a reset script in /etc/X11/Xreset.d and b) make a script attached to a launcher that sets your dual external displays up. As such, you would log off and everything would be back to normal, you would log on to your laptop, hit the launcher for the displays and enjoy life.

More information

  1. You might want to look into sudo dpkg-reconfigure -phigh xserver-xorg for resetting the xserver or (probably better look at the answer Mik suggested in the comments).

  2. A SuSE guy wrote a nice article about X.

  3. In a solved bugreport someone states:

    admins can drop scripts in /etc/X11/Xreset.d/ to run after the user logs out.

  4. This is the contents of the file:

You can find it on your own system.

#!/bin/sh
#
# /etc/X11/Xreset
#
# global Xreset file -- for use by display managers
 
# $Id: Xsession 967 2005-12-27 07:20:55Z dnusinow $

set -e
 
PROGNAME=Xreset
SYSSESSIONDIR=/etc/X11/Xreset.d
 
if [ ! -d "$SYSSESSIONDIR" ]; then
  # Nothing to do, exiting
  exit 0
fi

# use run-parts to source every file in the session directory; we source
# instead of executing so that the variables and functions defined above
# are available to the scripts, and so that they can pass variables to each
# other
SESSIONFILES=$(run-parts --list $SYSSESSIONDIR)
if [ -n "$SESSIONFILES" ]; then
  set +e
  for SESSIONFILE in $SESSIONFILES; do
    . $SESSIONFILE
  done
  set -e
fi 

exit 0

# vim:set ai et sts=2 sw=2 tw=80:
Related Question