Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Gnome and KDE both change resolutions when I dock/undock my laptop.

They seem to do it automatically, more or less, based on the state of the computer. I'd like to have that behavior if I just run something like IceWM or Openbox. Or even XFCE.

Any recommendations?

share|improve this question
2  
Just a hint: The CLI utility xrandr is responsible for changing resolutions, multiple screens, external monitors, etc. If the docking process triggers an udev event, then you can let udev run a script with an appropriate xrandr command. –  oddfellow Mar 18 '12 at 15:43
    
@oddfellow this sounds like an answer, not just a comment –  xubuntix May 17 '12 at 6:25
add comment

1 Answer

up vote 2 down vote accepted

I have in /etc/udev/rules.d/80-monitor.rules

ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", ENV{DEVNAME}=="dri/card0", RUN+="/etc/udev/monitors.sh"

Then in /etc/udev/monitors.sh (marked executable):

#!/bin/sh
set -e

export DISPLAY=:0
export XAUTHORITY=$(getent passwd $(w -h -s|awk '$3==":0"{print $1}'|sed 1q)|cut -d: -f6)/.Xauthority

desktop() {
    xrandr --output LVDS1 --off || true
    xrandr --output HDMI3 --auto --primary --output HDMI2 --auto --right-of HDMI3
}

laptop() {
    xrandr --output HDMI3 --off || true
    xrandr --output HDMI2 --off || true
    xrandr --output LVDS1 --auto
}

if xrandr|grep -q 'HDMI2 connected'; then
    desktop
else
    laptop
fi

Some hints and catches with this example:

  1. It only works for the first graphically logged in user.
  2. You'll need to tune the script to match your monitor setup. See the xrandr manpage for help with this.
  3. I'm not sure if the udev rule will match everyone's monitor status change event. I used udevadm monitor --property to figure out what to use.
  4. I had to use --off to turn off all displays explicitly first before reconfiguring before xrandr allowed me to configure new ones. I think this is driver-dependent and not well documented.
  5. I'm using the presence of the external screen to decide which way round to reconfigure. This might not work for everyone.
  6. xrandr sets some resolution by default which was optimal for me. See the manpage for details on how to set custom resolutions if you need.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.